Skip to content

Commit 2b46a6d

Browse files
authored
Merge pull request #10 from rust-ops/checks-api
Add support for GitHub Checks
2 parents 5769143 + 29e59f4 commit 2b46a6d

File tree

5 files changed

+57
-14
lines changed

5 files changed

+57
-14
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
sudo: false
22
language: python
33
python:
4-
- 3.3
54
- 3.4
65
- 3.5
76
install:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ the name of the repository you are configuring homu for.
107107
- Payload URL: `http://HOST:PORT/github`
108108
- Content type: `application/json`
109109
- Secret: The same as `repo.NAME.github.secret` in `cfg.toml`
110-
- Events: `Issue Comment`, `Pull Request`, `Push`, `Status`
110+
- Events: `Issue Comment`, `Pull Request`, `Push`, `Status`, `Check runs`
111111

112112
6. Add a Webhook to your continuous integration service, if necessary. You don't
113113
need this if using Travis/Appveyor.

cfg.sample.toml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ secret = ""
120120
#]
121121

122122
# Travis integration. Don't forget to allow Travis to test the `auto` branch!
123-
[repo.NAME.status.travis]
124-
# String label set by status updates. Don't touch this unless you really know
125-
# what you're doing.
126-
context = 'continuous-integration/travis-ci/push'
123+
[repo.NAME.checks.travis]
124+
# Name of the Checks API run. Don't touch this unless you really know what
125+
# you're doing.
126+
name = "Travis CI - Branch"
127127

128128
# Appveyor integration. Don't forget to allow Appveyor to test the `auto` branch!
129129
#[repo.NAME.status.appveyor]
@@ -144,6 +144,13 @@ context = 'continuous-integration/travis-ci/push'
144144
# only used if status_based_exemption is true.
145145
#pr_context = ""
146146

147+
# Generic GitHub Checks API support. You don't need this if you're using the
148+
# above examples for Travis/Appveyor.
149+
#[repo.NAME.checks.LABEL]
150+
#
151+
# String name of the Checks run.
152+
#name = ""
153+
147154
# Use buildbot for running tests
148155
#[repo.NAME.buildbot]
149156
#

homu/main.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ def start_testing(self, timeout):
346346
self.set_status('pending')
347347

348348
wm = weakref.WeakMethod(self.timed_out)
349+
349350
def timed_out():
350351
m = wm()
351352
if m:
@@ -874,12 +875,12 @@ def create_merge(state, repo_cfg, branch, logger, git_cfg,
874875
'You may also read'
875876
' [*Git Rebasing to Resolve Conflicts* by Drew Blessing](http://blessing.io/git/git-rebase/open-source/2015/08/23/git-rebasing-to-resolve-conflicts.html)' # noqa
876877
' for a short tutorial.\n\n'
877-
'Please avoid the ["**Resolve conflicts**" button](https://help.github.com/articles/resolving-a-merge-conflict-on-github/) on GitHub.' #noqa
878-
' It uses `git merge` instead of `git rebase` which makes the PR commit'
878+
'Please avoid the ["**Resolve conflicts**" button](https://help.github.com/articles/resolving-a-merge-conflict-on-github/) on GitHub.' # noqa
879+
' It uses `git merge` instead of `git rebase` which makes the PR commit' # noqa
879880
' history more difficult to read.\n\n'
880881
'Sometimes step 4 will complete without asking for resolution. This is'
881882
' usually due to difference between how `Cargo.lock` conflict is'
882-
' handled during merge and rebase. This is normal, and you should still'
883+
' handled during merge and rebase. This is normal, and you should still' # noqa
883884
' perform step 5 to update this PR.\n\n'
884885
'</details>\n\n'
885886
).format(branch=state.head_ref.split(':', 1)[1])
@@ -974,7 +975,7 @@ def create_merge(state, repo_cfg, branch, logger, git_cfg,
974975
stderr=subprocess.STDOUT,
975976
universal_newlines=True)
976977
except subprocess.CalledProcessError as e:
977-
comment += '<details><summary>Error message</summary>\n\n```text\n'
978+
comment += '<details><summary>Error message</summary>\n\n```text\n' # noqa
978979
comment += e.output
979980
comment += '\n```\n\n</details>'
980981
pass
@@ -1235,6 +1236,9 @@ def start_build(state, repo_cfgs, buildbot_slots, logger, db, git_cfg):
12351236

12361237
if found_travis_context and len(builders) == 1:
12371238
can_try_travis_exemption = True
1239+
if 'checks' in repo_cfg:
1240+
builders += ['checks-' + key for key, value in repo_cfg['checks'].items() if 'name' in value] # noqa
1241+
only_status_builders = False
12381242

12391243
if len(builders) is 0:
12401244
raise RuntimeError('Invalid configuration')
@@ -1679,6 +1683,8 @@ def main():
16791683
builders += ['travis']
16801684
if 'status' in repo_cfg:
16811685
builders += ['status-' + key for key, value in repo_cfg['status'].items() if 'context' in value] # noqa
1686+
if 'checks' in repo_cfg:
1687+
builders += ['checks-' + key for key, value in repo_cfg['checks'].items() if 'name' in value] # noqa
16821688
if len(builders) is 0:
16831689
raise RuntimeError('Invalid configuration')
16841690

homu/server.py

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,10 @@ def callback():
196196
logger.warn('/callback encountered an error '
197197
'during github oauth callback')
198198
# probably related to https://gitlab.com/pycqa/flake8/issues/42
199-
lazy_debug(logger, lambda: 'github oauth callback err: {}'.format(ex)) # noqa
199+
lazy_debug(
200+
logger,
201+
lambda ex=ex: 'github oauth callback err: {}'.format(ex),
202+
)
200203
abort(502, 'Bad Gateway')
201204

202205
args = urllib.parse.parse_qs(res.text)
@@ -514,6 +517,33 @@ def fail(err):
514517
report_build_res(info['state'] == 'success', info['target_url'],
515518
'status-' + status_name, state, logger, repo_cfg)
516519

520+
elif event_type == 'check_run':
521+
try:
522+
state, repo_label = find_state(info['check_run']['head_sha'])
523+
except ValueError:
524+
return 'OK'
525+
526+
current_run_name = info['check_run']['name']
527+
checks_name = None
528+
if 'checks' in repo_cfg:
529+
for name, value in repo_cfg['checks'].items():
530+
if 'name' in value and value['name'] == current_run_name:
531+
checks_name = name
532+
if checks_name is None:
533+
return 'OK'
534+
535+
if info['check_run']['status'] != 'completed':
536+
return 'OK'
537+
if info['check_run']['conclusion'] is None:
538+
return 'OK'
539+
540+
report_build_res(
541+
info['check_run']['conclusion'] == 'success',
542+
info['check_run']['details_url'],
543+
'checks-' + checks_name,
544+
state, logger, repo_cfg,
545+
)
546+
517547
return 'OK'
518548

519549

@@ -653,9 +683,10 @@ def buildbot():
653683
except Exception as ex:
654684
logger.warn('/buildbot encountered an error during '
655685
'github logs request')
656-
# probably related to
657-
# https://gitlab.com/pycqa/flake8/issues/42
658-
lazy_debug(logger, lambda: 'buildbot logs err: {}'.format(ex)) # noqa
686+
lazy_debug(
687+
logger,
688+
lambda ex=ex: 'buildbot logs err: {}'.format(ex),
689+
)
659690
abort(502, 'Bad Gateway')
660691

661692
mat = INTERRUPTED_BY_HOMU_RE.search(res.text)

0 commit comments

Comments
 (0)