-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextract_issue.py
48 lines (37 loc) · 1.5 KB
/
extract_issue.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
import requests
from urllib.parse import urlparse
import os
import json
def extract_github_issue (url, input_token):
parsed_url = urlparse(url)
path_segments = parsed_url.path.strip('/').split('/')
headers = {"Authorization": "token " + input_token }
owner, repo, issue_number = path_segments[0], path_segments[1], path_segments[3]
#print(owner, repo, issue_number)
api_url = f"https://api.github.com/repos/{owner}/{repo}/issues/{issue_number}"
response = requests.get(api_url, headers=headers)
if response.status_code == 200:
issue_info = response.json ()
return issue_info
else:
return None
def iterate ():
input_token = input()
for file in os.listdir("verified_bug"):
with open(f"verified_bug/{file}", "r") as f:
content = json.load(f)
for bug in content:
output = dict()
bug_id = content[bug]["bug_id"]
issue_url = content[bug]["issue"]["url"]
issue_info = extract_github_issue(issue_url, input_token)
output["issue_id"] = issue_info["number"]
output["issue_url"] = issue_info["html_url"]
output["title"] = issue_info["title"]
output["description_text"] = issue_info['body']
with open(f"bug_reports/{bug_id}.json", "w") as f:
json.dump(output, f, indent = 2)
if __name__ == '__main__':
if not os.path.isdir("bug_reports"):
os.makedirs("bug_reports")
iterate()