Skip to content

Commit 4e28b43

Browse files
committed
add support for --update-branch-github
1 parent 6d91a5e commit 4e28b43

File tree

5 files changed

+82
-23
lines changed

5 files changed

+82
-23
lines changed

easybuild/main.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
from easybuild.tools.filetools import adjust_permissions, cleanup, write_file
6060
from easybuild.tools.github import check_github, close_pr, new_branch_github, find_easybuild_easyconfig
6161
from easybuild.tools.github import install_github_token, list_prs, new_pr, new_pr_from_branch, merge_pr
62-
from easybuild.tools.github import sync_pr_with_develop, update_pr
62+
from easybuild.tools.github import sync_pr_with_develop, update_branch, update_pr
6363
from easybuild.tools.hooks import START, END, load_hooks, run_hook
6464
from easybuild.tools.modules import modules_tool
6565
from easybuild.tools.options import set_up_configuration, use_color
@@ -294,8 +294,8 @@ def main(args=None, logfile=None, do_build=None, testing=False, modtool=None):
294294
categorized_paths = categorize_files_by_type(orig_paths)
295295

296296
# command line options that do not require any easyconfigs to be specified
297-
pr_options = options.new_branch_github or options.new_pr or options.new_pr_from_branch
298-
pr_options = pr_options or options.preview_pr or options.sync_pr_with_develop or options.update_pr
297+
pr_options = options.new_branch_github or options.new_pr or options.new_pr_from_branch or options.preview_pr
298+
pr_options = pr_options or options.sync_pr_with_develop or options.update_branch_github or options.update_pr
299299
no_ec_opts = [options.aggregate_regtest, options.regtest, pr_options, search_query]
300300

301301
# determine paths to easyconfigs
@@ -390,8 +390,10 @@ def main(args=None, logfile=None, do_build=None, testing=False, modtool=None):
390390
print(review_pr(paths=determined_paths, colored=use_color(options.color)))
391391
elif options.sync_pr_with_develop:
392392
sync_pr_with_develop(options.sync_pr_with_develop)
393+
elif options.update_branch_github:
394+
update_branch(options.update_branch_github, categorized_paths, ordered_ecs)
393395
elif options.update_pr:
394-
update_pr(options.update_pr, categorized_paths, ordered_ecs, commit_msg=options.pr_commit_msg)
396+
update_pr(options.update_pr, categorized_paths, ordered_ecs)
395397
else:
396398
raise EasyBuildError("Unknown PR option!")
397399

easybuild/tools/config.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,11 @@ def init_build_options(build_options=None, cmdline_options=None):
442442
cmdline_options.force = True
443443
retain_all_deps = True
444444

445-
if cmdline_options.new_branch_github or cmdline_options.new_pr or cmdline_options.update_pr:
446-
_log.info("Retaining all dependencies of specified easyconfigs to create/update pull request")
445+
new_update_opt = cmdline_options.new_branch_github or cmdline_options.new_pr
446+
new_update_opt = new_update_opt or cmdline_options.update_branch_github or cmdline_options.update_pr
447+
448+
if new_update_opt:
449+
_log.info("Retaining all dependencies of specified easyconfigs to create/update branch or pull request")
447450
retain_all_deps = True
448451

449452
auto_ignore_osdeps_options = [cmdline_options.check_conflicts, cmdline_options.check_contrib,
@@ -453,7 +456,7 @@ def init_build_options(build_options=None, cmdline_options=None):
453456
cmdline_options.extended_dry_run, cmdline_options.fix_deprecated_easyconfigs,
454457
cmdline_options.missing_modules, cmdline_options.new_branch_github,
455458
cmdline_options.new_pr, cmdline_options.preview_pr,
456-
cmdline_options.update_pr]
459+
cmdline_options.update_branch_github, cmdline_options.update_pr]
457460
if any(auto_ignore_osdeps_options):
458461
_log.info("Auto-enabling ignoring of OS dependencies")
459462
cmdline_options.ignore_osdeps = True

easybuild/tools/github.py

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,34 +1537,56 @@ def det_account_branch_for_pr(pr_id, github_user=None):
15371537

