28d4ab6e98a5caecccd6b1946ecfa3c51fbda362

Author
Carlo Sala <carlosalag@protonmail.com>
Committer
GitHub <noreply@github.com>
Date

Message

ci(deps): add GH_TOKEN to GitHub API requests (#13502)

Diff

 1diff --git a/.github/workflows/dependencies/updater.py b/.github/workflows/dependencies/updater.py
 2index a830e52100d449ca8ac392ac80117142b3835c68..b61e5858a3671c8fb3eccbb85e127ba92288d833 100644
 3--- a/.github/workflows/dependencies/updater.py
 4+++ b/.github/workflows/dependencies/updater.py
 5@@ -18,6 +18,13 @@ TMP_DIR = os.path.join(os.environ.get("TMP_DIR", "/tmp"), "ohmyzsh")
 6 DEPS_YAML_FILE = ".github/dependencies.yml"
 7 # Dry run flag
 8 DRY_RUN = os.environ.get("DRY_RUN", "0") == "1"
 9+# GitHub Token is needed to avoid rate limiting
10+GH_TOKEN = os.environ.get("GH_TOKEN")
11+HEADERS = {
12+    "Accept": "application/vnd.github+json",
13+}
14+if GH_TOKEN:
15+    HEADERS["Authorization"] = f"Bearer {GH_TOKEN}"
16 
17 # utils for tag comparison
18 BASEVERSION = re.compile(
19@@ -453,7 +460,7 @@ class GitHub:
20         url = f"https://api.github.com/repos/{repo}/git/refs/tags"
21 
22         # Send a GET request to the GitHub API
23-        response = requests.get(url)
24+        response = requests.get(url, headers=HEADERS)
25         current_version = coerce(current_tag)
26         if current_version is None:
27             raise ValueError(
28@@ -513,7 +520,7 @@ class GitHub:
29         url = f"https://api.github.com/repos/{repo}/compare/{version}...{branch}"
30 
31         # Send a GET request to the GitHub API
32-        response = requests.get(url)
33+        response = requests.get(url, headers=HEADERS)
34 
35         # If the request was successful
36         if response.status_code == 200:
37@@ -595,14 +602,14 @@ def main():
38 
39     # Cache YAML version
40     DependencyStore.set(data)
41-    
42+
43     dependencies = data["dependencies"]
44     if len(sys.argv) > 1:
45         # argv is list of dependencies to run, default is all of them
46         dependency_list = sys.argv[1:]
47     else:
48         dependency_list = dependencies.keys()
49-    
50+
51     for path in dependency_list:
52         dependency = Dependency(path, dependencies[path])
53         dependency.update_or_notify()