1919from datetime import datetime , timezone , timedelta
2020from pathlib import Path
2121
22- import httpx
22+ from cli . github import fetch_first_approver
2323
2424PROJECT_DIR = Path (__file__ ).resolve ().parent .parent
2525CSV_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-
6645def 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