Skip to content

Commit 94e4a1c

Browse files
authored
Merge pull request #4947 from Crivella/fix-sync_pr_repo
Fix logic for `pr_repo` used in `--sync-pr-with-develop`
2 parents 87eabdd + 0b9092a commit 94e4a1c

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

easybuild/tools/github.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2173,7 +2173,7 @@ def new_pr(paths, ecs, title=None, descr=None, commit_msg=None):
21732173
pr_metadata=(file_info, deleted_paths, diff_stat), commit_msg=commit_msg)
21742174

21752175

2176-
def det_account_branch_for_pr(pr_id, github_user=None, pr_target_repo=None):
2176+
def det_account_repo_branch_for_pr(pr_id, github_user=None, pr_target_repo=None):
21772177
"""Determine account & branch corresponding to pull request with specified id."""
21782178

21792179
if github_user is None:
@@ -2190,10 +2190,19 @@ def det_account_branch_for_pr(pr_id, github_user=None, pr_target_repo=None):
21902190

21912191
# branch that corresponds with PR is supplied in form <account>:<branch_label>
21922192
account = pr_data['head']['label'].split(':')[0]
2193+
repo = pr_data['head']['repo']['name']
21932194
branch = ':'.join(pr_data['head']['label'].split(':')[1:])
21942195
github_target = '%s/%s' % (pr_target_account, pr_target_repo)
21952196
print_msg("Determined branch name corresponding to %s PR #%s: %s" % (github_target, pr_id, branch), log=_log)
21962197

2198+
return account, repo, branch
2199+
2200+
2201+
def det_account_branch_for_pr(pr_id, github_user=None, pr_target_repo=None):
2202+
"""Deprecated version of `det_account_repo_branch_for_pr`"""
2203+
_log.deprecated("`det_account_branch_for_pr` is deprecated, use `det_account_repo_branch_for_pr` instead", "6.0")
2204+
account, _, branch = det_account_repo_branch_for_pr(pr_id, github_user=github_user, pr_target_repo=pr_target_repo)
2205+
21972206
return account, branch
21982207

21992208

@@ -2291,7 +2300,7 @@ def update_pr(pr_id, paths, ecs, commit_msg=None):
22912300
exit_code=EasyBuildExit.OPTION_ERROR
22922301
)
22932302

2294-
github_account, branch_name = det_account_branch_for_pr(pr_id, pr_target_repo=pr_target_repo)
2303+
github_account, _, branch_name = det_account_repo_branch_for_pr(pr_id, pr_target_repo=pr_target_repo)
22952304

22962305
update_branch(branch_name, paths, ecs, github_account=github_account, commit_msg=commit_msg)
22972306

@@ -2883,18 +2892,18 @@ def sync_pr_with_develop(pr_id):
28832892
target_account = build_option('pr_target_account')
28842893
target_repo = build_option('pr_target_repo') or GITHUB_EASYCONFIGS_REPO
28852894

2886-
pr_account, pr_branch = det_account_branch_for_pr(pr_id)
2895+
pr_account, pr_repo, pr_branch = det_account_repo_branch_for_pr(pr_id)
28872896

28882897
# initialize repository
28892898
git_working_dir = tempfile.mkdtemp(prefix='git-working-dir')
28902899
git_repo = init_repo(git_working_dir, target_repo)
28912900

2892-
setup_repo(git_repo, pr_account, target_repo, pr_branch)
2901+
setup_repo(git_repo, pr_account, pr_repo, pr_branch)
28932902

28942903
sync_with_develop(git_repo, pr_branch, target_account, target_repo)
28952904

28962905
# push updated branch back to GitHub (unless we're doing a dry run)
2897-
return push_branch_to_github(git_repo, pr_account, target_repo, pr_branch)
2906+
return push_branch_to_github(git_repo, pr_account, pr_repo, pr_branch)
28982907

28992908

29002909
def sync_branch_with_develop(branch_name):

test/framework/github.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ def test_github_create_delete_gist(self):
11161116
gist_id = gist_url.split('/')[-1]
11171117
gh.delete_gist(gist_id, github_user=GITHUB_TEST_ACCOUNT, github_token=self.github_token)
11181118

1119-
def test_github_det_account_branch_for_pr(self):
1119+
def test_github_det_account_repo_branch_for_pr(self):
11201120
"""Test det_account_branch_for_pr."""
11211121
if self.skip_github_tests:
11221122
print("Skipping test_det_account_branch_for_pr, no GitHub token available?")
@@ -1129,9 +1129,10 @@ def test_github_det_account_branch_for_pr(self):
11291129

11301130
# see https://github.com/easybuilders/easybuild-easyconfigs/pull/9149
11311131
self.mock_stdout(True)
1132-
account, branch = gh.det_account_branch_for_pr(9149, github_user=GITHUB_TEST_ACCOUNT)
1132+
account, repo, branch = gh.det_account_repo_branch_for_pr(9149, github_user=GITHUB_TEST_ACCOUNT)
11331133
self.mock_stdout(False)
11341134
self.assertEqual(account, 'boegel')
1135+
self.assertEqual(repo, 'easybuild-easyconfigs')
11351136
self.assertEqual(branch, '20191017070734_new_pr_EasyBuild401')
11361137

11371138
init_config(build_options={
@@ -1141,9 +1142,10 @@ def test_github_det_account_branch_for_pr(self):
11411142

11421143
# see https://github.com/easybuilders/easybuild-framework/pull/3069
11431144
self.mock_stdout(True)
1144-
account, branch = gh.det_account_branch_for_pr(3069, github_user=GITHUB_TEST_ACCOUNT)
1145+
account, repo, branch = gh.det_account_repo_branch_for_pr(3069, github_user=GITHUB_TEST_ACCOUNT)
11451146
self.mock_stdout(False)
11461147
self.assertEqual(account, 'migueldiascosta')
1148+
self.assertEqual(repo, 'easybuild-framework')
11471149
self.assertEqual(branch, 'fix_inject_checksums')
11481150

11491151
def test_github_det_pr_target_repo(self):

0 commit comments

Comments
 (0)