Skip to content
This repository has been archived by the owner on Mar 22, 2021. It is now read-only.

Commit

Permalink
spec: also set required context on PRs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jlebon committed Mar 10, 2017
1 parent 2ae975f commit dc92027
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
13 changes: 6 additions & 7 deletions sample.redhat-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 10 additions & 6 deletions spawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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))

Expand Down

0 comments on commit dc92027

Please sign in to comment.