Skip to content

Commit 5b0d6a3

Browse files
committed
Improve --check-github output
Fix misdetecting an empty username as valid. Show more information on why/what failed, e.g. for creating gists or not/partially populated --git_working_dirs_path
1 parent 415cbcd commit 5b0d6a3

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

easybuild/tools/github.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,17 +2008,18 @@ def check_github():
20082008
github_user = build_option('github_user')
20092009
github_account = build_option('github_org') or build_option('github_user')
20102010

2011-
if github_user is None:
2012-
check_res = "(none available) => FAIL"
2013-
status['--new-pr'] = status['--update-pr'] = status['--upload-test-report'] = False
2014-
else:
2011+
if github_user:
20152012
check_res = "%s => OK" % github_user
2013+
else:
2014+
check_res = "%s => FAIL" % ('(none available)' if github_user is None else '(empty)')
2015+
status['--new-pr'] = status['--update-pr'] = status['--upload-test-report'] = False
20162016

20172017
print_msg(check_res, log=_log, prefix=False)
20182018

20192019
# check GitHub token
20202020
print_msg("* GitHub token...", log=_log, prefix=False, newline=False)
20212021
github_token = fetch_github_token(github_user)
2022+
github_token_valid = False
20222023
if github_token is None:
20232024
check_res = "(no token found) => FAIL"
20242025
else:
@@ -2027,6 +2028,7 @@ def check_github():
20272028
token_descr = partial_token + " (len: %d)" % len(github_token)
20282029
if validate_github_token(github_token, github_user):
20292030
check_res = "%s => OK (validated)" % token_descr
2031+
github_token_valid = True
20302032
else:
20312033
check_res = "%s => FAIL (validation failed)" % token_descr
20322034

@@ -2119,7 +2121,7 @@ def check_github():
21192121
try:
21202122
getattr(git_repo.remotes, remote_name).push(branch_name, delete=True)
21212123
except GitCommandError as err:
2122-
sys.stderr.write("WARNING: failed to delete test branch from GitHub: %s\n" % err)
2124+
print_warning("failed to delete test branch from GitHub: %s" % err, log=_log)
21232125

21242126
# test creating a gist
21252127
print_msg("* creating gists...", log=_log, prefix=False, newline=False)
@@ -2137,17 +2139,33 @@ def check_github():
21372139

21382140
if gist_url and re.match('https://gist.github.com/%s/[0-9a-f]+$' % github_user, gist_url):
21392141
check_res = "OK"
2140-
else:
2142+
elif not github_user:
2143+
check_res = "FAIL (no GitHub user specified)"
2144+
elif not github_token:
2145+
check_res = "FAIL (missing github token)"
2146+
elif not github_token_valid:
2147+
check_res = "FAIL (invalid github token)"
2148+
elif gist_url:
21412149
check_res = "FAIL (gist_url: %s)" % gist_url
2142-
status['--upload-test-report'] = False
2150+
else:
2151+
check_res = "FAIL"
21432152

2153+
if 'FAIL' in check_res:
2154+
status['--upload-test-report'] = False
21442155
print_msg(check_res, log=_log, prefix=False)
21452156

21462157
# check whether location to local working directories for Git repositories is available (not strictly needed)
21472158
print_msg("* location to Git working dirs... ", log=_log, prefix=False, newline=False)
21482159
git_working_dirs_path = build_option('git_working_dirs_path')
21492160
if git_working_dirs_path:
2150-
check_res = "OK (%s)" % git_working_dirs_path
2161+
repos = [GITHUB_EASYCONFIGS_REPO, GITHUB_EASYBLOCKS_REPO, GITHUB_FRAMEWORK_REPO]
2162+
missing_repos = [repo for repo in repos if not os.path.exists(os.path.join(git_working_dirs_path, repo))]
2163+
if not missing_repos:
2164+
check_res = "OK (%s)" % git_working_dirs_path
2165+
elif missing_repos != repos:
2166+
check_res = "OK (%s) but missing %s (suboptimal)" % (git_working_dirs_path, ', '.join(missing_repos))
2167+
else:
2168+
check_res = "set (%s) but not populated (suboptimal)" % git_working_dirs_path
21512169
else:
21522170
check_res = "not found (suboptimal)"
21532171

0 commit comments

Comments
 (0)