generated from Code-Institute-Org/ci-full-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
json_to_markdown.py
77 lines (60 loc) · 1.72 KB
/
json_to_markdown.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""Generate a markdown file from Github JSON data"""
import json
import pandas
# Load the JSON data
f = open('issues.json')
raw = json.load(f)
f.close()
# Helper functions
def remove_multiple_blank_lines(string):
string = string.replace('\r\n', '<br/>')
while '<br/><br/>' in string:
string = string.replace('<br/><br/>', '<br/>')
return string
def issue_key(issue):
return issue['Number']
def get_markdown(issues):
issues.sort(key=issue_key)
# Add title lines
md_lines = []
md_lines.append('# Resolved Bugs\r\n')
md_lines.append(
'The folllowings bugs have been resolved '
+ ' and retested.\r\n'
)
# Add issue lines
for issue in issues:
md_line = str(issue['Number'])
md_line += '. **' + issue['Title'] + '**<br/>'
md_line += issue['Description'] + '<br/>'
md_line += '**Resolution**<br/>' + issue['Resolution']
md_line += '\r\n'
md_lines.append(md_line)
return md_lines
# Generate issues dictionary from raw data
issues = []
for gh_issue in raw:
print(str(gh_issue))
# Extract and format data
title = '[' + gh_issue['title'] + '](' + gh_issue['url'] + ')'
description = remove_multiple_blank_lines(gh_issue['body'])
solution = ''
try:
solution = remove_multiple_blank_lines(gh_issue['comments'][0]['body'])
except Exception:
pass
# Create issue dictionary
issue = {
'Number': gh_issue['number'],
'Title': title,
'Description': description,
'Resolution': solution
}
print(str(issue))
issues.append(issue)
md = get_markdown(issues)
print(md)
f = open("BUGS.MD", "w")
for line in md:
f.write(line + '\r\n')
f.close()