File size: 1,478 Bytes
cc857c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import json, subprocess, time
rows = [r for r in json.load(open('land_rows.json')) if r['k'] == 'PR' and r['status'] != 'draft']
nums = [r['n'] for r in rows]; out = {}; t0 = time.time()
F = '''number title createdAt updatedAt isDraft mergeable reviewDecision author{login} authorAssociation baseRefName
 files(first:40){nodes{path}}
 commits(last:1){nodes{commit{committedDate statusCheckRollup{state}}}}
 reviews(last:20){nodes{author{login} authorAssociation state submittedAt}}
 reviewRequests(first:5){nodes{requestedReviewer{... on User{login} ... on Team{name}}}}
 comments(last:6){nodes{author{login} authorAssociation createdAt}}
 timelineItems(last:15,itemTypes:[REVIEW_REQUESTED_EVENT,READY_FOR_REVIEW_EVENT]){nodes{__typename ... on ReviewRequestedEvent{createdAt requestedReviewer{... on User{login}}} ... on ReadyForReviewEvent{createdAt}}}'''
for i in range(0, len(nums), 15):
    part = nums[i:i+15]
    q = '{repository(owner:"huggingface",name:"transformers"){' + ' '.join(f'n{n}: pullRequest(number:{n}){{{F}}}' for n in part) + '}}'
    for _ in range(5):
        r = subprocess.run(['gh', 'api', 'graphql', '-f', 'query=' + q], capture_output=True, text=True, timeout=120)
        if r.returncode == 0: break
        time.sleep(10)
    d = json.loads(r.stdout)['data']['repository']
    for n in part: out[n] = d[f'n{n}']
    print(f'[{len(out)}/{len(nums)}] | elapsed {time.time()-t0:.0f}s', flush=True)
json.dump(out, open('rq.json', 'w')); print('done')