From b8fa9b14e35d6ae073beb7c6ab41f8d72ba5e5ad Mon Sep 17 00:00:00 2001 From: Alan O'Cais Date: Fri, 9 Apr 2021 15:36:19 +0200 Subject: [PATCH 1/3] Catch problems if no github user specified --- easybuild/tools/github.py | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/easybuild/tools/github.py b/easybuild/tools/github.py index 9c7d04d31c..34b08cf8be 100644 --- a/easybuild/tools/github.py +++ b/easybuild/tools/github.py @@ -688,8 +688,10 @@ def setup_repo_from(git_repo, github_url, target_account, branch_name, silent=Fa # git fetch # can't use --depth to only fetch a shallow copy, since pushing to another repo from a shallow copy doesn't work print_msg("fetching branch '%s' from %s..." % (branch_name, github_url), silent=silent) + res = None try: - res = origin.fetch() + if target_account != None: + res = origin.fetch() except GitCommandError as err: raise EasyBuildError("Failed to fetch branch '%s' from %s: %s", branch_name, github_url, err) if res: @@ -971,21 +973,24 @@ def push_branch_to_github(git_repo, target_account, target_repo, branch): if dry_run: print_msg(push_branch_msg + ' [DRY RUN]', log=_log) else: - print_msg(push_branch_msg, log=_log) - try: - res = remote.push(branch) - except GitCommandError as err: - raise EasyBuildError("Failed to push branch '%s' to GitHub (%s): %s", branch, github_url, err) + if target_account == None: + raise EasyBuildError("No valid GitHub username (--github-user) given, pushing branch will fail!") + else: + print_msg(push_branch_msg, log=_log) + try: + res = remote.push(branch) + except GitCommandError as err: + raise EasyBuildError("Failed to push branch '%s' to GitHub (%s): %s", branch, github_url, err) - if res: - if res[0].ERROR & res[0].flags: - raise EasyBuildError("Pushing branch '%s' to remote %s (%s) failed: %s", - branch, remote, github_url, res[0].summary) + if res: + if res[0].ERROR & res[0].flags: + raise EasyBuildError("Pushing branch '%s' to remote %s (%s) failed: %s", + branch, remote, github_url, res[0].summary) + else: + _log.debug("Pushed branch %s to remote %s (%s): %s", branch, remote, github_url, res[0].summary) else: - _log.debug("Pushed branch %s to remote %s (%s): %s", branch, remote, github_url, res[0].summary) - else: - raise EasyBuildError("Pushing branch '%s' to remote %s (%s) failed: empty result", - branch, remote, github_url) + raise EasyBuildError("Pushing branch '%s' to remote %s (%s) failed: empty result", + branch, remote, github_url) def is_patch_for(patch_name, ec): From 54fb85f90ee41bcc4ec47ef4b8e95f89631a6461 Mon Sep 17 00:00:00 2001 From: Alan O'Cais Date: Fri, 9 Apr 2021 15:43:57 +0200 Subject: [PATCH 2/3] Fix None comparisons --- easybuild/tools/github.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/easybuild/tools/github.py b/easybuild/tools/github.py index 34b08cf8be..e3d695abc4 100644 --- a/easybuild/tools/github.py +++ b/easybuild/tools/github.py @@ -690,7 +690,7 @@ def setup_repo_from(git_repo, github_url, target_account, branch_name, silent=Fa print_msg("fetching branch '%s' from %s..." % (branch_name, github_url), silent=silent) res = None try: - if target_account != None: + if target_account is not None: res = origin.fetch() except GitCommandError as err: raise EasyBuildError("Failed to fetch branch '%s' from %s: %s", branch_name, github_url, err) @@ -973,7 +973,7 @@ def push_branch_to_github(git_repo, target_account, target_repo, branch): if dry_run: print_msg(push_branch_msg + ' [DRY RUN]', log=_log) else: - if target_account == None: + if target_account is None: raise EasyBuildError("No valid GitHub username (--github-user) given, pushing branch will fail!") else: print_msg(push_branch_msg, log=_log) From 5dd18902164b4feb14661b3e4b02ee2b416cf1fe Mon Sep 17 00:00:00 2001 From: Kenneth Hoste Date: Sat, 10 Apr 2021 11:38:09 +0200 Subject: [PATCH 3/3] make sure that --github-org or --github-user is specified in _easyconfigs_pr_common helper function + require that target_account is not None in setup_repo_from and push_branch_to_github --- easybuild/tools/github.py | 42 ++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/easybuild/tools/github.py b/easybuild/tools/github.py index e3d695abc4..ecdec1a8a5 100644 --- a/easybuild/tools/github.py +++ b/easybuild/tools/github.py @@ -676,6 +676,9 @@ def setup_repo_from(git_repo, github_url, target_account, branch_name, silent=Fa """ _log.debug("Cloning from %s", github_url) + if target_account is None: + raise EasyBuildError("target_account not specified in setup_repo_from!") + # salt to use for names of remotes/branches that are created salt = ''.join(random.choice(ascii_letters) for _ in range(5)) @@ -690,10 +693,10 @@ def setup_repo_from(git_repo, github_url, target_account, branch_name, silent=Fa print_msg("fetching branch '%s' from %s..." % (branch_name, github_url), silent=silent) res = None try: - if target_account is not None: - res = origin.fetch() + res = origin.fetch() except GitCommandError as err: raise EasyBuildError("Failed to fetch branch '%s' from %s: %s", branch_name, github_url, err) + if res: if res[0].flags & res[0].ERROR: raise EasyBuildError("Fetching branch '%s' from remote %s failed: %s", branch_name, origin, res[0].note) @@ -809,6 +812,10 @@ def _easyconfigs_pr_common(paths, ecs, start_branch=None, pr_branch=None, start_ # if start branch is not specified, we're opening a new PR # account to use is determined by active EasyBuild configuration (--github-org or --github-user) target_account = build_option('github_org') or build_option('github_user') + + if target_account is None: + raise EasyBuildError("--github-org or --github-user must be specified!") + # if branch to start from is specified, we're updating an existing PR start_branch = build_option('pr_target_branch') else: @@ -961,6 +968,8 @@ def push_branch_to_github(git_repo, target_account, target_repo, branch): :param target_repo: repository name :param branch: name of branch to push """ + if target_account is None: + raise EasyBuildError("target_account not specified in push_branch_to_github!") # push to GitHub remote = create_remote(git_repo, target_account, target_repo) @@ -973,24 +982,21 @@ def push_branch_to_github(git_repo, target_account, target_repo, branch): if dry_run: print_msg(push_branch_msg + ' [DRY RUN]', log=_log) else: - if target_account is None: - raise EasyBuildError("No valid GitHub username (--github-user) given, pushing branch will fail!") - else: - print_msg(push_branch_msg, log=_log) - try: - res = remote.push(branch) - except GitCommandError as err: - raise EasyBuildError("Failed to push branch '%s' to GitHub (%s): %s", branch, github_url, err) + print_msg(push_branch_msg, log=_log) + try: + res = remote.push(branch) + except GitCommandError as err: + raise EasyBuildError("Failed to push branch '%s' to GitHub (%s): %s", branch, github_url, err) - if res: - if res[0].ERROR & res[0].flags: - raise EasyBuildError("Pushing branch '%s' to remote %s (%s) failed: %s", - branch, remote, github_url, res[0].summary) - else: - _log.debug("Pushed branch %s to remote %s (%s): %s", branch, remote, github_url, res[0].summary) + if res: + if res[0].ERROR & res[0].flags: + raise EasyBuildError("Pushing branch '%s' to remote %s (%s) failed: %s", + branch, remote, github_url, res[0].summary) else: - raise EasyBuildError("Pushing branch '%s' to remote %s (%s) failed: empty result", - branch, remote, github_url) + _log.debug("Pushed branch %s to remote %s (%s): %s", branch, remote, github_url, res[0].summary) + else: + raise EasyBuildError("Pushing branch '%s' to remote %s (%s) failed: empty result", + branch, remote, github_url) def is_patch_for(patch_name, ec):