Update example with Octokit Checks API methods (#3375)
This commit is contained in:
@@ -140,18 +140,16 @@ You'll add this new method as a [Sinatra helper](https://github.com/sinatra/sina
|
|||||||
``` ruby
|
``` ruby
|
||||||
# Create a new check run with the status queued
|
# Create a new check run with the status queued
|
||||||
def create_check_run
|
def create_check_run
|
||||||
# # At the time of writing, Octokit does not support the Checks API yet, but
|
@installation_client.create_check_run(
|
||||||
# it does provide generic HTTP methods you can use:
|
# [String, Integer, Hash, Octokit Repository object] A GitHub repository.
|
||||||
# /rest/reference/checks#create-a-check-run
|
@payload['repository']['full_name'],
|
||||||
check_run = @installation_client.post(
|
# [String] The name of your check run.
|
||||||
"repos/#{@payload['repository']['full_name']}/check-runs",
|
'Octo RuboCop',
|
||||||
{
|
# [String] The SHA of the commit to check
|
||||||
accept: 'application/vnd.github.v3+json',
|
# The payload structure differs depending on whether a check run or a check suite event occurred.
|
||||||
# The name of your check run.
|
@payload['check_run'].nil? ? @payload['check_suite']['head_sha'] : @payload['check_run']['head_sha'],
|
||||||
name: 'Octo RuboCop',
|
# [Hash] 'Accept' header option, to avoid a warning about the API not being ready for production use.
|
||||||
# The payload structure differs depending on whether a check run or a check suite event occurred.
|
accept: 'application/vnd.github.v3+json'
|
||||||
head_sha: @payload['check_run'].nil? ? @payload['check_suite']['head_sha'] : @payload['check_run']['head_sha']
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
@@ -159,25 +157,22 @@ end
|
|||||||
``` ruby
|
``` ruby
|
||||||
# Create a new check run with the status queued
|
# Create a new check run with the status queued
|
||||||
def create_check_run
|
def create_check_run
|
||||||
# # At the time of writing, Octokit does not support the Checks API yet, but
|
@installation_client.create_check_run(
|
||||||
# it does provide generic HTTP methods you can use:
|
# [String, Integer, Hash, Octokit Repository object] A GitHub repository.
|
||||||
# /rest/reference/checks#create-a-check-run
|
@payload['repository']['full_name'],
|
||||||
check_run = @installation_client.post(
|
# [String] The name of your check run.
|
||||||
"repos/#{@payload['repository']['full_name']}/check-runs",
|
'Octo RuboCop',
|
||||||
{
|
# [String] The SHA of the commit to check
|
||||||
# This header allows for beta access to Checks API
|
# The payload structure differs depending on whether a check run or a check suite event occurred.
|
||||||
accept: 'application/vnd.github.antiope-preview+json',
|
@payload['check_run'].nil? ? @payload['check_suite']['head_sha'] : @payload['check_run']['head_sha'],
|
||||||
# The name of your check run.
|
# [Hash] 'Accept' header option, to avoid a warning about the API not being ready for production use.
|
||||||
name: 'Octo RuboCop',
|
accept: 'application/vnd.github.antiope-preview+json'
|
||||||
# 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']
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
This code calls the "[Create a check run](/rest/reference/checks#create-a-check-run)" endpoint using the generic [HTTP `POST` method](http://octokit.github.io/octokit.rb/Octokit/Connection.html#post-instance_method). This method takes two parameters: the URL of the endpoint and the input parameters to the method.
|
This code calls the "[Create a check run](/rest/reference/checks#create-a-check-run)" endpoint using the [create_check_run method](https://rdoc.info/gems/octokit/Octokit%2FClient%2FChecks:create_check_run).
|
||||||
|
|
||||||
To create a check run, only two input parameters are required: `name` and `head_sha`. We will use [Rubocop](https://rubocop.readthedocs.io/en/latest/) to implement the CI test later in this quickstart, which is why the name "Octo Rubocop" is used here, but you can choose any name you'd like for the check run.
|
To create a check run, only two input parameters are required: `name` and `head_sha`. We will use [Rubocop](https://rubocop.readthedocs.io/en/latest/) to implement the CI test later in this quickstart, which is why the name "Octo Rubocop" is used here, but you can choose any name you'd like for the check run.
|
||||||
|
|
||||||
@@ -240,31 +235,22 @@ def initiate_check_run
|
|||||||
# to 'in_progress' and run the CI process. When the CI finishes, you'll
|
# 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.
|
# update the check run status to 'completed' and add the CI results.
|
||||||
|
|
||||||
# Octokit doesn't yet support the Checks API, but it does provide generic
|
@installation_client.update_check_run(
|
||||||
# HTTP methods you can use:
|
@payload['repository']['full_name'],
|
||||||
# /rest/reference/checks#update-a-check-run
|
@payload['check_run']['id'],
|
||||||
updated_check_run = @installation_client.patch(
|
status: 'in_progress',
|
||||||
"repos/#{@payload['repository']['full_name']}/check-runs/#{@payload['check_run']['id']}",
|
accept: 'application/vnd.github.v3+json'
|
||||||
{
|
|
||||||
accept: 'application/vnd.github.v3+json',
|
|
||||||
name: 'Octo RuboCop',
|
|
||||||
status: 'in_progress',
|
|
||||||
started_at: Time.now.utc.iso8601
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# ***** RUN A CI TEST *****
|
# ***** RUN A CI TEST *****
|
||||||
|
|
||||||
# Mark the check run as complete!
|
# Mark the check run as complete!
|
||||||
updated_check_run = @installation_client.patch(
|
@installation_client.update_check_run(
|
||||||
"repos/#{@payload['repository']['full_name']}/check-runs/#{@payload['check_run']['id']}",
|
@payload['repository']['full_name'],
|
||||||
{
|
@payload['check_run']['id'],
|
||||||
accept: 'application/vnd.github.v3+json',
|
status: 'completed',
|
||||||
name: 'Octo RuboCop',
|
conclusion: 'success',
|
||||||
status: 'completed',
|
accept: 'application/vnd.github.v3+json'
|
||||||
conclusion: 'success',
|
|
||||||
completed_at: Time.now.utc.iso8601
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
@@ -276,40 +262,30 @@ def initiate_check_run
|
|||||||
# to 'in_progress' and run the CI process. When the CI finishes, you'll
|
# 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.
|
# update the check run status to 'completed' and add the CI results.
|
||||||
|
|
||||||
# Octokit doesn't yet support the Checks API, but it does provide generic
|
@installation_client.update_check_run(
|
||||||
# HTTP methods you can use:
|
@payload['repository']['full_name'],
|
||||||
# /rest/reference/checks#update-a-check-run
|
@payload['check_run']['id'],
|
||||||
updated_check_run = @installation_client.patch(
|
status: 'in_progress',
|
||||||
"repos/#{@payload['repository']['full_name']}/check-runs/#{@payload['check_run']['id']}",
|
accept: 'application/vnd.github.antiope-preview+json'
|
||||||
{
|
|
||||||
accept: 'application/vnd.github.antiope-preview+json', # This header is necessary for beta access to Checks API
|
|
||||||
name: 'Octo RuboCop',
|
|
||||||
status: 'in_progress',
|
|
||||||
started_at: Time.now.utc.iso8601
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# ***** RUN A CI TEST *****
|
# ***** RUN A CI TEST *****
|
||||||
|
|
||||||
# Mark the check run as complete!
|
# Mark the check run as complete!
|
||||||
updated_check_run = @installation_client.patch(
|
@installation_client.update_check_run(
|
||||||
"repos/#{@payload['repository']['full_name']}/check-runs/#{@payload['check_run']['id']}",
|
@payload['repository']['full_name'],
|
||||||
{
|
@payload['check_run']['id'],
|
||||||
# This header is necessary for beta access to Checks API
|
status: 'completed',
|
||||||
accept: 'application/vnd.github.antiope-preview+json',
|
conclusion: 'success',
|
||||||
name: 'Octo RuboCop',
|
accept: 'application/vnd.github.antiope-preview+json'
|
||||||
status: 'completed',
|
|
||||||
conclusion: 'success',
|
|
||||||
completed_at: Time.now.utc.iso8601
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
The code above calls the "[Update a check run](/rest/reference/checks#update-a-check-run)" API endpoint using the generic [`patch` HTTP method](http://octokit.github.io/octokit.rb/Octokit/Connection.html#patch-instance_method) to update the check run that you already created.
|
The code above calls the "[Update a check run](/rest/reference/checks#update-a-check-run)" API endpoint using the [`update_check_run` Octokit method](https://rdoc.info/gems/octokit/Octokit%2FClient%2FChecks:update_check_run) to update the check run that you already created.
|
||||||
|
|
||||||
Here's what this code is doing. First, it updates the check run's status to `in_progress` and sets the `started_at` time to the current time. In [Part 2](#part-2-creating-the-octo-rubocop-ci-test) of this quickstart, you'll add code that kicks off a real CI test under `***** RUN A CI TEST *****`. For now, you'll leave that section as a placeholder, so the code that follows it will just simulate that the CI process succeeds and all tests pass. Finally, the code updates the status of the check run again to `completed`.
|
Here's what this code is doing. First, it updates the check run's status to `in_progress` and implicitly sets the `started_at` time to the current time. In [Part 2](#part-2-creating-the-octo-rubocop-ci-test) of this quickstart, you'll add code that kicks off a real CI test under `***** RUN A CI TEST *****`. For now, you'll leave that section as a placeholder, so the code that follows it will just simulate that the CI process succeeds and all tests pass. Finally, the code updates the status of the check run again to `completed`.
|
||||||
|
|
||||||
You'll notice in the "[Update a check run](/rest/reference/checks#update-a-check-run)" docs that when you provide a status of `completed`, the `conclusion` and `completed_at` parameters are required. The `conclusion` summarizes the outcome of a check run and can be `success`, `failure`, `neutral`, `cancelled`, `timed_out`, or `action_required`. You'll set the conclusion to `success`, the `completed_at` time to the current time, and the status to `completed`.
|
You'll notice in the "[Update a check run](/rest/reference/checks#update-a-check-run)" docs that when you provide a status of `completed`, the `conclusion` and `completed_at` parameters are required. The `conclusion` summarizes the outcome of a check run and can be `success`, `failure`, `neutral`, `cancelled`, `timed_out`, or `action_required`. You'll set the conclusion to `success`, the `completed_at` time to the current time, and the status to `completed`.
|
||||||
|
|
||||||
@@ -613,29 +589,23 @@ Now you've got all the information you need to update your check run. In the [fi
|
|||||||
{% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@2.22" or currentVersion == "github-ae@latest" %}
|
{% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@2.22" or currentVersion == "github-ae@latest" %}
|
||||||
``` ruby
|
``` ruby
|
||||||
# Mark the check run as complete!
|
# Mark the check run as complete!
|
||||||
updated_check_run = @installation_client.patch(
|
@installation_client.update_check_run(
|
||||||
"repos/#{@payload['repository']['full_name']}/check-runs/#{@payload['check_run']['id']}",
|
@payload['repository']['full_name'],
|
||||||
{
|
@payload['check_run']['id'],
|
||||||
accept: 'application/vnd.github.v3+json',
|
status: 'completed',
|
||||||
name: 'Octo RuboCop',
|
conclusion: 'success',
|
||||||
status: 'completed',
|
accept: 'application/vnd.github.v3+json'
|
||||||
conclusion: 'success',
|
|
||||||
completed_at: Time.now.utc.iso8601
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
{% else %}
|
{% else %}
|
||||||
``` ruby
|
``` ruby
|
||||||
# Mark the check run as complete!
|
# Mark the check run as complete!
|
||||||
updated_check_run = @installation_client.patch(
|
@installation_client.update_check_run(
|
||||||
"repos/#{@payload['repository']['full_name']}/check-runs/#{@payload['check_run']['id']}",
|
@payload['repository']['full_name'],
|
||||||
{
|
@payload['check_run']['id'],
|
||||||
accept: 'application/vnd.github.antiope-preview+json', # This header is necessary for beta access to Checks API
|
status: 'completed',
|
||||||
name: 'Octo RuboCop',
|
conclusion: 'success',
|
||||||
status: 'completed',
|
accept: 'application/vnd.github.antiope-preview+json' # This header is necessary for beta access to Checks API
|
||||||
conclusion: 'success',
|
|
||||||
completed_at: Time.now.utc.iso8601
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -645,51 +615,45 @@ You'll need to update that code to use the `conclusion` variable you set based o
|
|||||||
{% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@2.22" or currentVersion == "github-ae@latest" %}
|
{% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@2.22" or currentVersion == "github-ae@latest" %}
|
||||||
``` ruby
|
``` ruby
|
||||||
# Mark the check run as complete! And if there are warnings, share them.
|
# Mark the check run as complete! And if there are warnings, share them.
|
||||||
updated_check_run = @installation_client.patch(
|
@installation_client.update_check_run(
|
||||||
"repos/#{@payload['repository']['full_name']}/check-runs/#{@payload['check_run']['id']}",
|
@payload['repository']['full_name'],
|
||||||
{
|
@payload['check_run']['id'],
|
||||||
accept: 'application/vnd.github.v3+json',
|
status: 'completed',
|
||||||
name: 'Octo RuboCop',
|
conclusion: conclusion,
|
||||||
status: 'completed',
|
output: {
|
||||||
conclusion: conclusion,
|
title: 'Octo RuboCop',
|
||||||
completed_at: Time.now.utc.iso8601,
|
summary: summary,
|
||||||
output: {
|
text: text,
|
||||||
title: 'Octo RuboCop',
|
annotations: annotations
|
||||||
summary: summary,
|
},
|
||||||
text: text,
|
actions: [{
|
||||||
annotations: annotations
|
label: 'Fix this',
|
||||||
},
|
description: 'Automatically fix all linter notices.',
|
||||||
actions: [{
|
identifier: 'fix_rubocop_notices'
|
||||||
label: 'Fix this',
|
}],
|
||||||
description: 'Automatically fix all linter notices.',
|
accept: 'application/vnd.github.v3+json'
|
||||||
identifier: 'fix_rubocop_notices'
|
|
||||||
}]
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
{% else %}
|
{% else %}
|
||||||
``` ruby
|
``` ruby
|
||||||
# Mark the check run as complete! And if there are warnings, share them.
|
# Mark the check run as complete! And if there are warnings, share them.
|
||||||
updated_check_run = @installation_client.patch(
|
@installation_client.update_check_run(
|
||||||
"repos/#{@payload['repository']['full_name']}/check-runs/#{@payload['check_run']['id']}",
|
@payload['repository']['full_name'],
|
||||||
{
|
@payload['check_run']['id'],
|
||||||
accept: 'application/vnd.github.antiope-preview+json',
|
status: 'completed',
|
||||||
name: 'Octo RuboCop',
|
conclusion: conclusion,
|
||||||
status: 'completed',
|
output: {
|
||||||
conclusion: conclusion,
|
title: 'Octo RuboCop',
|
||||||
completed_at: Time.now.utc.iso8601,
|
summary: summary,
|
||||||
output: {
|
text: text,
|
||||||
title: 'Octo RuboCop',
|
annotations: annotations
|
||||||
summary: summary,
|
},
|
||||||
text: text,
|
actions: [{
|
||||||
annotations: annotations
|
label: 'Fix this',
|
||||||
},
|
description: 'Automatically fix all linter notices.',
|
||||||
actions: [{
|
identifier: 'fix_rubocop_notices'
|
||||||
label: 'Fix this',
|
}],
|
||||||
description: 'Automatically fix all linter notices.',
|
accept: 'application/vnd.github.antiope-preview+json'
|
||||||
identifier: 'fix_rubocop_notices'
|
|
||||||
}]
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
Reference in New Issue
Block a user