Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pull request status script to python 3.6 [4.3] #522

Merged
merged 1 commit into from
Oct 4, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 29 additions & 47 deletions templates/pr-update-status.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@
import re
import sys


def error(message):
print(
'\n\n\n'
f'{message}'
'\n'
'Please contact the testing team: '
'https://github.com/orgs/plone/teams/testing-team'
'\n'
'Fill an issue as well: '
'https://github.com/plone/jenkins.plone.org/issues/new'
'\n\n\n'
)
sys.exit(1)


job_name = os.environ['JOB_NAME']
tests_folder = 'parts/test/testreports'
if '4.3' in job_name:
Expand Down Expand Up @@ -42,18 +58,7 @@
try:
github_api_key = os.environ['GITHUB_API_KEY']
except KeyError:
print(
'\n\n\n'
'GITHUB_API_KEY does not exist, pull requests can not be updated. '
'\n'
'Please contact the testing team: '
'https://github.com/orgs/plone/teams/testing-team'
'\n'
'Fill an issue as well: '
'https://github.com/plone/jenkins.plone.org/issues/new'
'\n\n\n'
)
sys.exit(0)
error('GITHUB_API_KEY does not exist, pull requests can not be updated.')

pull_request_urls = os.environ['PULL_REQUEST_URL']
build_url = os.environ['BUILD_URL']
Expand All @@ -68,56 +73,33 @@
try:
g_org = g.get_organization(org)
except BadCredentialsException:
print(
'\n\n\n'
'The API key used seems to not be valid any longer.'
'\n'
'Please contact the testing team: '
'https://github.com/orgs/plone/teams/testing-team'
'\n'
'Fill an issue as well: '
'https://github.com/plone/jenkins.plone.org/issues/new'
'\n\n\n'
)
sys.exit(0)
error('The API key used seems to not be valid any longer.')
except UnknownObjectException:
msg = (
'\n\n\n'
'Error on trying to get info from Pull Request %s'
error(
f'Error on trying to get info from Pull Request {pr}'
'\n'
'The organization "%s" does not seem to exist.'
'\n\n\n'
f'The organization "{org}" does not seem to exist.'
)
print(msg % (pr, org))
sys.exit(0)

# the repo where the pull request is from
try:
g_repo = g_org.get_repo(repo)
except UnknownObjectException:
msg = (
'\n\n\n'
'Error on trying to get info from Pull Request %s'
error(
f'Error on trying to get info from Pull Request {pr}'
'\n'
'The repository "%s" does not seem to exist.'
'\n\n\n'
f'The repository "{repo}" does not seem to exist.'
)
print(msg % (pr, repo))
sys.exit(0)

# the pull request itself
try:
g_pr = g_repo.get_pull(pr_number)
except UnknownObjectException:
msg = (
'\n\n\n'
'Error on trying to get info from Pull Request %s'
error(
f'Error on trying to get info from Pull Request {pr}'
'\n'
'The pull request num "%s" does not seem to exist.'
'\n\n\n'
f'The pull request num "{pr_number}" does not seem to exist.'
)
print(msg % (pr, pr_number))
sys.exit(0)

# get the branch
branch = g_pr.head.ref
Expand All @@ -131,6 +113,6 @@
last_commit.create_status(
status,
target_url=build_url,
description=u'Job finished with %s status' % status,
context='Plone Jenkins CI - {0}'.format(job_name),
description=f'Job finished with {status} status',
context=f'Plone Jenkins CI - {job_name}',
)