Skip to content

Commit

Permalink
Merge pull request #525 from plone/revert-522-pull-request-update-py3…
Browse files Browse the repository at this point in the history
…6-43

Revert "Update pull request status script to python 3.6 [4.3]"
  • Loading branch information
gforcada authored Oct 4, 2018
2 parents 102ee7a + 843db36 commit 6cf9228
Showing 1 changed file with 47 additions and 29 deletions.
76 changes: 47 additions & 29 deletions templates/pr-update-status.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,6 @@
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 @@ -58,7 +42,18 @@ def error(message):
try:
github_api_key = os.environ['GITHUB_API_KEY']
except KeyError:
error('GITHUB_API_KEY does not exist, pull requests can not be updated.')
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)

pull_request_urls = os.environ['PULL_REQUEST_URL']
build_url = os.environ['BUILD_URL']
Expand All @@ -73,33 +68,56 @@ def error(message):
try:
g_org = g.get_organization(org)
except BadCredentialsException:
error('The API key used seems to not be valid any longer.')
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)
except UnknownObjectException:
error(
f'Error on trying to get info from Pull Request {pr}'
msg = (
'\n\n\n'
'Error on trying to get info from Pull Request %s'
'\n'
f'The organization "{org}" does not seem to exist.'
'The organization "%s" does not seem to exist.'
'\n\n\n'
)
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:
error(
f'Error on trying to get info from Pull Request {pr}'
msg = (
'\n\n\n'
'Error on trying to get info from Pull Request %s'
'\n'
f'The repository "{repo}" does not seem to exist.'
'The repository "%s" does not seem to exist.'
'\n\n\n'
)
print(msg % (pr, repo))
sys.exit(0)

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

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

0 comments on commit 6cf9228

Please sign in to comment.