From 39b88bfdd92119869f138c24b634fdf6b680da29 Mon Sep 17 00:00:00 2001 From: Miguel Dias Costa Date: Wed, 2 Oct 2019 10:12:48 +0800 Subject: [PATCH 1/3] add closing to reopen as a reason to --close-pr --- easybuild/tools/github.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/easybuild/tools/github.py b/easybuild/tools/github.py index 340ce2c8fd..b8b9be8583 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', + 'reopen': '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['reopen'] + 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): From aa991ca1ae691d07054d6c50de184d9a119296b8 Mon Sep 17 00:00:00 2001 From: Miguel Dias Costa Date: Wed, 2 Oct 2019 15:11:29 +0800 Subject: [PATCH 2/3] rename --close-pr reopen reason to retest and enhance test --- easybuild/tools/github.py | 4 ++-- test/framework/github.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/easybuild/tools/github.py b/easybuild/tools/github.py index b8b9be8583..1b7a443183 100644 --- a/easybuild/tools/github.py +++ b/easybuild/tools/github.py @@ -107,7 +107,7 @@ 'archived': 'uses an archived toolchain', 'inactive': 'no activity for > 6 months', 'obsolete': 'obsoleted by more recent PRs', - 'reopen': 'closing and reopening to trigger tests', + 'retest': 'closing and reopening to trigger tests', } @@ -1110,7 +1110,7 @@ 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['reopen'] + reopen = motivation_msg == VALID_CLOSE_PR_REASONS['retest'] if not motivation_msg: print_msg("No reason or message specified, looking for possible reasons\n") diff --git a/test/framework/github.py b/test/framework/github.py index b403f6c947..3f68e8d084 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 @@ -227,6 +228,23 @@ def test_close_pr(self): 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 pull request #2", + "[DRY RUN] Reopened hpcugent/testrepository pull request #2", + ] + for pattern in patterns: + self.assertTrue(pattern in stdout, "Pattern '%s' found in: %s" % (pattern, stdout)) + def test_fetch_easyconfigs_from_pr(self): """Test fetch_easyconfigs_from_pr function.""" if self.skip_github_tests: From 75ce731714458f2bfce5dcaf527488a991a0edc0 Mon Sep 17 00:00:00 2001 From: Miguel Dias Costa Date: Wed, 2 Oct 2019 15:22:51 +0800 Subject: [PATCH 3/3] fix test --- test/framework/github.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/framework/github.py b/test/framework/github.py index 3f68e8d084..13ed6efd6b 100644 --- a/test/framework/github.py +++ b/test/framework/github.py @@ -223,7 +223,7 @@ 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)) @@ -239,8 +239,8 @@ 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): %s" % retest_msg, - "[DRY RUN] Closed hpcugent/testrepository pull request #2", - "[DRY RUN] Reopened hpcugent/testrepository pull request #2", + "[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))