make GITHUB_TOKEN in lfs_probe a fallback rather than an override

This commit is contained in:
Óscar San José 2024-05-14 10:24:02 +02:00
Родитель 4d54c09a6f
Коммит 5b572a2c2a
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 5579CE1712B30217
1 изменённых файлов: 10 добавлений и 9 удалений

Просмотреть файл

@ -68,16 +68,17 @@ 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:
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)
# see https://git-scm.com/docs/git-credential
credentials = get_env(git("credential", "fill", check=True,
# drop leading / from url.path
input=f"protocol={url.scheme}\nhost={url.netloc}\npath={url.path[1:]}\n"))
auth = base64.b64encode(f'{credentials["username"]}:{credentials["password"]}'.encode()).decode('ascii')
endpoint.headers["Authorization"] = f"Basic {auth}"
if "GITHUB_TOKEN" in os.environ:
endpoint.headers["Authorization"] = f"token {os.environ['GITHUB_TOKEN']}"
else:
# last chance: use git credentials (possibly backed by a credential helper like the one installed by gh)
# see https://git-scm.com/docs/git-credential
credentials = get_env(git("credential", "fill", check=True,
# drop leading / from url.path
input=f"protocol={url.scheme}\nhost={url.netloc}\npath={url.path[1:]}\n"))
auth = base64.b64encode(f'{credentials["username"]}:{credentials["password"]}'.encode()).decode('ascii')
endpoint.headers["Authorization"] = f"Basic {auth}"
return endpoint