15381538

15391539
@only_if_module_is_available('git', pkgname='GitPython')
1540-
def update_pr(pr_id, paths, ecs, commit_msg=None):
1540+
def update_branch(branch_name, paths, ecs, github_account=None, commit_msg=None):
15411541
"""
1542-
Update specified pull request using specified files
1542+
Update specified branch in GitHub using specified files
15431543
1544-
:param pr_id: ID of pull request to update
15451544
:param paths: paths to categorized lists of files (easyconfigs, files to delete, patches)
1545+
:param github_account: GitHub account where branch is located
15461546
:param ecs: list of parsed easyconfigs, incl. for dependencies (if robot is enabled)
15471547
:param commit_msg: commit message to use
15481548
"""
1549+
if commit_msg is None:
1550+
commit_msg = build_option('pr_commit_msg')
15491551

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

1553-
pr_target_account = build_option('pr_target_account')
1554-
pr_target_repo = build_option('pr_target_repo')
1555-
1556-
account, branch = det_account_branch_for_pr(pr_id)
1555+
if github_account is None:
1556+
github_account = build_option('github_user') or build_option('github_org')
15571557

1558-
_, _, _, _, diff_stat = _easyconfigs_pr_common(paths, ecs, start_branch=branch, pr_branch=branch,
1559-
start_account=account, commit_msg=commit_msg)
1558+
_, _, _, _, diff_stat = _easyconfigs_pr_common(paths, ecs, start_branch=branch_name, pr_branch=branch_name,
1559+
start_account=github_account, commit_msg=commit_msg)
15601560

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

1563-
full_repo = '%s/%s' % (pr_target_account, pr_target_repo)
1564-
msg = "Updated %s PR #%s by pushing to branch %s/%s" % (full_repo, pr_id, account, branch)
1563+
full_repo = '%s/%s' % (github_account, build_option('pr_target_repo'))
1564+
msg = "pushed updated branch '%s' to %s" % (branch_name, full_repo)
15651565
if build_option('dry_run') or build_option('extended_dry_run'):
15661566
msg += " [DRY RUN]"
1567-
print_msg(msg, log=_log, prefix=False)
1567+
print_msg(msg, log=_log)
1568+
1569+
1570+
@only_if_module_is_available('git', pkgname='GitPython')
1571+
def update_pr(pr_id, paths, ecs, commit_msg=None):
1572+
"""
1573+
Update specified pull request using specified files
1574+
1575+
:param pr_id: ID of pull request to update
1576+
:param paths: paths to categorized lists of files (easyconfigs, files to delete, patches)
1577+
:param ecs: list of parsed easyconfigs, incl. for dependencies (if robot is enabled)
1578+
:param commit_msg: commit message to use
1579+
"""
1580+
1581+
github_account, branch_name = det_account_branch_for_pr(pr_id)
1582+
1583+
update_branch(branch_name, paths, ecs, github_account=github_account, commit_msg=commit_msg)
1584+
1585+
full_repo = '%s/%s' % (build_option('pr_target_account'), build_option('pr_target_repo'))
1586+
msg = "updated https://github.com/%s/pull/%s" % (full_repo, pr_id)
1587+
if build_option('dry_run') or build_option('extended_dry_run'):
1588+
msg += " [DRY RUN]"
1589+
print_msg(msg, log=_log)
15681590

15691591

15701592
def check_github():

easybuild/tools/options.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,7 @@ def github_options(self):
612612
'review-pr': ("Review specified pull request", int, 'store', None, {'metavar': 'PR#'}),
613613
'test-report-env-filter': ("Regex used to filter out variables in environment dump of test report",
614614
None, 'regex', None),
615+
'update-branch-github': ("Update specified branch in GitHub", str, 'store', None),
615616
'update-pr': ("Update an existing pull request", int, 'store', None, {'metavar': 'PR#'}),
616617
'upload-test-report': ("Upload full test report as a gist on GitHub", None, 'store_true', False, 'u'),
617618
})
@@ -1358,6 +1359,8 @@ def set_up_configuration(args=None, logfile=None, testing=False, silent=False):
13581359
if not robot_path:
13591360
print_warning("Robot search path is empty!")
13601361

