diff --git a/Gemfile b/Gemfile index c03ffaf..8c4d7c0 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source 'http://rubygems.org' gem 'sinatra', '~> 2.0' gem 'jwt', '~> 2.1' -gem 'octokit', '~> 4.0' +gem 'octokit', '~> 4.14' gem 'rubocop' gem 'dotenv' gem 'git' diff --git a/Gemfile.lock b/Gemfile.lock index 2611e27..80446fc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -5,14 +5,14 @@ GEM public_suffix (>= 2.0.2, < 4.0) ast (2.4.0) dotenv (2.5.0) - faraday (0.15.3) + faraday (0.15.4) multipart-post (>= 1.2, < 3) git (1.5.0) jaro_winkler (1.5.1) jwt (2.1.0) multipart-post (2.0.0) mustermann (1.0.3) - octokit (4.13.0) + octokit (4.14.0) sawyer (~> 0.8.0, >= 0.5.3) parallel (1.12.1) parser (2.5.3.0) @@ -50,7 +50,7 @@ DEPENDENCIES dotenv git jwt (~> 2.1) - octokit (~> 4.0) + octokit (~> 4.14) rubocop sinatra (~> 2.0) diff --git a/server.rb b/server.rb index 8b9e422..414f8df 100644 --- a/server.rb +++ b/server.rb @@ -83,20 +83,11 @@ class GHAapp < Sinatra::Application # Create a new check run with the status queued def create_check_run - # At the time of writing, Octokit does not support the Checks API, but - # it does provide generic HTTP methods you can use: - # https://developer.github.com/v3/checks/runs/#create-a-check-run - check_run = @installation_client.post( - "repos/#{@payload['repository']['full_name']}/check-runs", - { - # This header allows for beta access to Checks API - accept: 'application/vnd.github.antiope-preview+json', - # The name of your check run. - name: 'Octo RuboCop', - # The payload structure differs depending on whether a check run or a check suite event occurred. - head_sha: @payload['check_run'].nil? ? @payload['check_suite']['head_sha'] : @payload['check_run']['head_sha'] - } - ) + # The name of your check run. + name = 'Octo RuboCop' + # The payload structure differs depending on whether a check run or a check suite event occurred. + head_sha = @payload['check_run'].nil? ? @payload['check_suite']['head_sha'] : @payload['check_run']['head_sha'] + Octokit.create_check_run(@payload['repository']['full_name'], name, head_sha) # You requested the creation of a check run from GitHub. Now, you'll wait # to get confirmation from GitHub, in the form of a webhook, that it was @@ -109,19 +100,8 @@ def initiate_check_run # Once the check run is created, you'll update the status of the check run # to 'in_progress' and run the CI process. When the CI finishes, you'll # update the check run status to 'completed' and add the CI results. - - # At the time of writing, Octokit doesn't support the Checks API, but - # it does provide generic HTTP methods you can use: - # https://developer.github.com/v3/checks/runs/#update-a-check-run - updated_check_run = @installation_client.patch( - "repos/#{@payload['repository']['full_name']}/check-runs/#{@payload['check_run']['id']}", - { - accept: 'application/vnd.github.antiope-preview+json', - name: 'Octo RuboCop', - status: 'in_progress', - started_at: Time.now.utc.iso8601 - } - ) + Octokit.update_check_run(@payload['repository']['full_name'], @payload['check_run']['id'], name: 'Octo RuboCop', + status: 'in_progress', started_at: Time.now.utc.iso8601) # ***** RUN A CI TEST ***** # Ideally this would be performed async, so you could return immediately. @@ -192,8 +172,7 @@ def initiate_check_run text = "Octo RuboCop version: #{@output['metadata']['rubocop_version']}" # Mark the check run as complete! And if there are warnings, share them. - updated_check_run = @installation_client.patch( - "repos/#{@payload['repository']['full_name']}/check-runs/#{@payload['check_run']['id']}", + Octokit.update_check_run(@payload['repository']['full_name'], @payload['check_run']['id'], { accept: 'application/vnd.github.antiope-preview+json', name: 'Octo RuboCop', @@ -305,7 +284,9 @@ def authenticate_app def authenticate_installation(payload) @installation_id = payload['installation']['id'] @installation_token = @app_client.create_app_installation_access_token(@installation_id)[:token] - @installation_client = Octokit::Client.new(bearer_token: @installation_token) + Octokit.configure do |c| + c.bearer_token = @installation_token + end end # Check X-Hub-Signature to confirm that this webhook was generated by