Skip to content

Commit

Permalink
Merge pull request #46 from boegel/github_user
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ocaisa authored Apr 10, 2021
2 parents 54fb85f + 5dd1890 commit aa73371
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions easybuild/tools/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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):
Expand Down

0 comments on commit aa73371

Please sign in to comment.