Skip to content

Commit

Permalink
Merge pull request #522 from plone/pull-request-update-py36-43
Browse files Browse the repository at this point in the history
Update pull request status script to python 3.6 [4.3]
  • Loading branch information
gforcada authored Oct 4, 2018
2 parents b115832 + f05cd55 commit 102ee7a
Showing 1 changed file with 29 additions and 47 deletions.
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}',
)

0 comments on commit 102ee7a

Please sign in to comment.