Spaces:
Running
Running
File size: 1,276 Bytes
cc857c8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | 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)
|