make sure GITHUB_TOKEN exists and is not empty before using it in auth headers

This commit is contained in:
Óscar San José
2024-05-14 11:22:07 +02:00
parent faa2dcee24
commit 9105faa3fd

View File

@@ -68,7 +68,7 @@ def get_endpoint():
# see https://github.com/actions/checkout/blob/44c2b7a8a4ea60a981eaca3cf939b5f4305c123b/src/git-auth-helper.ts#L56-L63
auth = git("config", f"http.{url.scheme}://{url.netloc}/.extraheader")
endpoint.update_headers(get_env(auth, sep=": "))
if "GITHUB_TOKEN" in os.environ and os.environ.get("GITHUB_TOKEN") != "":
if os.environ.get("GITHUB_TOKEN"):
endpoint.headers["Authorization"] = f"token {os.environ['GITHUB_TOKEN']}"
if "Authorization" not in endpoint.headers:
# last chance: use git credentials (possibly backed by a credential helper like the one installed by gh)