Skip to content

Commit 6f88b5e

Browse files
committed
flesh out det_pr_account_branch from update_pr
1 parent 314cf7c commit 6f88b5e

File tree

2 files changed

+54
-13
lines changed

2 files changed

+54
-13
lines changed

easybuild/tools/github.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,41 +1359,55 @@ def new_pr(paths, ecs, title=None, descr=None, commit_msg=None):
13591359
_log.info("Failed to add labels to PR# %s: %s." % (pr, err))
13601360

13611361

1362+
def det_account_branch_for_pr(pr_id, github_user=None):
1363+
"""Determine account & branch corresponding to pull request with specified id."""
1364+
1365+
if github_user is None:
1366+
github_user = build_option('github_user')
1367+
1368+
if github_user is None:
1369+
raise EasyBuildError("GitHub username (--github-user) must be specified!")
1370+
1371+
pr_target_account = build_option('pr_target_account')
1372+
pr_target_repo = build_option('pr_target_repo')
1373+
1374+
pr_data, _ = fetch_pr_data(pr_id, pr_target_account, pr_target_repo, github_user)
1375+
1376+
# branch that corresponds with PR is supplied in form <account>:<branch_label>
1377+
account = pr_data['head']['label'].split(':')[0]
1378+
branch = ':'.join(pr_data['head']['label'].split(':')[1:])
1379+
github_target = '%s/%s' % (pr_target_account, pr_target_repo)
1380+
print_msg("Determined branch name corresponding to %s PR #%s: %s" % (github_target, pr_id, branch), log=_log)
1381+
1382+
return account, branch
1383+
1384+
13621385
@only_if_module_is_available('git', pkgname='GitPython')
1363-
def update_pr(pr, paths, ecs, commit_msg=None):
1386+
def update_pr(pr_id, paths, ecs, commit_msg=None):
13641387
"""
13651388
Update specified pull request using specified files
13661389
1367-
:param pr: ID of pull request to update
1390+
:param pr_id: ID of pull request to update
13681391
:param paths: paths to categorized lists of files (easyconfigs, files to delete, patches)
13691392
:param ecs: list of parsed easyconfigs, incl. for dependencies (if robot is enabled)
13701393
:param commit_msg: commit message to use
13711394
"""
1372-
github_user = build_option('github_user')
1373-
if github_user is None:
1374-
raise EasyBuildError("GitHub user must be specified to use --update-pr")
13751395

13761396
if commit_msg is None:
13771397
raise EasyBuildError("A meaningful commit message must be specified via --pr-commit-msg when using --update-pr")
13781398

13791399
pr_target_account = build_option('pr_target_account')
13801400
pr_target_repo = build_option('pr_target_repo')
13811401

1382-
pr_data, _ = fetch_pr_data(pr, pr_target_account, pr_target_repo, github_user)
1383-
1384-
# branch that corresponds with PR is supplied in form <account>:<branch_label>
1385-
account = pr_data['head']['label'].split(':')[0]
1386-
branch = ':'.join(pr_data['head']['label'].split(':')[1:])
1387-
github_target = '%s/%s' % (pr_target_account, pr_target_repo)
1388-
print_msg("Determined branch name corresponding to %s PR #%s: %s" % (github_target, pr, branch), log=_log)
1402+
account, branch = det_account_branch_for_pr(pr_id)
13891403

13901404
_, _, _, _, diff_stat = _easyconfigs_pr_common(paths, ecs, start_branch=branch, pr_branch=branch,
13911405
start_account=account, commit_msg=commit_msg)
13921406

13931407
print_msg("Overview of changes:\n%s\n" % diff_stat, log=_log, prefix=False)
13941408

13951409
full_repo = '%s/%s' % (pr_target_account, pr_target_repo)
1396-
msg = "Updated %s PR #%s by pushing to branch %s/%s" % (full_repo, pr, account, branch)
1410+
msg = "Updated %s PR #%s by pushing to branch %s/%s" % (full_repo, pr_id, account, branch)
13971411
if build_option('dry_run') or build_option('extended_dry_run'):
13981412
msg += " [DRY RUN]"
13991413
print_msg(msg, log=_log, prefix=False)

test/framework/github.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,33 @@ def test_create_delete_gist(self):
636636
gist_id = gist_url.split('/')[-1]
637637
gh.delete_gist(gist_id, github_user=GITHUB_TEST_ACCOUNT, github_token=self.github_token)
638638

639+
def test_det_account_branch_for_pr(self):
640+
"""Test det_account_branch_for_pr."""
641+
642+
init_config(build_options={
643+
'pr_target_account': 'easybuilders',
644+
'pr_target_repo': 'easybuild-easyconfigs',
645+
})
646+
647+
# see https://github.com/easybuilders/easybuild-easyconfigs/pull/9149
648+
self.mock_stdout(True)
649+
account, branch = gh.det_account_branch_for_pr(9149, github_user=GITHUB_TEST_ACCOUNT)
650+
self.mock_stdout(False)
651+
self.assertEqual(account, 'boegel')
652+
self.assertEqual(branch, '20191017070734_new_pr_EasyBuild401')
653+
654+
init_config(build_options={
655+
'pr_target_account': 'easybuilders',
656+
'pr_target_repo': 'easybuild-framework',
657+
})
658+
659+
# see https://github.com/easybuilders/easybuild-framework/pull/3069
660+
self.mock_stdout(True)
661+
account, branch = gh.det_account_branch_for_pr(3069, github_user=GITHUB_TEST_ACCOUNT)
662+
self.mock_stdout(False)
663+
self.assertEqual(account, 'migueldiascosta')
664+
self.assertEqual(branch, 'fix_inject_checksums')
665+
639666

640667
def suite():
641668
""" returns all the testcases in this module """

0 commit comments

Comments
 (0)