From dc92027639d0950e5a3353c3c462a915394912a3 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Fri, 10 Mar 2017 15:09:56 -0500 Subject: [PATCH] spec: also set required context on PRs For the same reasons the 'required' context is useful for branches, it can also be useful for PRs: it allows repo admins to set a single status as required in the branch protection settings rather than multiple, possibly changing, statuses. This also specifically helps with status-based exemptions in Homu: by having the required context set on the PR, Homu will be able to determine whether it can safely skip re-testing the code on the auto branch. --- sample.redhat-ci.yml | 13 ++++++------- spawner.py | 16 ++++++++++------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/sample.redhat-ci.yml b/sample.redhat-ci.yml index 01bf5fe..c3a343b 100644 --- a/sample.redhat-ci.yml +++ b/sample.redhat-ci.yml @@ -111,13 +111,12 @@ context: 'CI Tester' # OPTIONAL # Mark this testsuite as required. This causes a special -# "required" context to be reported to GitHub on branch -# tests. The result is set to successful only if all -# testsuites marked as required are also successful. This is -# useful for integration with merge bots, so that they only -# need to watch for a single status rather than multiple -# (possibly changing) statuses. If omitted, defaults to -# false. +# "required" context to be reported to GitHub. The result is +# set to successful only if all testsuites marked as +# required are also successful. This is useful for +# integration with merge bots, so that they only need to +# watch for a single status rather than multiple (possibly +# changing) statuses. If omitted, defaults to false. required: true # OPTIONAL diff --git a/spawner.py b/spawner.py index 033653c..023f142 100755 --- a/spawner.py +++ b/spawner.py @@ -153,9 +153,14 @@ def count_failures(suites): def update_required_context(suites): - # only send 'required' context for branches if 'github_pull_id' in os.environ: - return + fallback_url = ('https://github.com/%s/pull/%s' % + (os.environ['github_repo'], + os.environ['github_pull_id'])) + else: + fallback_url = ('https://github.com/%s/commits/%s' % + (os.environ['github_repo'], + os.environ['github_branch'])) # don't send 'required' context if we're only targeting some testsuites if 'github_contexts' in os.environ: @@ -178,10 +183,9 @@ def update_required_context(suites): url = f.read().strip() else: # Something went really wrong in the tester. Just link back to the - # branch for now, though we should probably just capture the same - # text we used to update the commit status. - url = ('https://github.com/%s/commits/%s' % - (os.environ['github_repo'], os.environ['github_branch'])) + # branch/PR for now, though we should probably just capture the + # same text we used to update the commit status. + url = fallback_url result = (suite['rc'] == 0) results_suites.append((name, result, url))