Repository: easybuilders/easybuild-framework

Issue:
--from-pr & co should not pass GitHub login ID when no token is available
If `--github-user` is set but no GitHub token is available, this happens when using `--from-pr` or `--install-latest-eb-release`:

```
== temporary log file in case of crash /Users/kehoste/work/TMP/eb-qGSK8p/easybuild-iAnkL8.log
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/private/tmp/eb392/software/EasyBuild/3.9.2/lib/python2.7/site-packages/easybuild_framework-3.9.2-py2.7.egg/easybuild/main.py", line 457, in <module>
    main()
  File "/private/tmp/eb392/software/EasyBuild/3.9.2/lib/python2.7/site-packages/easybuild_framework-3.9.2-py2.7.egg/easybuild/main.py", line 295, in main
    determined_paths = det_easyconfig_paths(categorized_paths['easyconfigs'])
  File "/private/tmp/eb392/software/EasyBuild/3.9.2/lib/python2.7/site-packages/easybuild_framework-3.9.2-py2.7.egg/easybuild/framework/easyconfig/tools.py", line 313, in det_easyconfig_paths
    pr_files = fetch_easyconfigs_from_pr(from_pr)
  File "/private/tmp/eb392/software/EasyBuild/3.9.2/lib/python2.7/site-packages/easybuild_framework-3.9.2-py2.7.egg/easybuild/tools/github.py", line 387, in fetch_easyconfigs_from_pr
    pr_data, _ = fetch_pr_data(pr, github_account, github_repo, github_user)
  File "/private/tmp/eb392/software/EasyBuild/3.9.2/lib/python2.7/site-packages/easybuild_framework-3.9.2-py2.7.egg/easybuild/tools/github.py", line 1694, in fetch_pr_data
    status, pr_data = github_api_get_request(pr_url, github_user, **parameters)
  File "/private/tmp/eb392/software/EasyBuild/3.9.2/lib/python2.7/site-packages/easybuild_framework-3.9.2-py2.7.egg/easybuild/tools/github.py", line 243, in github_api_get_request
    url = request_f(RestClient(GITHUB_API_URL, username=github_user, token=token))
  File "/private/tmp/eb392/software/EasyBuild/3.9.2/lib/python2.7/site-packages/vsc_base-2.8.4-py2.7.egg/vsc/utils/rest.py", line 287, in __init__
    self.client = Client(*args, **kwargs)
  File "/private/tmp/eb392/software/EasyBuild/3.9.2/lib/python2.7/site-packages/vsc_base-2.8.4-py2.7.egg/vsc/utils/rest.py", line 99, in __init__
    raise TypeError("You need a password or an OAuth token to authenticate as " + username)
TypeError: You need a password or an OAuth token to authenticate as boegel
```

This can be avoided by not passing the GitHub login ID in `github_api_get_request`  when no token is available...


Discussion:

Resolving patch:
diff --git a/easybuild/tools/github.py b/easybuild/tools/github.py
--- a/easybuild/tools/github.py
+++ b/easybuild/tools/github.py
@@ -249,6 +249,12 @@ def github_api_get_request(request_f, github_user=None, token=None, **kwargs):
     if token is None:
         token = fetch_github_token(github_user)
 
+    # if we don't have a GitHub token, don't pass username either;
+    # this makes sense for read-only actions like fetching files from PRs
+    if token is None:
+        _log.info("Not specifying username since no GitHub token is available for %s", github_user)
+        github_user = None
+
     url = request_f(RestClient(GITHUB_API_URL, username=github_user, token=token))
 
     try:


Test patch: