Query the GH Api authenticated if GITHUB_TOKEN env variable is available

Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
Pedro Algarvio 2023-03-18 07:35:01 +00:00
parent c9c1e2414e
commit 3fe729c471
No known key found for this signature in database
GPG key ID: BB36BF6584A298FF

View file

@ -1305,7 +1305,12 @@ def _get_salt_releases(ctx: Context, repository: str) -> list[Version]:
"""
versions = set()
with ctx.web as web:
web.headers.update({"Accept": "application/vnd.github+json"})
headers = {
"Accept": "application/vnd.github+json",
}
if "GITHUB_TOKEN" in os.environ:
headers["Authorization"] = f"Bearer {os.environ['GITHUB_TOKEN']}"
web.headers.update(headers)
ret = web.get(f"https://api.github.com/repos/{repository}/tags")
if ret.status_code != 200:
ctx.error(