forked from natke/repostats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_issues.py
51 lines (40 loc) · 1.7 KB
/
get_issues.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
45
46
47
48
49
50
51
import os
import requests
import json
import argparse
TOKEN=os.getenv('GITHUB_TOKEN')
PAGE_SIZE=100
argparser = argparse.ArgumentParser()
argparser.add_argument('--start_page', type=int, default = 1, help='Start page for issues query')
argparser.add_argument('--end_page', type=int, default = -1, help='End page for issues query')
argparser.add_argument('--org', type=str, default = 'microsoft', help='org to query')
argparser.add_argument('--repo', type=str, default = 'onnxruntime', help='repo to query')
argparser.add_argument("--labels", type=str, help="List of comma separated GitHub labels from the repo")
args = argparser.parse_args()
start_page = args.start_page
end_page = args.end_page
org = args.org
repo = args.repo
label_filter = args.labels
num_issues = PAGE_SIZE
page=start_page
# Get issues in descending order (oldest first) until the last page
while (num_issues == PAGE_SIZE and (end_page == -1 or page <= end_page)):
# Create an API request
url = f'https://api.github.com/repos/{org}/{repo}/issues'
if label_filter:
url += f'?labels={label_filter}'
file = f'data/{org}-{repo}-{label_filter.replace(",","-").replace(" ", "-")}-issues-{page:06d}.json'
else:
file = f'data/{org}-{repo}-issues-{page:06d}.json'
headers={'Authorization': f'token {TOKEN}'}
params = {'per_page': 100, 'page': page, 'state': "all", 'direction': "asc"}
print(url)
response = requests.get(url, headers=headers, params=params)
response_data = response.json()
num_issues = len(response_data)
print(f'Number of issues in page {page} {num_issues}')
ordered_page = f'{page:06d}'
with open(file, 'w', encoding='utf-8') as f:
json.dump(response_data, f, ensure_ascii=False, indent=4)
page=page+1