Skip to content

Commit

Permalink
Merge pull request #3040 from migueldiascosta/trigger
Browse files Browse the repository at this point in the history
add 'retest' as a reason to --close-pr, to close/re-open PRs to trigger re-test in Travis
  • Loading branch information
boegel authored Oct 12, 2019
2 parents 6c45977 + 75ce731 commit 528cd09
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
25 changes: 18 additions & 7 deletions easybuild/tools/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
'archived': 'uses an archived toolchain',
'inactive': 'no activity for > 6 months',
'obsolete': 'obsoleted by more recent PRs',
'retest': 'closing and reopening to trigger tests',
}


Expand Down Expand Up @@ -668,7 +669,7 @@ def _easyconfigs_pr_common(paths, ecs, start_branch=None, pr_branch=None, start_
if paths['easyconfigs']:
for path in paths['easyconfigs']:
if not os.path.exists(path):
non_existing_paths.append(path)
non_existing_paths.append(path)
else:
ec_paths.append(path)

Expand Down Expand Up @@ -1109,6 +1110,8 @@ def close_pr(pr, motivation_msg=None):

dry_run = build_option('dry_run') or build_option('extended_dry_run')

reopen = motivation_msg == VALID_CLOSE_PR_REASONS['retest']

if not motivation_msg:
print_msg("No reason or message specified, looking for possible reasons\n")
possible_reasons = reasons_for_closing(pr_data)
Expand All @@ -1120,15 +1123,18 @@ def close_pr(pr, motivation_msg=None):
motivation_msg = ", ".join([VALID_CLOSE_PR_REASONS[reason] for reason in possible_reasons])
print_msg("\nNo reason specified but found possible reasons: %s.\n" % motivation_msg, prefix=False)

msg = "@%s, this PR is being closed for the following reason(s): %s.\n" % (pr_data['user']['login'], motivation_msg)
msg += "Please don't hesitate to reopen this PR or add a comment if you feel this contribution is still relevant.\n"
msg += "For more information on our policy w.r.t. closing PRs, see "
msg += "https://easybuild.readthedocs.io/en/latest/Contributing.html"
msg += "#why-a-pull-request-may-be-closed-by-a-maintainer"
msg = "@%s, this PR is being closed for the following reason(s): %s." % (pr_data['user']['login'], motivation_msg)
if not reopen:
msg += "\nPlease don't hesitate to reopen this PR or add a comment if you feel this contribution is still "
msg += "relevant.\nFor more information on our policy w.r.t. closing PRs, see "
msg += "https://easybuild.readthedocs.io/en/latest/Contributing.html"
msg += "#why-a-pull-request-may-be-closed-by-a-maintainer"
post_comment_in_issue(pr, msg, account=pr_target_account, repo=pr_target_repo, github_user=github_user)

if dry_run:
print_msg("[DRY RUN] Closed %s/%s pull request #%s" % (pr_target_account, pr_target_repo, pr), prefix=False)
print_msg("[DRY RUN] Closed %s/%s PR #%s" % (pr_target_account, pr_target_repo, pr), prefix=False)
if reopen:
print_msg("[DRY RUN] Reopened %s/%s PR #%s" % (pr_target_account, pr_target_repo, pr), prefix=False)
else:
github_token = fetch_github_token(github_user)
if github_token is None:
Expand All @@ -1139,6 +1145,11 @@ def close_pr(pr, motivation_msg=None):
status, data = pull_url.post(body=body)
if not status == HTTP_STATUS_OK:
raise EasyBuildError("Failed to close PR #%s; status %s, data: %s", pr, status, data)
if reopen:
body = {'state': 'open'}
status, data = pull_url.post(body=body)
if not status == HTTP_STATUS_OK:
raise EasyBuildError("Failed to reopen PR #%s; status %s, data: %s", pr, status, data)


def list_prs(params, per_page=GITHUB_MAX_PER_PAGE, github_user=None):
Expand Down
20 changes: 19 additions & 1 deletion test/framework/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from easybuild.tools.config import module_classes
from easybuild.tools.configobj import ConfigObj
from easybuild.tools.filetools import read_file, write_file
from easybuild.tools.github import VALID_CLOSE_PR_REASONS
from easybuild.tools.py2vs3 import HTTPError, URLError, ascii_letters
import easybuild.tools.github as gh

Expand Down Expand Up @@ -222,7 +223,24 @@ def test_close_pr(self):
"hpcugent/testrepository PR #2 was submitted by migueldiascosta",
"[DRY RUN] Adding comment to testrepository issue #2: '" +
"@migueldiascosta, this PR is being closed for the following reason(s): just a test",
"[DRY RUN] Closed hpcugent/testrepository pull request #2",
"[DRY RUN] Closed hpcugent/testrepository PR #2",
]
for pattern in patterns:
self.assertTrue(pattern in stdout, "Pattern '%s' found in: %s" % (pattern, stdout))

retest_msg = VALID_CLOSE_PR_REASONS['retest']

self.mock_stdout(True)
gh.close_pr(2, motivation_msg=retest_msg)
stdout = self.get_stdout()
self.mock_stdout(False)

patterns = [
"hpcugent/testrepository PR #2 was submitted by migueldiascosta",
"[DRY RUN] Adding comment to testrepository issue #2: '" +
"@migueldiascosta, this PR is being closed for the following reason(s): %s" % retest_msg,
"[DRY RUN] Closed hpcugent/testrepository PR #2",
"[DRY RUN] Reopened hpcugent/testrepository PR #2",
]
for pattern in patterns:
self.assertTrue(pattern in stdout, "Pattern '%s' found in: %s" % (pattern, stdout))
Expand Down

0 comments on commit 528cd09

Please sign in to comment.