Class: AirTest::GithubClient
- Inherits:
-
Object
- Object
- AirTest::GithubClient
- Defined in:
- lib/air_test/github_client.rb
Overview
Handles GitHub API interactions for AirTest, such as commits and pull requests.
Instance Method Summary collapse
- #commit_and_push_branch(branch, files, commit_message) ⇒ Object
-
#create_pull_request(branch, pr_title, pr_body, assignees: ["Notion"]) ⇒ Object
rubocop:disable Metrics/MethodLength.
-
#initialize(config = AirTest.configuration) ⇒ GithubClient
constructor
A new instance of GithubClient.
Constructor Details
#initialize(config = AirTest.configuration) ⇒ GithubClient
Returns a new instance of GithubClient.
8 9 10 11 12 |
# File 'lib/air_test/github_client.rb', line 8 def initialize(config = AirTest.configuration) @token = config.github[:token] @repo = config.repo || detect_repo_from_git @client = Octokit::Client.new(access_token: @token) if @token end |
Instance Method Details
#commit_and_push_branch(branch, files, commit_message) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/air_test/github_client.rb', line 14 def commit_and_push_branch(branch, files, ) if branch_exists?(branch) system("git checkout #{branch}") else system("git checkout -b #{branch}") end # Set git user to bot system('git config user.name "air-test-bot"') system('git config user.email "[email protected]"') # Set remote to use bot token if available if @token repo_url = "github.com/#{@repo}.git" system("git remote set-url origin https://#{@token}@#{repo_url}") end files.each { |f| system("git add -f #{f}") } has_changes = !system("git diff --cached --quiet") system("git commit -m '#{commit_message}'") if has_changes system("git push origin #{branch}") has_changes end |
#create_pull_request(branch, pr_title, pr_body, assignees: ["Notion"]) ⇒ Object
rubocop:disable Metrics/MethodLength
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/air_test/github_client.rb', line 36 def create_pull_request(branch, pr_title, pr_body, assignees: ["Notion"]) return unless @client && @repo @client.create_pull_request( @repo, "main", branch, pr_title, pr_body, { assignees: assignees } ) rescue Octokit::UnprocessableEntity => e warn "❌ Erreur lors de la création de la PR : #{e.message}" nil end |