-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbugs_last_pulse.py
executable file
·44 lines (33 loc) · 1.23 KB
/
bugs_last_pulse.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python3
import argparse
import subprocess
import json
from itertools import batched
import sys
TEAM_NAME = "solutions-engineering"
def parse_args(args):
parser = argparse.ArgumentParser()
parser.add_argument('-s', '--start')
parser.add_argument('-e', '--end')
return parser.parse_args(args)
# So sorry, this is really hacky
def main():
args = parse_args(sys.argv[1:])
period = f"{args.start}..{args.end}"
# TODO: use actual python bindings!
repos_cmd = f"gh api --slurp --paginate /orgs/canonical/teams/{TEAM_NAME}/repos"
repos_json = subprocess.run(repos_cmd, shell=True, capture_output=True).stdout
repos = json.loads(repos_json)
repos_list = [r['full_name'] for r in repos[0]]
output = ''
# try to stay under the 256 chars limit of the CLI API
for batch in batched(repos_list, 6):
csv = ','.join(batch)
cmd = f"gh search issues -R {csv} --label bug --created \"{period}\" --json repository,url"
bugs_json = subprocess.run(cmd, shell=True, capture_output=True).stdout
bugs = json.loads(bugs_json)
for bug in bugs:
output += f"{bug['repository']['name']},{bug['url']}\n"
print(output)
if __name__ == '__main__':
main()