ArthurZ's picture
ArthurZ HF Staff
Add triage pipeline code
cc857c8 verified
Raw History Blame Contribute Delete
1.28 kB
import json, subprocess, sys, time
Q = """
query($cursor:String){repository(owner:"huggingface",name:"transformers"){
pullRequests(states:OPEN, first:30, after:$cursor){ totalCount pageInfo{hasNextPage endCursor}
nodes{ number title createdAt updatedAt isDraft baseRefName mergeable reviewDecision additions deletions
author{login} authorAssociation labels(first:10){nodes{name}}
commits(last:1){nodes{commit{committedDate}}}
files(first:100){totalCount nodes{path}}
comments(last:3){nodes{author{login} authorAssociation createdAt body}}
}}}}
"""
items, cursor, t0 = [], None, time.time()
while True:
args = ["gh", "api", "graphql", "-f", f"query={Q}"] + (["-f", f"cursor={cursor}"] if cursor else [])
for _ in range(5):
r = subprocess.run(args, capture_output=True, text=True)
if r.returncode == 0: break
time.sleep(10)
d = json.loads(r.stdout)["data"]["repository"]["pullRequests"]
items += d["nodes"]; el = time.time() - t0
print(f"[{len(items)}/{d['totalCount']}] | elapsed {el:.0f}s | eta ~{el/len(items)*(d['totalCount']-len(items)):.0f}s", flush=True)
if not d["pageInfo"]["hasNextPage"]: break
cursor = d["pageInfo"]["endCursor"]
json.dump(items, open(sys.argv[1], "w"))
print("done", flush=True)