Skip to content

Commit a7875cc

Browse files
authored
Merge pull request #50 from migueldiascosta/sync_branch_with_develop
add sync_branch_with_develop
2 parents bdb1148 + c28b21c commit a7875cc

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

easybuild/main.py

Lines changed: 5 additions & 2 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_branch, update_pr
62+
from easybuild.tools.github import sync_branch_with_develop, 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
@@ -295,7 +295,8 @@ def main(args=None, logfile=None, do_build=None, testing=False, modtool=None):
295295

296296
# command line options that do not require any easyconfigs to be specified
297297
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
298+
pr_options = pr_options or options.sync_branch_with_develop or options.sync_pr_with_develop
299+
pr_options = pr_options or options.update_branch_github or options.update_pr
299300
no_ec_opts = [options.aggregate_regtest, options.regtest, pr_options, search_query]
300301

301302
# determine paths to easyconfigs
@@ -388,6 +389,8 @@ def main(args=None, logfile=None, do_build=None, testing=False, modtool=None):
388389
new_pr_from_branch(options.new_pr_from_branch)
389390
elif options.preview_pr:
390391
print(review_pr(paths=determined_paths, colored=use_color(options.color)))
392+
elif options.sync_branch_with_develop:
393+
sync_branch_with_develop(options.sync_branch_with_develop)
391394
elif options.sync_pr_with_develop:
392395
sync_pr_with_develop(options.sync_pr_with_develop)
393396
elif options.update_branch_github:

easybuild/tools/github.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,3 +2029,24 @@ def sync_pr_with_develop(pr_id):
20292029

20302030
# push updated branch back to GitHub (unless we're doing a dry run)
20312031
return push_branch_to_github(git_repo, pr_account, target_repo, pr_branch)
2032+
2033+
2034+
def sync_branch_with_develop(branch_name):
2035+
"""Sync branch with specified name with current develop branch."""
2036+
github_user = build_option('github_user')
2037+
if github_user is None:
2038+
raise EasyBuildError("GitHub user must be specified to use --sync-branch-with-develop")
2039+
2040+
target_account = build_option('pr_target_account')
2041+
target_repo = build_option('pr_target_repo')
2042+
2043+
# initialize repository
2044+
git_working_dir = tempfile.mkdtemp(prefix='git-working-dir')
2045+
git_repo = init_repo(git_working_dir, target_repo)
2046+
2047+
setup_repo(git_repo, github_user, target_repo, branch_name)
2048+
2049+
sync_with_develop(git_repo, branch_name, target_account, target_repo)
2050+
2051+
# push updated branch back to GitHub (unless we're doing a dry run)
2052+
return push_branch_to_github(git_repo, github_user, target_repo, branch_name)

easybuild/tools/options.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ def github_options(self):
607607
'pr-target-repo': ("Target repository for new/updating PRs", str, 'store', GITHUB_EASYCONFIGS_REPO),
608608
'pr-title': ("Title for new pull request created with --new-pr", str, 'store', None),
609609
'preview-pr': ("Preview a new pull request", None, 'store_true', False),
610+
'sync-branch-with-develop': ("Sync branch with current 'develop' branch", str, 'store', None),
610611
'sync-pr-with-develop': ("Sync pull request with current 'develop' branch",
611612
int, 'store', None, {'metavar': 'PR#'}),
612613
'review-pr': ("Review specified pull request", int, 'store', None, {'metavar': 'PR#'}),

test/framework/options.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3153,6 +3153,34 @@ def test_sync_pr_with_develop(self):
31533153
regex = re.compile(pattern)
31543154
self.assertTrue(regex.match(txt), "Pattern '%s' doesn't match: %s" % (regex.pattern, txt))
31553155

3156+
def test_sync_branch_with_develop(self):
3157+
"""Test use of --sync-branch-with-develop (dry run only)."""
3158+
if self.github_token is None:
3159+
print("Skipping test_sync_pr_with_develop, no GitHub token available?")
3160+
return
3161+
3162+
# see https://github.com/boegel/easybuild-easyconfigs/tree/test_new_pr_from_branch_DO_NOT_REMOVE
3163+
test_branch = 'test_new_pr_from_branch_DO_NOT_REMOVE'
3164+
3165+
args = [
3166+
'--github-user=%s' % GITHUB_TEST_ACCOUNT,
3167+
'--github-org=boegel', # used to determine account to grab branch from
3168+
'--sync-branch-with-develop=%s' % test_branch,
3169+
'--dry-run',
3170+
]
3171+
txt, _ = self._run_mock_eb(args, do_build=True, raise_error=True, testing=False)
3172+
3173+
github_path = r"boegel/easybuild-easyconfigs\.git"
3174+
pattern = '\n'.join([
3175+
r"== temporary log file in case of crash .*",
3176+
r"== fetching branch '%s' from https://github\.com/%s\.\.\." % (test_branch, github_path),
3177+
r"== pulling latest version of 'develop' branch from easybuilders/easybuild-easyconfigs\.\.\.",
3178+
r"== merging 'develop' branch into PR branch 'develop'\.\.\.",
3179+
r"== pushing branch 'develop' to remote '.*' \(git@github\.com:%s\) \[DRY RUN\]" % github_path,
3180+
])
3181+
regex = re.compile(pattern)
3182+
self.assertTrue(regex.match(txt), "Pattern '%s' doesn't match: %s" % (regex.pattern, txt))
3183+
31563184
def test_new_pr_python(self):
31573185
"""Check generated PR title for --new-pr on easyconfig that includes Python dependency."""
31583186
if self.github_token is None:

0 commit comments

Comments
 (0)