23
23
'feature request' ,
24
24
'customer success' ,
25
25
]
26
+ ISSUE_LABELS_ORDERED_BY_IMPORTANCE = [
27
+ 'feature request' ,
28
+ 'customer success' ,
29
+ 'bug' ,
30
+ 'documentation' ,
31
+ 'internal' ,
32
+ 'maintenance' ,
33
+ ]
26
34
NEW_LINE = '\n '
27
35
GITHUB_URL = 'https://api.github.com/repos/sdv-dev/sdmetrics'
28
36
GITHUB_TOKEN = os .getenv ('GH_ACCESS_TOKEN' )
@@ -36,10 +44,12 @@ def _get_milestone_number(milestone_title):
36
44
body = response .json ()
37
45
if response .status_code != 200 :
38
46
raise Exception (str (body ))
47
+
39
48
milestones = body
40
49
for milestone in milestones :
41
50
if milestone .get ('title' ) == milestone_title :
42
51
return milestone .get ('number' )
52
+
43
53
raise ValueError (f'Milestone { milestone_title } not found in past 100 milestones.' )
44
54
45
55
@@ -57,16 +67,22 @@ def _get_issues_by_milestone(milestone):
57
67
body = response .json ()
58
68
if response .status_code != 200 :
59
69
raise Exception (str (body ))
70
+
60
71
issues_on_page = body
61
72
if not issues_on_page :
62
73
break
74
+
75
+ # Filter our PRs
76
+ issues_on_page = [issue for issue in issues_on_page if issue .get ('pull_request' ) is None ]
63
77
issues .extend (issues_on_page )
64
78
page += 1
79
+
65
80
return issues
66
81
67
82
68
83
def _get_issues_by_category (release_issues ):
69
84
category_to_issues = defaultdict (list )
85
+
70
86
for issue in release_issues :
71
87
issue_title = issue ['title' ]
72
88
issue_number = issue ['number' ]
@@ -76,6 +92,7 @@ def _get_issues_by_category(release_issues):
76
92
if assignee :
77
93
login = assignee ['login' ]
78
94
line += f' by @{ login } '
95
+
79
96
# Check if any known label is marked on the issue
80
97
labels = [label ['name' ] for label in issue ['labels' ]]
81
98
found_category = False
@@ -84,22 +101,27 @@ def _get_issues_by_category(release_issues):
84
101
category_to_issues [category ].append (line )
85
102
found_category = True
86
103
break
104
+
87
105
if not found_category :
88
106
category_to_issues ['misc' ].append (line )
107
+
89
108
return category_to_issues
90
109
91
110
92
111
def _create_release_notes (issues_by_category , version , date ):
93
112
title = f'## v{ version } - { date } '
94
113
release_notes = f'{ title } { NEW_LINE } { NEW_LINE } '
95
- for category in ISSUE_LABELS + ['misc' ]:
114
+
115
+ for category in ISSUE_LABELS_ORDERED_BY_IMPORTANCE + ['misc' ]:
96
116
issues = issues_by_category .get (category )
97
117
if issues :
98
118
section_text = (
99
119
f'### { LABEL_TO_HEADER [category ]} { NEW_LINE } { NEW_LINE } '
100
120
f'{ NEW_LINE .join (issues )} { NEW_LINE } { NEW_LINE } '
101
121
)
122
+
102
123
release_notes += section_text
124
+
103
125
return release_notes
104
126
105
127
@@ -108,10 +130,12 @@ def update_release_notes(release_notes):
108
130
file_path = 'HISTORY.md'
109
131
with open (file_path , 'r' ) as history_file :
110
132
history = history_file .read ()
133
+
111
134
token = '# HISTORY\n \n '
112
135
split_index = history .find (token ) + len (token ) + 1
113
136
header = history [:split_index ]
114
137
new_notes = f'{ header } { release_notes } { history [split_index :]} '
138
+
115
139
with open (file_path , 'w' ) as new_history_file :
116
140
new_history_file .write (new_notes )
117
141
0 commit comments