Class: AirTest::NotionTicketParser

Inherits:
Object
  • Object
show all
Includes:
TicketParser
Defined in:
lib/air_test/notion_ticket_parser.rb

Overview

Implements TicketParser for Notion integration.

Instance Method Summary collapse

Constructor Details

#initialize(config = AirTest.configuration) ⇒ NotionTicketParser

Returns a new instance of NotionTicketParser.



12
13
14
15
16
17
# File 'lib/air_test/notion_ticket_parser.rb', line 12

def initialize(config = AirTest.configuration)
  @database_id = config.notion[:database_id]
  @notion_token = config.notion[:token]
  @status_filter = config.status_filter || "Not started"
  @base_url = "https://api.notion.com/v1"
end

Instance Method Details

#extract_ticket_id(ticket) ⇒ Object



69
70
71
# File 'lib/air_test/notion_ticket_parser.rb', line 69

def extract_ticket_id(ticket)
  ticket.dig("properties", "ID", "unique_id", "number") || "No ID"
end

#extract_ticket_title(ticket) ⇒ Object



65
66
67
# File 'lib/air_test/notion_ticket_parser.rb', line 65

def extract_ticket_title(ticket)
  ticket.dig("properties", "Projects", "title", 0, "plain_text") || "No title"
end

#extract_ticket_url(ticket) ⇒ Object



73
74
75
# File 'lib/air_test/notion_ticket_parser.rb', line 73

def extract_ticket_url(ticket)
  ticket["url"] || "https://www.notion.so/#{ticket["id"].gsub("-", "")}"
end

#fetch_tickets(limit: 5) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/air_test/notion_ticket_parser.rb', line 19

def fetch_tickets(limit: 5)
  uri = URI("#{@base_url}/databases/#{@database_id}/query")
  # Add filter for 'Not started' status
  request_body = {
    page_size: 100,
    filter: {
      property: "Status",
      status: {
        equals: @status_filter
      }
    }
  }
  
  response = make_api_request(uri, request_body)
  
  return [] unless response.code == "200"

  data = JSON.parse(response.body)
  results = data["results"].first(limit)
  
  # Debug: Show the first ticket's properties to understand the structure
  if ENV['AIRTEST_DEBUG'] && results.any?
    first_ticket = results.first
    puts "🔍 Debug: First ticket properties:"
    first_ticket["properties"].each do |prop_name, prop_value|
      puts "  - #{prop_name}: #{prop_value['type']}"
    end
  end
  
  results
end

#parse_ticket_content(page_id) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/air_test/notion_ticket_parser.rb', line 51

def parse_ticket_content(page_id)
  blocks = get_page_content(page_id)
  # puts "\n===== RAW NOTION BLOCKS ====="
  # puts JSON.pretty_generate(blocks)
  return nil unless blocks

  normalized_blocks = normalize_blocks(blocks)
  # puts "\n===== NORMALIZED BLOCKS ====="
  # puts JSON.pretty_generate(normalized_blocks)
  parse_content(normalized_blocks)
  # puts "\n===== PARSED DATA ====="
  # puts JSON.pretty_generate(parsed_data)
end