1362+
new_update_opt = options.new_pr or options.new_pr_from_branch or options.update_branch_github or options.update_pr
1363+
13611364
# configure & initialize build options
13621365
config_options_dict = eb_go.get_options_by_section('config')
13631366
build_options = {
@@ -1366,7 +1369,7 @@ def set_up_configuration(args=None, logfile=None, testing=False, silent=False):
13661369
'external_modules_metadata': parse_external_modules_metadata(options.external_modules_metadata),
13671370
'pr_path': pr_path,
13681371
'robot_path': robot_path,
1369-
'silent': testing or options.new_pr or options.update_pr,
1372+
'silent': testing or new_update_opt,
13701373
'try_to_generate': try_to_generate,
13711374
'valid_stops': [x[0] for x in EasyBlock.get_steps()],
13721375
}

test/framework/options.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2884,6 +2884,35 @@ def test_new_pr_from_branch(self):
28842884
]
28852885
self._assert_regexs(regexs, txt)
28862886

2887+
def test_update_branch_github(self):
2888+
"""Test --update-branch-github."""
2889+
if self.github_token is None:
2890+
print("Skipping test_update_branch_github, no GitHub token available?")
2891+
return
2892+
2893+
topdir = os.path.dirname(os.path.abspath(__file__))
2894+
test_ecs = os.path.join(topdir, 'easyconfigs', 'test_ecs')
2895+
toy_ec = os.path.join(test_ecs, 't', 'toy', 'toy-0.0.eb')
2896+
2897+
args = [
2898+
'--update-branch-github=develop',
2899+
'--github-user=boegel', # used to determine account to grab branch from (no GitHub token needed)
2900+
toy_ec,
2901+
'--pr-commit-msg="this is just a test"',
2902+
'-D',
2903+
]
2904+
txt, _ = self._run_mock_eb(args, do_build=True, raise_error=True, testing=False)
2905+
2906+
full_repo = 'boegel/easybuild-easyconfigs'
2907+
regexs = [
2908+
r"^== fetching branch 'develop' from https://github.com/%s.git\.\.\." % full_repo,
2909+
r"^== copying easyconfigs to .*/git-working-dir.*/easybuild-easyconfigs...",
2910+
r"^== pushing branch 'develop' to remote '.*' \([email protected]:%s.git\) \[DRY RUN\]" % full_repo,
2911+
r"^Overview of changes:\n.*/easyconfigs/t/toy/toy-0.0.eb \| 32",
2912+
r"== pushed updated branch 'develop' to boegel/easybuild-easyconfigs \[DRY RUN\]",
2913+
]
2914+
self._assert_regexs(regexs, txt)
2915+
28872916
def test_new_update_pr(self):
28882917
"""Test use of --new-pr (dry run only)."""
28892918
if self.github_token is None:
@@ -3067,9 +3096,9 @@ def test_new_update_pr(self):
30673096
r"^== fetching branch 'develop' from https://github.com/easybuilders/easybuild-easyconfigs.git...",
30683097
r".*/toy-0.0-gompi-2018a-test.eb\s*\|",
30693098
r"^\s*1 file(s?) changed",
3070-
"^== pushing branch 'develop' to remote '.*' \([email protected]:easybuilders/easybuild-easyconfigs.git\)",
3071-
r"^Updated easybuilders/easybuild-easyconfigs PR #2237 "
3072-
"by pushing to branch easybuilders/develop \[DRY RUN\]",
3099+
r"^== pushing branch 'develop' to remote '.*' \([email protected]:easybuilders/easybuild-easyconfigs.git\)",
3100+
r"^== pushed updated branch 'develop' to easybuilders/easybuild-easyconfigs \[DRY RUN\]",
3101+
r"^== updated https://github.com/easybuilders/easybuild-easyconfigs/pull/2237 \[DRY RUN\]",
30733102
]
30743103
self._assert_regexs(regexs, txt)
30753104

0 commit comments

Comments
 (0)