fix: adding rate limit warning at verify token permission stage (#14756)
This commit is contained in:
@@ -13,6 +13,15 @@ from urllib.error import HTTPError
|
|||||||
from urllib.request import Request, urlopen
|
from urllib.request import Request, urlopen
|
||||||
|
|
||||||
|
|
||||||
|
def is_rate_limit_error(e):
|
||||||
|
"""Check if an exception is a rate limit error"""
|
||||||
|
return (
|
||||||
|
isinstance(e, HTTPError)
|
||||||
|
and e.code in [403, 429]
|
||||||
|
and "rate limit exceeded" in getattr(e, "error_body", "").lower()
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def make_github_request(url, token, method="GET", data=None):
|
def make_github_request(url, token, method="GET", data=None):
|
||||||
"""Make authenticated request to GitHub API"""
|
"""Make authenticated request to GitHub API"""
|
||||||
headers = {
|
headers = {
|
||||||
@@ -56,6 +65,9 @@ def verify_token_permissions(repo_owner, repo_name, token):
|
|||||||
repo_data = json.loads(response)
|
repo_data = json.loads(response)
|
||||||
print(f"Repository access verified: {repo_data['full_name']}")
|
print(f"Repository access verified: {repo_data['full_name']}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
if is_rate_limit_error(e):
|
||||||
|
warnings.warn("GitHub API rate limit exceeded during token verification.")
|
||||||
|
return "rate_limited"
|
||||||
print(f"Failed to access repository: {e}")
|
print(f"Failed to access repository: {e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -65,6 +77,9 @@ def verify_token_permissions(repo_owner, repo_name, token):
|
|||||||
response = make_github_request(url, token)
|
response = make_github_request(url, token)
|
||||||
print("Repository contents access verified")
|
print("Repository contents access verified")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
if is_rate_limit_error(e):
|
||||||
|
warnings.warn("GitHub API rate limit exceeded during token verification.")
|
||||||
|
return "rate_limited"
|
||||||
print(f"Failed to access repository contents: {e}")
|
print(f"Failed to access repository contents: {e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -277,7 +292,14 @@ def publish_traces(traces_dir, run_id, run_number):
|
|||||||
print(f"Found {len(files_to_upload)} files to upload")
|
print(f"Found {len(files_to_upload)} files to upload")
|
||||||
|
|
||||||
# Verify token permissions before proceeding
|
# Verify token permissions before proceeding
|
||||||
if not verify_token_permissions(repo_owner, repo_name, token):
|
permission_check = verify_token_permissions(repo_owner, repo_name, token)
|
||||||
|
if permission_check == "rate_limited":
|
||||||
|
warnings.warn(
|
||||||
|
"Skipping trace upload due to GitHub API rate limit. "
|
||||||
|
"This is expected during high CI activity and does not indicate a test failure."
|
||||||
|
)
|
||||||
|
return
|
||||||
|
elif not permission_check:
|
||||||
print(
|
print(
|
||||||
"Token permission verification failed. Please check the token permissions."
|
"Token permission verification failed. Please check the token permissions."
|
||||||
)
|
)
|
||||||
@@ -340,11 +362,7 @@ def publish_traces(traces_dir, run_id, run_number):
|
|||||||
error_type = f"HTTP {e.code}"
|
error_type = f"HTTP {e.code}"
|
||||||
|
|
||||||
# Check for rate limit errors (non-fatal - just warn and skip)
|
# Check for rate limit errors (non-fatal - just warn and skip)
|
||||||
if (
|
if is_rate_limit_error(e):
|
||||||
isinstance(e, HTTPError)
|
|
||||||
and e.code in [403, 429]
|
|
||||||
and "rate limit exceeded" in getattr(e, "error_body", "").lower()
|
|
||||||
):
|
|
||||||
warnings.warn("GitHub API rate limit exceeded. Skipping trace upload.")
|
warnings.warn("GitHub API rate limit exceeded. Skipping trace upload.")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user