Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ isort = ">=5.13.2,<8.0.0"
pytest-aiohttp = "^1.0.5"
pytest-asyncio = ">=0.25,<1.3"
pre-commit = "^4.0.0"
debugpy = "^1.8.17"

[build-system]
requires = ["poetry-core"]
Expand Down
34 changes: 33 additions & 1 deletion reviewtally/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import time
from typing import Any

import requests
from tqdm import tqdm

from reviewtally.analysis.sprint_periods import calculate_sprint_periods
Expand All @@ -20,7 +21,12 @@
from reviewtally.exporters.sprint_export import export_sprint_csv
from reviewtally.metrics_calculation import calculate_reviewer_metrics
from reviewtally.output_formatting import generate_results_table
from reviewtally.queries import set_github_host
from reviewtally.queries import (
GENERAL_TIMEOUT,
build_github_rest_api_url,
require_github_token,
set_github_host,
)
from reviewtally.queries.get_repos_gql import get_repos
from reviewtally.visualization.individual_plot import (
SUPPORTED_INDIVIDUAL_METRICS,
Expand Down Expand Up @@ -61,6 +67,32 @@ def main() -> None:
f"{time.time() - start_time:.2f} seconds"
)
timestamped_print(configured_message)
token = require_github_token()
headers = {
"Authorization": f"Bearer {token}",
"Accept": "application/vnd.github.v3+json",
}
for target in repo_targets:
url = build_github_rest_api_url(
f"repos/{target.owner}/{target.name}",
)
response = requests.get(
url,
headers=headers,
timeout=GENERAL_TIMEOUT,
)
try:
response.raise_for_status()
except requests.exceptions.HTTPError as e:
status = (
getattr(e.response, "status_code", None)
or response.status_code
)
print( # noqa: T201
f"Error: repository {target.owner}/{target.name} not found "
f"(HTTP {status})",
)
sys.exit(1)
else:
request_message = (
"Calling get_repos_by_language "
Expand Down
16 changes: 14 additions & 2 deletions reviewtally/queries/get_prs.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,25 @@ def _make_pr_request_with_retry(

# Handle rate limiting (existing logic)
backoff_if_ratelimited(response.headers)
Comment on lines 95 to 97

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Respect rate-limit reset before retrying pull request fetch

In _make_pr_request_with_retry the loop now continues for retryable statuses before calling backoff_if_ratelimited. For responses like 429 the exponential backoff runs but the code ignores X-RateLimit-Reset, so retries fire immediately and exhaust MAX_RETRIES even though waiting until the reset would succeed. The previous version always slept using the rate-limit headers, so this change regresses handling of GitHub rate limits.

Useful? React with 👍 / 👎.

response.raise_for_status()
try:
response.raise_for_status()
except requests.exceptions.HTTPError as e:
status = getattr(e.response, "status_code", None) or response.status_code
# Fail fast on non-retryable HTTP errors (e.g. 404/422)
if status not in RETRYABLE_STATUS_CODES:
raise
# Retry on retryable HTTP errors if attempts remain
if attempt < MAX_RETRIES:
_backoff_delay(attempt)
continue
# No attempts left; re-raise
raise

return response.json()

except (
requests.exceptions.RequestException,
requests.exceptions.Timeout,
requests.exceptions.ConnectionError,
):
if attempt < MAX_RETRIES:
_backoff_delay(attempt)
Expand Down
Loading