From 6b881aa6651e7a5ed3375584600da6bdae7998d5 Mon Sep 17 00:00:00 2001 From: Philipp Schlegel Date: Thu, 16 May 2024 09:40:44 +0100 Subject: [PATCH] annotations: use `GITHUT_PAT` env variable for Github queries if avail. --- fafbseg/flywire/annotations.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/fafbseg/flywire/annotations.py b/fafbseg/flywire/annotations.py index 3a76e54..19966ad 100644 --- a/fafbseg/flywire/annotations.py +++ b/fafbseg/flywire/annotations.py @@ -1542,10 +1542,20 @@ def _get_cached_annotation_materializations(commit): return np.array(mats) +@lru_cache +def _get_github_session(): + s = requests.Session() + if "GITHUB_PAT" in os.environ: + s.auth = ('user', 'pass') + s.headers.update({'Authorization': f"Bearer {os.environ['GITHUB_PAT']}"}) + + return s + + @lru_cache def _get_available_annotation_versions(): # Get available tags - r = requests.get("https://api.github.com/repos/flyconnectome/flywire_annotations/tags") + r = _get_github_session().get("https://api.github.com/repos/flyconnectome/flywire_annotations/tags") r.raise_for_status() return r.json() @@ -1553,7 +1563,7 @@ def _get_available_annotation_versions(): @lru_cache def _get_available_commits(): # Get available commits - r = requests.get("https://api.github.com/repos/flyconnectome/flywire_annotations/commits") + r = _get_github_session().get("https://api.github.com/repos/flyconnectome/flywire_annotations/commits") r.raise_for_status() return r.json() @@ -1561,7 +1571,7 @@ def _get_available_commits(): @lru_cache def _get_available_branches(): # Get available tags - r = requests.get("https://api.github.com/repos/flyconnectome/flywire_annotations/branches") + r = _get_github_session().get("https://api.github.com/repos/flyconnectome/flywire_annotations/branches") r.raise_for_status() return r.json()