Skip to content

Commit 65e877e

Browse files
committed
Fix refactoring
1 parent 2a232b8 commit 65e877e

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

tools/analytics/org/analyze_runner_usage.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@
7979
GITHUB_TOKEN = os.getenv("GITHUB_TOKEN")
8080
ORG_NAME = None # Will be set by argparse
8181

82+
# GitHub API headers
83+
HEADERS = {
84+
"Authorization": f"Bearer {GITHUB_TOKEN}",
85+
"Accept": "application/vnd.github+json",
86+
}
87+
8288
# List of repositories to exclude in the format 'org/repo'
8389
EXCLUDED_REPOS = [
8490
"pytorch/pytorch",
@@ -150,7 +156,7 @@ def get_repos(org: str) -> List[str]:
150156
while True:
151157
url = f"{BASE_URL}/orgs/{org}/repos?per_page=100&page={page}"
152158
logging.debug(f"[get_repos] Requesting URL: {url}")
153-
data = make_cached_request(url)
159+
data = make_cached_request(url, HEADERS)
154160
if data is None:
155161
logging.error(f"[get_repos] Failed to fetch page {page} for org: {org}")
156162
break
@@ -186,7 +192,7 @@ def get_workflow_runs(org: str, repo: str) -> List[Dict]:
186192
while True:
187193
url = f"{BASE_URL}/repos/{org}/{repo}/actions/runs?per_page=100&page={page}&created=>={WORKFLOW_RUN_LOOKBACK}"
188194
logging.debug(f"[get_workflow_runs] Requesting URL: {url}")
189-
response_data = make_cached_request(url)
195+
response_data = make_cached_request(url, HEADERS)
190196
if response_data is None:
191197
logging.error(
192198
f"[get_workflow_runs] Failed to fetch page {page} for repo: {repo}"
@@ -271,7 +277,7 @@ def get_jobs_for_run(
271277
)
272278
url = f"{BASE_URL}/repos/{org}/{repo}/actions/runs/{run_id}/jobs"
273279
logging.debug(f"[get_jobs_for_run] Requesting URL: {url}")
274-
response_data = make_cached_request(url)
280+
response_data = make_cached_request(url, HEADERS)
275281
if response_data is None:
276282
logging.error(
277283
f"[get_jobs_for_run] Failed to fetch jobs for run {run_id} in repo: {repo}"

tools/analytics/org/cache_manager.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,21 +130,15 @@ def clear_cache():
130130
logging.info(f"[clear_cache] Cache directory does not exist: {CACHE_DIR}")
131131

132132

133-
HEADERS = {
134-
"Authorization": f"Bearer {GITHUB_TOKEN}",
135-
"Accept": "application/vnd.github+json",
136-
}
137-
138-
139133
def make_cached_request(
140-
url: str, headers: Optional[Dict[str, str]] = None
134+
url: str, headers: Dict[str, str]
141135
) -> Optional[Dict]:
142136
"""
143137
Make an HTTP request with caching. Returns the JSON response if successful.
144138
145139
Args:
146140
url: The URL to request
147-
headers: Optional headers for the request
141+
headers: Headers for the request (required)
148142
149143
Returns:
150144
JSON response data if successful, None if failed
@@ -158,7 +152,7 @@ def make_cached_request(
158152
# Make actual HTTP request
159153
logging.info(f"[make_cached_request] Making HTTP request to: {url}")
160154
try:
161-
response = requests.get(url, headers=headers or HEADERS)
155+
response = requests.get(url, headers=headers)
162156
response.raise_for_status()
163157
data = response.json()
164158

0 commit comments

Comments
 (0)