Repository: easybuilders/easybuild-framework

Issue:
`--new-pr` does not check for valid GitHub user name
I was just opening an easyconfig PR and noticed that `--new-pr` doesn't seem to check that there is a valid GitHub user name set (any more?..EB v4.3.4) and tries to use `None`

```
alanc@~$ eb --new-pr line-prof.eb
== Temporary log file in case of crash /tmp/eb-za20dzv9/easybuild-vg4d9x65.log
== fetching branch 'develop' from https://github.com/easybuilders/easybuild-easyconfigs.git...
== copying files to /tmp/eb-za20dzv9/git-working-dirdxszylm8/easybuild-easyconfigs...
== pushing branch '20210409123147_new_pr_line_profiler310' to remote 'github_None_VeRJa' (git@github.com:None/easybuild-easyconfigs.git)
ERROR: Failed to push branch '20210409123147_new_pr_line_profiler310' to GitHub (git@github.com:None/easybuild-easyconfigs.git): Cmd('git') failed due to: exit code(128)
  cmdline: git push --porcelain github_None_VeRJa 20210409123147_new_pr_line_profiler310
  stderr: 'fatal: Could not read from remote repository.
```


Discussion:
Also true for `--check-github`, it tries to do GitHub operations with no valid user name
I think we can probably add a check in https://github.com/easybuilders/easybuild-framework/blob/develop/easybuild/tools/github.py#L953 that the `target_account` is not None, and don't attempt the push in this case (and say why).
Similar for gists in https://github.com/easybuilders/easybuild-framework/blob/develop/easybuild/tools/github.py#L559?
Hmm, can you check if this a regression we introduced at some point?

We can definitely do better, but there are some caveats too: if `--new-pr --dry-run` is used, we should still do all the local stuff, and in that case we don't actually need a GitHub token (or a GitHub user name). I guess in that case we can/should still try to produce a warning.

I'm a bit surprised by this though: when `--new-pr` is run, EB will try and grab the GitHub token, and it needs the GitHub username for that...
So I use `AddKeysToAgent Confirm` in my ssh config and I can see that when using `--check-github`, there are 2 usages of the key for push access and one usage for gists when a github user is given. With no user given, it still tries to use the key once when checking for push access so there is something not quite right there. This behaviour is there back to `4.0.x`.

Resolving patch:
diff --git a/easybuild/tools/github.py b/easybuild/tools/github.py
--- 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))
 
@@ -688,10 +691,12 @@ 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()
     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)
@@ -807,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:
@@ -959,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)


Test patch: