Skip to content

Commit 27abfbf

Browse files
fix: use panel.querySelector for leaderboard table, import fetch_first_approver in backfill
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 5631929 commit 27abfbf

2 files changed

Lines changed: 8 additions & 25 deletions

File tree

reports/interactive_report.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,11 +1401,11 @@ def build_interactive_report(
14011401
const medals = ['\U0001F947', '\U0001F948', '\U0001F949'];
14021402
const rowClasses = ['gold-row', 'silver-row', 'bronze-row'];
14031403
if (!rows.length) {{
1404-
document.getElementById('lb-tbody').innerHTML =
1404+
panel.querySelector('#lb-tbody').innerHTML =
14051405
'<tr><td colspan="5" style="text-align:center;padding:2rem;color:var(--text-muted)">No approval data for this period</td></tr>';
14061406
return;
14071407
}}
1408-
document.getElementById('lb-tbody').innerHTML = rows.map((r, i) => {{
1408+
panel.querySelector('#lb-tbody').innerHTML = rows.map((r, i) => {{
14091409
const cls = i < 3 ? rowClasses[i] : '';
14101410
const rank = i < 3 ? medals[i] : (i + 1);
14111411
return `<tr class="${{cls}}">

scripts/backfill-approvals.py

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from datetime import datetime, timezone, timedelta
2020
from pathlib import Path
2121

22-
import httpx
22+
from cli.github import fetch_first_approver
2323

2424
PROJECT_DIR = Path(__file__).resolve().parent.parent
2525
CSV_FILE = PROJECT_DIR / "complexity-report.csv"
@@ -42,27 +42,6 @@ def _parse_github_url(url: str):
4242
return parts[-4], parts[-3], int(parts[-1])
4343

4444

45-
def _fetch_first_approver(owner: str, repo: str, pr: int, token: str) -> str:
46-
"""Return login of first APPROVED reviewer, or '' if none."""
47-
url = f"https://api.github.com/repos/{owner}/{repo}/pulls/{pr}/reviews"
48-
headers = {
49-
"Authorization": f"Bearer {token}",
50-
"Accept": "application/vnd.github+json",
51-
}
52-
try:
53-
resp = httpx.get(url, headers=headers, timeout=30)
54-
if resp.status_code == 404:
55-
return ""
56-
resp.raise_for_status()
57-
reviews = resp.json()
58-
approved = [r for r in reviews if r.get("state") == "APPROVED"]
59-
approved.sort(key=lambda r: r.get("submitted_at", ""))
60-
return approved[0]["user"]["login"] if approved else ""
61-
except Exception as e:
62-
print(f" Warning: {e}", file=sys.stderr)
63-
return ""
64-
65-
6645
def main() -> None:
6746
if not CSV_FILE.exists():
6847
print(f"Error: {CSV_FILE} not found", file=sys.stderr)
@@ -121,7 +100,11 @@ def main() -> None:
121100
continue
122101

123102
print(f" [{i}/{len(to_backfill)}] {pr_url} ...", end=" ", flush=True)
124-
approver = _fetch_first_approver(owner, repo, pr_num, token)
103+
try:
104+
approver = fetch_first_approver(owner, repo, pr_num, token=token)
105+
except Exception as e:
106+
print(f" Warning: {e}", file=sys.stderr)
107+
approver = ""
125108
row["approved_by"] = approver
126109
filled += 1
127110
print(approver or "(none)")

0 commit comments

Comments
 (0)