Skip to content

Commit 9046777

Browse files
authored
Merge pull request #92 from github/repo-sync
repo sync
2 parents 9acc5a5 + 44145e4 commit 9046777

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed

content/developers/apps/creating-ci-tests-with-the-checks-api.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,26 @@ The `requested` action requests a check run each time code is pushed to the repo
133133

134134
You'll add this new method as a [Sinatra helper](https://github.com/sinatra/sinatra#helpers) in case you want other routes to use it too. Under `helpers do`, add this `create_check_run` method:
135135

136+
{% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@2.22" %}
137+
``` ruby
138+
# Create a new check run with the status queued
139+
def create_check_run
140+
# # At the time of writing, Octokit does not support the Checks API yet, but
141+
# it does provide generic HTTP methods you can use:
142+
# /v3/checks/runs/#create-a-check-run
143+
check_run = @installation_client.post(
144+
"repos/#{@payload['repository']['full_name']}/check-runs",
145+
{
146+
accept: 'application/vnd.github.v3+json',
147+
# The name of your check run.
148+
name: 'Octo RuboCop',
149+
# The payload structure differs depending on whether a check run or a check suite event occurred.
150+
head_sha: @payload['check_run'].nil? ? @payload['check_suite']['head_sha'] : @payload['check_run']['head_sha']
151+
}
152+
)
153+
end
154+
```
155+
{% else %}
136156
``` ruby
137157
# Create a new check run with the status queued
138158
def create_check_run
@@ -152,6 +172,7 @@ def create_check_run
152172
)
153173
end
154174
```
175+
{% endif %}
155176

156177
This code calls the "[Create a check run](/v3/checks/runs/#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.
157178

@@ -208,6 +229,43 @@ In this section, you're not going to kick off the CI test yet, but you'll walk t
208229

209230
Let's create the `initiate_check_run` method and update the status of the check run. Add the following code to the helpers section:
210231

232+
{% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@2.22" %}
233+
``` ruby
234+
# Start the CI process
235+
def initiate_check_run
236+
# Once the check run is created, you'll update the status of the check run
237+
# to 'in_progress' and run the CI process. When the CI finishes, you'll
238+
# update the check run status to 'completed' and add the CI results.
239+
240+
# Octokit doesn't yet support the Checks API, but it does provide generic
241+
# HTTP methods you can use:
242+
# /v3/checks/runs/#update-a-check-run
243+
updated_check_run = @installation_client.patch(
244+
"repos/#{@payload['repository']['full_name']}/check-runs/#{@payload['check_run']['id']}",
245+
{
246+
accept: 'application/vnd.github.v3+json',
247+
name: 'Octo RuboCop',
248+
status: 'in_progress',
249+
started_at: Time.now.utc.iso8601
250+
}
251+
)
252+
253+
# ***** RUN A CI TEST *****
254+
255+
# Mark the check run as complete!
256+
updated_check_run = @installation_client.patch(
257+
"repos/#{@payload['repository']['full_name']}/check-runs/#{@payload['check_run']['id']}",
258+
{
259+
accept: 'application/vnd.github.v3+json',
260+
name: 'Octo RuboCop',
261+
status: 'completed',
262+
conclusion: 'success',
263+
completed_at: Time.now.utc.iso8601
264+
}
265+
)
266+
end
267+
```
268+
{% else %}
211269
``` ruby
212270
# Start the CI process
213271
def initiate_check_run
@@ -244,6 +302,7 @@ def initiate_check_run
244302
)
245303
end
246304
```
305+
{% endif %}
247306

248307
The code above calls the "[Update a check run](/v3/checks/runs/#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.
249308

@@ -548,6 +607,21 @@ text = "Octo RuboCop version: #{@output['metadata']['rubocop_version']}"
548607

549608
Now you've got all the information you need to update your check run. In the [first half of this quickstart](#step-14-updating-a-check-run), you added this code to set the status of the check run to `success`:
550609

610+
{% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@2.22" %}
611+
``` ruby
612+
# Mark the check run as complete!
613+
updated_check_run = @installation_client.patch(
614+
"repos/#{@payload['repository']['full_name']}/check-runs/#{@payload['check_run']['id']}",
615+
{
616+
accept: 'application/vnd.github.v3+json',
617+
name: 'Octo RuboCop',
618+
status: 'completed',
619+
conclusion: 'success',
620+
completed_at: Time.now.utc.iso8601
621+
}
622+
)
623+
```
624+
{% else %}
551625
``` ruby
552626
# Mark the check run as complete!
553627
updated_check_run = @installation_client.patch(
@@ -561,9 +635,36 @@ updated_check_run = @installation_client.patch(
561635
}
562636
)
563637
```
638+
{% endif %}
564639

565640
You'll need to update that code to use the `conclusion` variable you set based on the RuboCop results (to `success` or `neutral`). You can update the code with the following:
566641

642+
{% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@2.22" %}
643+
``` ruby
644+
# Mark the check run as complete! And if there are warnings, share them.
645+
updated_check_run = @installation_client.patch(
646+
"repos/#{@payload['repository']['full_name']}/check-runs/#{@payload['check_run']['id']}",
647+
{
648+
accept: 'application/vnd.github.v3+json',
649+
name: 'Octo RuboCop',
650+
status: 'completed',
651+
conclusion: conclusion,
652+
completed_at: Time.now.utc.iso8601,
653+
output: {
654+
title: 'Octo RuboCop',
655+
summary: summary,
656+
text: text,
657+
annotations: annotations
658+
},
659+
actions: [{
660+
label: 'Fix this',
661+
description: 'Automatically fix all linter notices.',
662+
identifier: 'fix_rubocop_notices'
663+
}]
664+
}
665+
)
666+
```
667+
{% else %}
567668
``` ruby
568669
# Mark the check run as complete! And if there are warnings, share them.
569670
updated_check_run = @installation_client.patch(
@@ -588,6 +689,7 @@ updated_check_run = @installation_client.patch(
588689
}
589690
)
590691
```
692+
{% endif %}
591693

592694
Now that you're setting a conclusion based on the status of the CI test and you've added the output from the RuboCop results, you've created a CI test! Congratulations. 🙌
593695

content/rest/overview/api-previews.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,24 @@ You can now [require multiple approving reviews](/v3/repos/branches) for a pull
166166
**Custom media type:** `luke-cage-preview`
167167
**Announced:** [2018-03-16](https://developer.github.com/changes/2018-03-16-protected-branches-required-approving-reviews)
168168

169+
{% if currentVersion != "free-pro-team@latest" and currentVersion ver_lt "enterprise-server@2.19" %}
170+
### Retrieve hovercard information
171+
172+
Retrieve information from [someone's hovercard](/v3/users/#get-contextual-information-for-a-user).
173+
174+
**Custom media type:** `hagar-preview`
175+
**Announced:** [2018-03-21](https://developer.github.com/changes/2018-03-21-hovercard-api-preview)
176+
177+
{% endif %}
178+
179+
{% if currentVersion ver_lt "enterprise-server@2.23" %}
169180
### Check runs and check suites API
170181

171182
Allows a GitHub App to run external checks on a repository's code. See the [Check runs](/v3/checks/runs/) and [Check suites](/v3/checks/suites/) APIs for more details.
172183

173184
**Custom media type:** `antiope-preview`
174185
**Announced:** [2018-05-07](https://developer.github.com/changes/2018-05-07-new-checks-api-public-beta/)
186+
{% endif %}
175187

176188
{% if currentVersion != "free-pro-team@latest" %}
177189

0 commit comments

Comments
 (0)