Class: AirTest::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/air_test/runner.rb

Overview

Runs the main automation workflow for AirTest, orchestrating Notion parsing and GitHub actions.

Instance Method Summary collapse

Constructor Details

#initialize(config = AirTest.configuration) ⇒ Runner

Returns a new instance of Runner.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/air_test/runner.rb', line 8

def initialize(config = AirTest.configuration)
  @config = config
  @parser = case config.tool.to_s.downcase
            when "notion"
              NotionTicketParser.new(config)
            when "jira"
              JiraTicketParser.new(config)
            when "monday"
              MondayTicketParser.new(config)
            else
              raise "Unknown tool: #{config.tool}"
            end
  @spec = SpecGenerator.new
  @github = GithubClient.new(config)
end

Instance Method Details

#run(limit: 5) ⇒ Object



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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/air_test/runner.rb', line 24

def run(limit: 5)
  @config.validate!
  tickets = @parser.fetch_tickets(limit: limit)
  # Filter for 'Not started' tickets (assuming each parser returns only those, or filter here if needed)
  puts "šŸ” Found #{tickets.length} tickets"
  tickets.each do |ticket|
    ticket_id = @parser.extract_ticket_id(ticket)
    title = @parser.extract_ticket_title(ticket)
    url = @parser.extract_ticket_url(ticket)
    puts "\nšŸ“‹ Processing: FDR#{ticket_id} - #{title}"
    parsed_data = @parser.parse_ticket_content(ticket["id"])
    unless parsed_data && parsed_data[:feature] && !parsed_data[:feature].empty?
      puts "āš ļø  Skipping ticket FDR#{ticket_id} due to missing or empty feature."
      next
    end

    branch = "air_test/#{ticket_id}-#{title.downcase.gsub(/[^a-z0-9]+/, "-").gsub(/^-|-$/, "")}"
    spec_path = @spec.generate_spec_from_parsed_data(ticket_id, parsed_data)
    step_path = @spec.generate_step_definitions_for_spec(spec_path)
    files_to_commit = [spec_path]
    files_to_commit << step_path if step_path
    has_changes = @github.commit_and_push_branch(branch, files_to_commit,
                                                 "Add specs for Notion ticket #{ticket_id}")
    if has_changes
      pr_title = title
      scenarios_md = parsed_data[:scenarios].map.with_index(1) do |sc, _i|
        steps = sc[:steps]&.map { |step| "      - #{step}" }&.join("\n")
        "  - [ ] #{sc[:title]}\n#{steps}"
      end.join("\n")
      pr_body = "          - **Story Notion :** \#{url}\n          - **Feature** : \#{parsed_data[:feature]}\n          - **Sc\u00E9narios** :\n        \#{scenarios_md}\n        - **Want to help us improve airtest?**\n        Leave feedback [here](http://bit.ly/4o5rinU)\n        or [join the community](https://discord.gg/ggnBvhtw7E)\n      MD\n      pr = @github.create_pull_request(branch, pr_title, pr_body)\n      puts \"\u2705 Pull Request cr\u00E9\u00E9e : \#{pr.html_url}\" if pr\n    else\n      puts \"\u26A0\uFE0F  Aucun changement d\u00E9tect\u00E9, PR non cr\u00E9\u00E9e.\"\n    end\n  end\nend\n"