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.

Closes: #30
Approved by: cgwalters
  • Loading branch information
jlebon authored and rh-atomic-bot committed Sep 27, 2017
1 parent e7472d8 commit 9d5f60b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
13 changes: 6 additions & 7 deletions docs/sample.papr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,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 grouping
# statuses under a single context to be used by the branch
# protection settings or by a merge bot, rather than dealing
# with multiple (possibly changing) statuses.
required: true

# OPTIONAL
Expand Down
19 changes: 12 additions & 7 deletions papr/spawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,17 @@ def count_failures(suites):

def update_required_context(suites):

# only send 'required' context for branches
# Prepare a fallback URL in case something goes really wrong in the tester.
# We just link back to the branch/PR for now, though we should probably
# just capture the same text we used to update the commit status.
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 @@ -185,11 +193,8 @@ def update_required_context(suites):
with open("state/suite-%d/url" % i) as f:
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']))
# something went really wrong in the tester, just use fallback url
url = fallback_url
result = (suite['rc'] == 0)
results_suites.append((name, result, url))

Expand Down

0 comments on commit 9d5f60b

Please sign in to comment.