Skip to content

Commit 528cd09

Browse files
authored
Merge pull request #3040 from migueldiascosta/trigger
add 'retest' as a reason to --close-pr, to close/re-open PRs to trigger re-test in Travis
2 parents 6c45977 + 75ce731 commit 528cd09

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

easybuild/tools/github.py

+18-7
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
'archived': 'uses an archived toolchain',
108108
'inactive': 'no activity for > 6 months',
109109
'obsolete': 'obsoleted by more recent PRs',
110+
'retest': 'closing and reopening to trigger tests',
110111
}
111112

112113

@@ -668,7 +669,7 @@ def _easyconfigs_pr_common(paths, ecs, start_branch=None, pr_branch=None, start_
668669
if paths['easyconfigs']:
669670
for path in paths['easyconfigs']:
670671
if not os.path.exists(path):
671-
non_existing_paths.append(path)
672+
non_existing_paths.append(path)
672673
else:
673674
ec_paths.append(path)
674675

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

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

1113+
reopen = motivation_msg == VALID_CLOSE_PR_REASONS['retest']
1114+
11121115
if not motivation_msg:
11131116
print_msg("No reason or message specified, looking for possible reasons\n")
11141117
possible_reasons = reasons_for_closing(pr_data)
@@ -1120,15 +1123,18 @@ def close_pr(pr, motivation_msg=None):
11201123
motivation_msg = ", ".join([VALID_CLOSE_PR_REASONS[reason] for reason in possible_reasons])
11211124
print_msg("\nNo reason specified but found possible reasons: %s.\n" % motivation_msg, prefix=False)
11221125

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

11301134
if dry_run:
1131-
print_msg("[DRY RUN] Closed %s/%s pull request #%s" % (pr_target_account, pr_target_repo, pr), prefix=False)
1135+
print_msg("[DRY RUN] Closed %s/%s PR #%s" % (pr_target_account, pr_target_repo, pr), prefix=False)
1136+
if reopen:
1137+
print_msg("[DRY RUN] Reopened %s/%s PR #%s" % (pr_target_account, pr_target_repo, pr), prefix=False)
11321138
else:
11331139
github_token = fetch_github_token(github_user)
11341140
if github_token is None:
@@ -1139,6 +1145,11 @@ def close_pr(pr, motivation_msg=None):
11391145
status, data = pull_url.post(body=body)
11401146
if not status == HTTP_STATUS_OK:
11411147
raise EasyBuildError("Failed to close PR #%s; status %s, data: %s", pr, status, data)
1148+
if reopen:
1149+
body = {'state': 'open'}
1150+
status, data = pull_url.post(body=body)
1151+
if not status == HTTP_STATUS_OK:
1152+
raise EasyBuildError("Failed to reopen PR #%s; status %s, data: %s", pr, status, data)
11421153

11431154

11441155
def list_prs(params, per_page=GITHUB_MAX_PER_PAGE, github_user=None):

test/framework/github.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from easybuild.tools.config import module_classes
4242
from easybuild.tools.configobj import ConfigObj
4343
from easybuild.tools.filetools import read_file, write_file
44+
from easybuild.tools.github import VALID_CLOSE_PR_REASONS
4445
from easybuild.tools.py2vs3 import HTTPError, URLError, ascii_letters
4546
import easybuild.tools.github as gh
4647

@@ -222,7 +223,24 @@ def test_close_pr(self):
222223
"hpcugent/testrepository PR #2 was submitted by migueldiascosta",
223224
"[DRY RUN] Adding comment to testrepository issue #2: '" +
224225
"@migueldiascosta, this PR is being closed for the following reason(s): just a test",
225-
"[DRY RUN] Closed hpcugent/testrepository pull request #2",
226+
"[DRY RUN] Closed hpcugent/testrepository PR #2",
227+
]
228+
for pattern in patterns:
229+
self.assertTrue(pattern in stdout, "Pattern '%s' found in: %s" % (pattern, stdout))
230+
231+
retest_msg = VALID_CLOSE_PR_REASONS['retest']
232+
233+
self.mock_stdout(True)
234+
gh.close_pr(2, motivation_msg=retest_msg)
235+
stdout = self.get_stdout()
236+
self.mock_stdout(False)
237+
238+
patterns = [
239+
"hpcugent/testrepository PR #2 was submitted by migueldiascosta",
240+
"[DRY RUN] Adding comment to testrepository issue #2: '" +
241+
"@migueldiascosta, this PR is being closed for the following reason(s): %s" % retest_msg,
242+
"[DRY RUN] Closed hpcugent/testrepository PR #2",
243+
"[DRY RUN] Reopened hpcugent/testrepository PR #2",
226244
]
227245
for pattern in patterns:
228246
self.assertTrue(pattern in stdout, "Pattern '%s' found in: %s" % (pattern, stdout))

0 commit comments

Comments
 (0)