diff --git a/easybuild/tools/github.py b/easybuild/tools/github.py index 340ce2c8fd..1b7a443183 100644 --- a/easybuild/tools/github.py +++ b/easybuild/tools/github.py @@ -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', } @@ -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) @@ -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) @@ -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: @@ -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): diff --git a/test/framework/github.py b/test/framework/github.py index b403f6c947..13ed6efd6b 100644 --- a/test/framework/github.py +++ b/test/framework/github.py @@ -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 @@ -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))