From 050b135f4e70f3ae3f82764c7bf10b9e29050e50 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Mon, 30 Jul 2018 12:51:27 +0530 Subject: [PATCH 1/3] Monkey patch Octokit::Client to access Checks API --- github/octokit_client_patch.rb | 54 ++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 github/octokit_client_patch.rb diff --git a/github/octokit_client_patch.rb b/github/octokit_client_patch.rb new file mode 100644 index 0000000..5031536 --- /dev/null +++ b/github/octokit_client_patch.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +require "octokit" +# +# --------------------------------------------------------------------------------------- +# TODO: Remove this patch-file once the `octokit` gem ships with methods to send requests +# to the Checks API endpoints. +# --------------------------------------------------------------------------------------- +# +module Octokit + class Client + # Required to access the Checks API during the preview period + PREVIEW_HEADER = { + :headers => { + "Accept" => "application/vnd.github.antiope-preview+json" + } + } + + # ----------------------------------------------------------------------------------- + # Note: The following methods have been fashioned along the lines of existing methods + # included in Octokit::Client to allow smoother transition to the gem. + # ----------------------------------------------------------------------------------- + + # Create a new check run + # Use when the app intercepts either a `check_suite` event with a `requested` action + # or a `check_run` event with a `rerequested` action. + # + # repo: [STRING] The repository name in the 'name_with_owner' pattern. + # options: [HASH] The customizable payload sent along with the request. + # + # ----------------------------------------------------------------------------------- + # https://developer.github.com/v3/checks/runs/#create-a-check-run + # ----------------------------------------------------------------------------------- + def create_check_run(repo, options) + post "#{Repository.path repo}/check-runs", options.merge(PREVIEW_HEADER) + end + + # Update an existing check run + # Use to update the status of a check run (e.g. to `completed`) or with any new + # information available from the underlying test run or to simply mark the check + # run as `success`, `failure`, etc. + # + # repo: [STRING] The repository name in the 'name_with_owner' pattern. + # id: [INTEGER] The id of the check run to be modified. + # options: [HASH] The customizable payload sent along with the request. + # + # ----------------------------------------------------------------------------------- + # https://developer.github.com/v3/checks/runs/#update-a-check-run + # ----------------------------------------------------------------------------------- + def update_check_run(repo, id, options) + patch "#{Repository.path repo}/check-runs/#{id}", options.merge(PREVIEW_HEADER) + end + end +end From 340b61a30a363d6ba4dc9658a824619fa50cef0b Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Mon, 30 Jul 2018 19:22:04 +0530 Subject: [PATCH 2/3] add parentheses to arguments in interpolated code --- github/octokit_client_patch.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/github/octokit_client_patch.rb b/github/octokit_client_patch.rb index 5031536..62b63e2 100644 --- a/github/octokit_client_patch.rb +++ b/github/octokit_client_patch.rb @@ -32,7 +32,7 @@ class Client # https://developer.github.com/v3/checks/runs/#create-a-check-run # ----------------------------------------------------------------------------------- def create_check_run(repo, options) - post "#{Repository.path repo}/check-runs", options.merge(PREVIEW_HEADER) + post "#{Repository.path(repo)}/check-runs", options.merge(PREVIEW_HEADER) end # Update an existing check run @@ -48,7 +48,7 @@ def create_check_run(repo, options) # https://developer.github.com/v3/checks/runs/#update-a-check-run # ----------------------------------------------------------------------------------- def update_check_run(repo, id, options) - patch "#{Repository.path repo}/check-runs/#{id}", options.merge(PREVIEW_HEADER) + patch "#{Repository.path(repo)}/check-runs/#{id}", options.merge(PREVIEW_HEADER) end end end From ca6394054f346392bfbd29c78f6b986ea7079c4d Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Mon, 30 Jul 2018 19:27:04 +0530 Subject: [PATCH 3/3] Rename octokit_client_patch.rb to octokit_client_checks_api_patch.rb --- ...octokit_client_patch.rb => octokit_client_checks_api_patch.rb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename github/{octokit_client_patch.rb => octokit_client_checks_api_patch.rb} (100%) diff --git a/github/octokit_client_patch.rb b/github/octokit_client_checks_api_patch.rb similarity index 100% rename from github/octokit_client_patch.rb rename to github/octokit_client_checks_api_patch.rb