Spaces:
Running
Running
Download code/build_morning.py from ArthurZ/transformers-triage: direct link, hf CLI and curl.
- Browser
- Download file 4.65 kB
-
https://huggingface.co/spaces/ArthurZ/transformers-triage/resolve/main/code/build_morning.py
- Command line
-
hf download hf://spaces/ArthurZ/transformers-triage/code/build_morning.py
-
curl -L -o build_morning.py https://huggingface.co/spaces/ArthurZ/transformers-triage/resolve/main/code/build_morning.py
4.65 kB
| import json, re | |
| E = [r for k in range(3) for r in json.load(open(f'results_E{k}.json'))] | |
| ij = {j['n']: j for j in json.load(open('issues_jobs.json'))} | |
| pj = {j['n']: j for j in json.load(open('open_prs_jobs.json'))} | |
| title = {} | |
| for f in ('issues_v4.html', 'open_prs.html', 'cleanup.html'): | |
| for c in json.loads(re.search(r'const DATA = (.*);\nconst KEY', open(f).read(), re.S).group(1).replace('<\\/', '</')): | |
| title[c['number']] = c['title'] | |
| cards = [] | |
| # 1. posted closes with no evidence -> reopen? | |
| for r in E: | |
| if r['status'].startswith('POSTED') and r['verdict'] == 'no_evidence' and r['number'] != 45709: # 45709: your own message | |
| cards.append(dict(kind=r['kind'], number=r['number'], title=title.get(r['number'], ''), category='reopen?', action='reopen', | |
| confidence='medium', reason=(r.get('note') or r.get('evidence') or 'closed without evidence'), message=r['message'])) | |
| # 2. posted with a wrong reason -> correction comment? | |
| for n in (36514, 10340, 32478): | |
| r = next((x for x in E if x['number'] == n), None) | |
| if r: cards.append(dict(kind=r['kind'], number=n, title=title.get(n, ''), category='correct reason?', action='comment', confidence='medium', | |
| reason='closed with a wrong reason; corrected message cites: ' + (r.get('evidence') or ''), message=r['message'])) | |
| # 3. planned closes the audit could not back -> left open | |
| for r in E: | |
| if r['status'] != 'PENDING close' or r['verdict'] != 'no_evidence': continue | |
| n = r['number']; j = ij.get(n) if r['kind'] == 'issue' else pj.get(n) | |
| if not j: continue | |
| cards.append(dict(kind=r['kind'], number=n, title=title.get(n, ''), category='left open', confidence='medium', | |
| reason=(r.get('note') or r['message'] or 'no evidence found'), message=j['msg'], close_as=j.get('reason'))) | |
| # 4. run failures | |
| fails = [] | |
| for f in ('queue_A_fails.json', 'queue_B_fails.json'): | |
| try: fails += json.load(open(f)) | |
| except Exception: pass | |
| for kind, n, err in fails: | |
| cards.append(dict(kind=kind, number=n, title=title.get(n, ''), category='failed', confidence='medium', reason='GitHub error: ' + err, message='')) | |
| cards.append(dict(kind='pr', number=41827, title=title.get(41827,''), category='maintainer pushback', confidence='medium', | |
| reason='@vasqu reopened it 4 min after our close: "Keeping it for my own references". Left open, nothing to do unless you disagree.', message='')) | |
| cards.append(dict(kind='issue', number=48851, title=title.get(48851,''), category='maintainer pushback', confidence='medium', | |
| reason='@vasqu deleted our new-model details comment (they said earlier it is being done internally). Nothing re-posted.', message='')) | |
| cards += json.load(open('undecided_prs.json')) | |
| t = open('template4.html').read() | |
| t = t.replace("DATA.forEach(a=>{if(!st[a.number])st[a.number]={d:'go'}}); // default: go\n", '') | |
| t = t.replace("a.action==='comment'?`gh ${a.kind==='pr'?'pr':'issue'} comment", | |
| "a.action==='reopen'?`gh ${a.kind==='pr'?'pr':'issue'} reopen ${a.number} -R $R && gh ${a.kind==='pr'?'pr':'issue'} comment ${a.number} -R $R -b ${q(m)}`:a.action==='comment'?`gh ${a.kind==='pr'?'pr':'issue'} comment") | |
| t = t.replace("lines.push(a.action==='reopen'", "lines.push(a.action==='reopen'") | |
| t = t.replace(":`gh issue close ${a.number} -R $R -r ${q(a.close_as||'completed')} -c ${q(m)}`", ":`gh issue close ${a.number} -R $R -r ${q(a.close_as||'completed')} -c ${q(m)}`") | |
| t = t.replace('<option>superseded</option><option>obsolete</option><option>stale</option><option>nudge</option>', | |
| '<option>undecided PR close</option><option>undecided nudge</option><option>maintainer pushback</option><option>reopen?</option><option>correct reason?</option><option>left open</option><option>failed</option>') | |
| t = t.replace("if(a.confidence!=='high'&&!isRead(a)){skipped++;return;} // unread check-cards = undecided; obvious ones export", '') | |
| t = t.replace("const KEY='triage-open-prs-decisions';", "const KEY='triage-morning-decisions';") | |
| t = t.replace('<b>transformers open PRs</b>', '<b>Morning: your calls</b>').replace('<title>Open PR Review</title>', '<title>Morning Decisions</title>') | |
| t = t.replace("l.download='open_prs.sh'", "l.download='morning.sh'").replace('Export gh script (read cards only)', 'Export gh script') | |
| t = t.replace('<input type="checkbox" id="hideNudge" checked>', '<input type="checkbox" id="hideNudge">') | |
| assert 'reopen ${a.number}' in t | |
| open('morning.html', 'w').write(t.replace('__DATA__', json.dumps(cards).replace('</', '<\\/'))) | |
| from collections import Counter; print(len(cards), Counter(c['category'] for c in cards)) | |