air_test 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c4921bb57f9c5c1f8d720c7fe14ddb50b6ab1959a5fb16521918d05083c65b90
4
+ data.tar.gz: a4fcbc657772c9bf9fa5ad50e61e37682681427b7788c78ba2c2d7ab54002ffe
5
+ SHA512:
6
+ metadata.gz: 20aff8beca5a75f7465a4dbdf0e7a14f3ff6df85e4e73184ec967173a2f8ac43057a53f0bc96d310a095e45389ea5882510bb4ac29e131b9d375a440ce173aca
7
+ data.tar.gz: 0de7e6835c9dde4bf40b713080befe07dea4d107044c1039a21c745caa09895a7c78dc994d49930064d534aaa9e3a103eead6cf8b7666ed9aed0001839ce5bbb
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.1
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Style/StringLiteralsInInterpolation:
8
+ EnforcedStyle: double_quotes
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-07-17
4
+
5
+ - Initial release
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 julien bouland
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,133 @@
1
+ # air_test
2
+
3
+ Automate the generation of Turnip/RSpec specs from Notion tickets, create branches, commits, pushes, and GitHub Pull Requests—all with a single Rake command.
4
+
5
+ ## 🚀 Features
6
+
7
+ - Fetches Notion tickets (Gherkin format)
8
+ - Parses and extracts features/scenarios
9
+ - Generates Turnip/RSpec spec files and matching step definitions
10
+ - Creates a dedicated branch, commits, pushes
11
+ - Opens a Pull Request on GitHub with a rich, pre-filled template
12
+
13
+ ---
14
+
15
+ ## ⚡️ Installation
16
+
17
+ Add the gem to your `Gemfile`:
18
+
19
+ ```ruby
20
+ gem 'air_test', path: '../path/to/air_test'
21
+ ```
22
+ or, if you publish it on a git repo:
23
+ ```ruby
24
+ gem 'air_test', git: 'https://github.com/your-org/air_test.git'
25
+ ```
26
+
27
+ Then install dependencies:
28
+ ```sh
29
+ bundle install
30
+ ```
31
+
32
+ ---
33
+
34
+ ## ⚙️ Configuration
35
+
36
+ Create an initializer in your Rails project:
37
+ `config/initializers/air_test.rb`
38
+
39
+ ```ruby
40
+ AirTest.configure do |config|
41
+ config.notion_token = ENV['NOTION_TOKEN']
42
+ config.notion_database_id = ENV['NOTION_DATABASE_ID']
43
+ config.github_token = ENV['GITHUB_BOT_TOKEN'] # or GITHUB_TOKEN
44
+ config.repo = 'your-org/your-repo' # format: 'organization/repo_name'
45
+ end
46
+ ```
47
+
48
+ Make sure your environment variables are set (in `.env`, your shell, or your CI/CD).
49
+
50
+ ---
51
+
52
+ ## 🛠 Usage
53
+
54
+ Run the automated workflow from your Rails project terminal:
55
+
56
+ ```sh
57
+ bundle exec rake air_test:generate_specs_from_notion
58
+ ```
59
+
60
+ - This will:
61
+ - Fetch Notion tickets
62
+ - Generate Turnip/RSpec specs and step files
63
+ - Create a branch, commit, push
64
+ - Open a Pull Request on GitHub with a rich template
65
+
66
+ ---
67
+
68
+ ## 📋 Requirements
69
+
70
+ - A Notion API token with access to your database
71
+ - A GitHub token with push and PR creation rights
72
+ - A configured remote git repository (`git remote -v`)
73
+ - The folders `spec/features` and `spec/steps` (created automatically if needed)
74
+
75
+ ---
76
+
77
+ ## 🧩 Gem Structure
78
+
79
+ - `lib/air_test/configuration.rb`: centralized configuration
80
+ - `lib/air_test/notion_parser.rb`: Notion extraction and parsing
81
+ - `lib/air_test/spec_generator.rb`: spec and step file generation
82
+ - `lib/air_test/github_client.rb`: git and GitHub PR management
83
+ - `lib/air_test/runner.rb`: workflow orchestrator
84
+ - `lib/tasks/air_test.rake`: Rake task to launch the automation
85
+
86
+ ---
87
+
88
+ ## 📝 Example .env
89
+
90
+ ```
91
+ NOTION_TOKEN=secret_xxx
92
+ NOTION_DATABASE_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
93
+ GITHUB_BOT_TOKEN=ghp_xxx
94
+ ```
95
+
96
+ ---
97
+
98
+ ## 🧪 Tests (optional)
99
+
100
+ If you want to test the gem’s services, you can add specs in the `spec/` folder.
101
+
102
+ ---
103
+
104
+ ## 🆘 Troubleshooting
105
+
106
+ - **Notion or GitHub authentication error**: check your tokens.
107
+ - **PR not created**: make sure the branch contains commits different from `main`.
108
+ - **Permission issues**: ensure the GitHub bot has access to the repo.
109
+
110
+ ---
111
+
112
+ ## 📦 Publishing the Gem (optional)
113
+
114
+ To publish the gem on RubyGems:
115
+
116
+ ```sh
117
+ gem build air_test.gemspec
118
+ gem push air_test-x.y.z.gem
119
+ ```
120
+
121
+ ---
122
+
123
+ ## 👨‍💻 Author & License
124
+
125
+ - Author: [Airtest]
126
+ - License: MIT
127
+
128
+ ---
129
+
130
+ **Need an integration example or install script?**
131
+ Open an issue or contact me!
132
+
133
+ ---
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AirTest
4
+ class Configuration
5
+ attr_accessor :notion_token, :notion_database_id, :github_token, :repo
6
+
7
+ def initialize
8
+ @notion_token = ENV['NOTION_TOKEN']
9
+ @notion_database_id = ENV['NOTION_DATABASE_ID']
10
+ @github_token = ENV['GITHUB_BOT_TOKEN'] || ENV['GITHUB_TOKEN']
11
+ @repo = nil
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+ require 'octokit'
3
+
4
+ module AirTest
5
+ class GithubClient
6
+ def initialize(config = AirTest.configuration)
7
+ @github_token = config.github_token
8
+ @repo = config.repo || detect_repo_from_git
9
+ @client = Octokit::Client.new(access_token: @github_token) if @github_token
10
+ end
11
+
12
+ def commit_and_push_branch(branch, files, commit_message)
13
+ if branch_exists?(branch)
14
+ system("git checkout #{branch}")
15
+ else
16
+ system("git checkout -b #{branch}")
17
+ end
18
+ files.each { |f| system("git add -f #{f}") }
19
+ has_changes = !system("git diff --cached --quiet")
20
+ if has_changes
21
+ system("git commit -m '#{commit_message}'")
22
+ end
23
+ system("git push origin #{branch}")
24
+ has_changes
25
+ end
26
+
27
+ def create_pull_request(branch, pr_title, pr_body, assignees: ['Notion'])
28
+ return unless @client && @repo
29
+ @client.create_pull_request(
30
+ @repo,
31
+ 'main',
32
+ branch,
33
+ pr_title,
34
+ pr_body,
35
+ { assignees: assignees }
36
+ )
37
+ rescue Octokit::UnprocessableEntity => e
38
+ warn "❌ Erreur lors de la création de la PR : #{e.message}"
39
+ nil
40
+ end
41
+
42
+ private
43
+
44
+ def branch_exists?(branch)
45
+ system("git show-ref --verify --quiet refs/heads/#{branch}")
46
+ end
47
+
48
+ def detect_repo_from_git
49
+ remote_url = `git config --get remote.origin.url`.strip
50
+ remote_url.split(/[:\/]/).last(2).join('/').gsub(/\.git$/, '')
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,165 @@
1
+ # frozen_string_literal: true
2
+ require 'net/http'
3
+ require 'json'
4
+ require 'uri'
5
+
6
+ module AirTest
7
+ class NotionParser
8
+ def initialize(config = AirTest.configuration)
9
+ @database_id = config.notion_database_id
10
+ @notion_token = config.notion_token
11
+ @base_url = 'https://api.notion.com/v1'
12
+ end
13
+
14
+ def fetch_tickets(limit: 5)
15
+ uri = URI("#{@base_url}/databases/#{@database_id}/query")
16
+ response = make_api_request(uri, { page_size: 100 })
17
+ return [] unless response.code == '200'
18
+ data = JSON.parse(response.body)
19
+ data['results'].first(limit)
20
+ end
21
+
22
+ def parse_ticket_content(page_id)
23
+ blocks = get_page_content(page_id)
24
+ return nil unless blocks
25
+ parse_content(blocks)
26
+ end
27
+
28
+ def extract_ticket_title(ticket)
29
+ ticket.dig('properties', 'Projects', 'title', 0, 'plain_text') || 'No title'
30
+ end
31
+
32
+ def extract_ticket_id(ticket)
33
+ ticket.dig('properties', 'ID', 'unique_id', 'number') || 'No ID'
34
+ end
35
+
36
+ def extract_ticket_url(ticket)
37
+ ticket['url'] || "https://www.notion.so/#{ticket['id'].gsub('-', '')}"
38
+ end
39
+
40
+ private
41
+
42
+ def get_page_content(page_id)
43
+ uri = URI("#{@base_url}/blocks/#{page_id}/children")
44
+ response = make_api_request(uri, nil, 'GET')
45
+ return nil unless response.code == '200'
46
+ data = JSON.parse(response.body)
47
+ data['results']
48
+ end
49
+
50
+ def make_api_request(uri, request_body = nil, method = 'POST')
51
+ http = Net::HTTP.new(uri.host, uri.port)
52
+ http.use_ssl = true
53
+ if method == 'GET'
54
+ request = Net::HTTP::Get.new(uri)
55
+ else
56
+ request = Net::HTTP::Post.new(uri)
57
+ request.body = request_body.to_json if request_body
58
+ end
59
+ request['Authorization'] = "Bearer #{@notion_token}"
60
+ request['Notion-Version'] = '2022-06-28'
61
+ request['Content-Type'] = 'application/json'
62
+ http.request(request)
63
+ end
64
+
65
+ def parse_content(blocks)
66
+ parsed_data = {
67
+ feature: '',
68
+ scenarios: [],
69
+ meta: { tags: [], priority: '', estimate: nil, assignee: '' }
70
+ }
71
+ current_scenario = nil
72
+ in_feature_block = false
73
+ in_scenario_block = false
74
+ blocks.each do |block|
75
+ case block['type']
76
+ when 'heading_1', 'heading_2', 'heading_3'
77
+ heading_text = extract_text(block[block['type']]['rich_text'])
78
+ if heading_text.downcase.include?('feature')
79
+ in_feature_block = true
80
+ in_scenario_block = false
81
+ parsed_data[:feature] = heading_text
82
+ elsif heading_text.downcase.include?('scenario')
83
+ in_scenario_block = true
84
+ in_feature_block = false
85
+ current_scenario = { title: heading_text, steps: [] }
86
+ parsed_data[:scenarios] << current_scenario
87
+ else
88
+ in_feature_block = false
89
+ in_scenario_block = false
90
+ end
91
+ when 'paragraph'
92
+ text = extract_text(block['paragraph']['rich_text'])
93
+ next if text.empty?
94
+ if in_feature_block
95
+ parsed_data[:feature] += "\n" + text
96
+ elsif in_scenario_block && current_scenario
97
+ current_scenario[:steps] << text
98
+ end
99
+ when 'bulleted_list_item', 'numbered_list_item'
100
+ text = extract_text(block[block['type']]['rich_text'])
101
+ next if text.empty?
102
+ if in_feature_block
103
+ parsed_data[:feature] += "\n• " + text
104
+ elsif in_scenario_block && current_scenario
105
+ current_scenario[:steps] << text
106
+ end
107
+ when 'callout'
108
+ text = extract_text(block['callout']['rich_text'])
109
+ next if text.empty?
110
+ if text.downcase.include?('tag')
111
+ tags = extract_tags(text)
112
+ parsed_data[:meta][:tags].concat(tags)
113
+ elsif text.downcase.include?('priority')
114
+ parsed_data[:meta][:priority] = extract_priority(text)
115
+ elsif text.downcase.include?('estimate')
116
+ parsed_data[:meta][:estimate] = extract_estimate(text)
117
+ elsif text.downcase.include?('assignee')
118
+ parsed_data[:meta][:assignee] = extract_assignee(text)
119
+ end
120
+ end
121
+ end
122
+ parsed_data[:feature] = parsed_data[:feature].strip
123
+ parsed_data[:meta][:tags] = parsed_data[:meta][:tags].uniq
124
+ parsed_data
125
+ end
126
+
127
+ def extract_text(rich_text_array)
128
+ return '' unless rich_text_array
129
+ rich_text_array.map { |text| text['plain_text'] }.join(' ')
130
+ end
131
+
132
+ def extract_tags(text)
133
+ if text =~ /tags?:\s*(.+)/i
134
+ tags_text = $1.strip
135
+ tags_text.split(/[\,\s]+/).map(&:strip).reject(&:empty?)
136
+ else
137
+ []
138
+ end
139
+ end
140
+
141
+ def extract_priority(text)
142
+ if text =~ /priority:\s*(.+)/i
143
+ $1.strip
144
+ else
145
+ ''
146
+ end
147
+ end
148
+
149
+ def extract_estimate(text)
150
+ if text =~ /estimate:\s*(\d+)/i
151
+ $1.to_i
152
+ else
153
+ nil
154
+ end
155
+ end
156
+
157
+ def extract_assignee(text)
158
+ if text =~ /assignee:\s*(.+)/i
159
+ $1.strip
160
+ else
161
+ ''
162
+ end
163
+ end
164
+ end
165
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AirTest
4
+ class Runner
5
+ def initialize(config = AirTest.configuration)
6
+ @notion = NotionParser.new(config)
7
+ @spec = SpecGenerator.new
8
+ @github = GithubClient.new(config)
9
+ end
10
+
11
+ def run(limit: 5)
12
+ tickets = @notion.fetch_tickets(limit: limit)
13
+ puts "🔍 Found #{tickets.length} tickets"
14
+ tickets.each do |ticket|
15
+ ticket_id = @notion.extract_ticket_id(ticket)
16
+ title = @notion.extract_ticket_title(ticket)
17
+ url = @notion.extract_ticket_url(ticket)
18
+ puts "\n📋 Processing: FDR#{ticket_id} - #{title}"
19
+ parsed_data = @notion.parse_ticket_content(ticket['id'])
20
+ next unless parsed_data && parsed_data[:feature] && !parsed_data[:feature].empty?
21
+ slug = parsed_data[:feature].downcase.gsub(/[^a-z0-9]+/, '-').gsub(/^-|-$/, '')
22
+ branch = "air_test/#{ticket_id}-#{slug}"
23
+ spec_path = @spec.generate_spec_from_parsed_data(ticket_id, parsed_data)
24
+ step_path = @spec.generate_step_definitions_for_spec(spec_path)
25
+ files_to_commit = [spec_path]
26
+ files_to_commit << step_path if step_path
27
+ has_changes = @github.commit_and_push_branch(branch, files_to_commit, "Add specs for Notion ticket #{ticket_id}")
28
+ if has_changes
29
+ pr_title = title
30
+ scenarios_md = parsed_data[:scenarios].map.with_index(1) do |sc, i|
31
+ steps = sc[:steps]&.join(' ')
32
+ " - [ ] #{sc[:title]} – #{steps}"
33
+ end.join("\n")
34
+ pr_body = <<~MD
35
+ - **Story Notion :** #{url}
36
+ - **Feature** : #{parsed_data[:feature]}
37
+ - **Scénarios** :
38
+ #{scenarios_md}
39
+ MD
40
+ pr = @github.create_pull_request(branch, pr_title, pr_body)
41
+ puts "✅ Pull Request créée : #{pr.html_url}" if pr
42
+ else
43
+ puts "⚠️ Aucun changement détecté, PR non créée."
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+ require 'fileutils'
3
+
4
+ module AirTest
5
+ class SpecGenerator
6
+ def generate_spec_from_parsed_data(ticket_id, parsed_data, output_dir: 'spec/features')
7
+ feature_slug = parsed_data[:feature].downcase.gsub(/[^a-z0-9]+/, '-').gsub(/^-|-$/, '')
8
+ filename = "#{feature_slug}_fdr#{ticket_id}.rb"
9
+ filepath = File.join(output_dir, filename)
10
+ FileUtils.mkdir_p(output_dir)
11
+ File.open(filepath, 'w') do |f|
12
+ f.puts "# language: turnip"
13
+ f.puts "# frozen_string_literal: true\n"
14
+ f.puts "feature '#{parsed_data[:feature]}' do"
15
+ parsed_data[:scenarios].each do |scenario|
16
+ f.puts " scenario '#{scenario[:title]}' do"
17
+ scenario[:steps].each do |step|
18
+ f.puts " pending '#{step}'"
19
+ end
20
+ f.puts " end"
21
+ end
22
+ f.puts "end"
23
+ end
24
+ filepath
25
+ end
26
+
27
+ def generate_step_definitions_for_spec(spec_filepath, output_dir: 'spec/steps')
28
+ step_texts = []
29
+ File.readlines(spec_filepath).each do |line|
30
+ if line =~ /pending ['\"](.*)['\"]/
31
+ step_texts << $1.strip
32
+ end
33
+ end
34
+ return if step_texts.empty?
35
+ spec_filename = File.basename(spec_filepath, '.rb')
36
+ step_file = File.join(output_dir, "#{spec_filename}_steps.rb")
37
+ FileUtils.mkdir_p(output_dir)
38
+ File.open(step_file, 'w') do |f|
39
+ f.puts "# Auto-generated step definitions for #{spec_filename.gsub('-', ' ')}"
40
+ step_texts.uniq.each do |step|
41
+ f.puts "\nstep '#{step}' do"
42
+ f.puts " pending 'Implement: #{step.gsub("'", "\\'")}'"
43
+ f.puts "end"
44
+ end
45
+ end
46
+ step_file
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AirTest
4
+ VERSION = "0.1.0"
5
+ end
data/lib/air_test.rb ADDED
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "air_test/version"
4
+ require_relative "air_test_automation/configuration"
5
+ require_relative "air_test_automation/notion_parser"
6
+ require_relative "air_test_automation/spec_generator"
7
+ require_relative "air_test_automation/github_client"
8
+ require_relative "air_test_automation/rake_tasks"
9
+
10
+ module AirTest
11
+ class << self
12
+ attr_accessor :configuration
13
+ end
14
+
15
+ def self.configure
16
+ self.configuration ||= Configuration.new
17
+ yield(configuration)
18
+ end
19
+ end
@@ -0,0 +1,7 @@
1
+ namespace :air_test do
2
+ desc "Generate specs and PR from Notion"
3
+ task generate_specs_from_notion: :environment do
4
+ require 'air_test/runner'
5
+ AirTest::Runner.new.run(limit: 5)
6
+ end
7
+ end
data/sig/air_test.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module AirTest
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: air_test
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - julien bouland
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 2025-07-18 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: Automate the generation of Turnip/RSpec specs from Notion tickets, create
13
+ branches, commits, pushes, and GitHub Pull Requests—all with a single Rake command.
14
+ email:
15
+ - bouland.julien@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".rspec"
21
+ - ".rubocop.yml"
22
+ - CHANGELOG.md
23
+ - CODE_OF_CONDUCT.md
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - lib/air_test.rb
28
+ - lib/air_test/configuration.rb
29
+ - lib/air_test/github_client.rb
30
+ - lib/air_test/notion_parser.rb
31
+ - lib/air_test/runner.rb
32
+ - lib/air_test/spec_generator.rb
33
+ - lib/air_test/version.rb
34
+ - lib/tasks/air_test.rake
35
+ - sig/air_test.rbs
36
+ homepage: https://github.com/airtest-io/air_test
37
+ licenses:
38
+ - MIT
39
+ metadata:
40
+ homepage_uri: https://github.com/airtest-io/air_test
41
+ source_code_uri: https://github.com/airtest-io/air_test
42
+ changelog_uri: https://github.com/airtest-io/air_test/blob/main/CHANGELOG.md
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 3.1.0
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubygems_version: 3.6.2
58
+ specification_version: 4
59
+ summary: Generate specs and PR from Notion
60
+ test_files: []