@@ -80,31 +80,30 @@ function isSilent(pr) {
80
80
return false ;
81
81
}
82
82
83
- function getPRsByType ( PRs ) {
84
- const silentPRs = [ ] ,
85
- features = [ ] ,
86
- web = [ ] ,
87
- fixes = [ ] ,
88
- infra = [ ] ,
89
- others = [ ] ;
83
+ function getPRsByType ( PRs , categories ) {
84
+ const categorizedPRs = [ ] ;
85
+
86
+ categories . forEach ( category => {
87
+ categorizedPRs . push ( { name : category . name , PRs : [ ] , title : category . title } ) ;
88
+ } ) ;
90
89
91
90
PRs . forEach ( pr => {
92
- if ( isSilent ( pr ) ) {
93
- silentPRs . push ( pr ) ;
94
- } else if ( pr . branch . startsWith ( 'feat/' ) ) {
95
- features . push ( pr ) ;
96
- } else if ( pr . branch . startsWith ( 'web/' ) ) {
97
- web . push ( pr ) ;
98
- } else if ( pr . branch . startsWith ( 'fix/' ) ) {
99
- fixes . push ( pr ) ;
100
- } else if ( pr . branch . startsWith ( 'infra/' ) ) {
101
- infra . push ( pr ) ;
91
+ const category = categories . find ( category => {
92
+ return pr . branch . toLowerCase ( ) . startsWith ( category . branch ) ;
93
+ } ) ;
94
+ if ( category ) {
95
+ const foundCategory = categorizedPRs . find ( cat => cat . name === category . name ) ;
96
+ foundCategory . PRs . push ( pr ) ;
97
+ } else if ( isSilent ( pr ) ) {
98
+ const silentCategory = categorizedPRs . find ( cat => cat . name === 'silent' ) ;
99
+ silentCategory . PRs . push ( pr ) ;
102
100
} else {
103
- others . push ( pr ) ;
101
+ const otherCategory = categorizedPRs . find ( cat => cat . name === 'others' ) ;
102
+ otherCategory . PRs . push ( pr ) ;
104
103
}
105
104
} ) ;
106
105
107
- return { silentPRs , features , web , fixes , infra , others } ;
106
+ return categorizedPRs ;
108
107
}
109
108
110
109
function getLine ( log , requester , prNumber ) {
@@ -153,34 +152,47 @@ function getReleaseNotesForType(PRs, title) {
153
152
return releaseNotes ;
154
153
}
155
154
156
- async function _generateReleaseNotes ( latestVersion , newVersion , githubToken , fileNamePrefix , repo , header , tagPrefix ) {
155
+ async function _generateReleaseNotes ( latestVersion ,
156
+ newVersion ,
157
+ githubToken ,
158
+ fileNamePrefix ,
159
+ repo ,
160
+ header ,
161
+ tagPrefix ,
162
+ categories ) {
157
163
const latestReleaseDate = fetchLatestReleaseDate ( tagPrefix , latestVersion ) ;
158
164
const PRs = await fetchMergedPRs ( latestReleaseDate , repo , githubToken ) ;
159
165
if ( ! PRs ) {
160
166
return ;
161
167
}
162
168
163
- const { silentPRs, features, web, fixes, infra, others} = getPRsByType ( PRs ) ;
169
+ const prCategories = [
170
+ { name : 'features' , branch : 'feat/' , title : ':gift: Features' } ,
171
+ { name : 'web' , branch : 'web/' , title : ':spider_web: Web support' } ,
172
+ { name : 'fixes' , branch : 'fix/' , title : ':wrench: Fixes' } ,
173
+ { name : 'infra' , branch : 'infra/' , title : ':gear: Maintenance & Infra' } ,
174
+ ...categories ,
175
+ { name : 'others' , branch : '' , title : 'OTHERS' } ,
176
+ {
177
+ name : 'silent' ,
178
+ branch : '' ,
179
+ title : '// Silent - these PRs did not have a changelog or were left out for some other reason, is it on purpose?'
180
+ }
181
+ ] ;
164
182
183
+ const categorizedPRs = getPRsByType ( PRs , prCategories ) ;
165
184
let releaseNotes = header ;
166
185
167
186
releaseNotes += getTitle ( ':rocket: What’s New?' ) ;
168
187
169
- releaseNotes += getReleaseNotesForType ( features , ':gift: Features' ) ;
170
-
171
- releaseNotes += getReleaseNotesForType ( web , ':spider_web: Web support' ) ;
172
-
173
- releaseNotes += getReleaseNotesForType ( fixes , ':wrench: Fixes' ) ;
174
-
175
- releaseNotes += getReleaseNotesForType ( infra , ':gear: Maintenance & Infra' ) ;
188
+ categorizedPRs . forEach ( ( { PRs, title} ) => {
189
+ if ( PRs . length > 0 ) {
190
+ releaseNotes += getReleaseNotesForType ( PRs , title ) ;
191
+ }
192
+ } ) ;
176
193
177
194
releaseNotes += getTitle ( ':bulb: Deprecations & Migrations' ) ;
178
195
179
- releaseNotes += getReleaseNotesForType ( others , 'OTHERS' ) ;
180
-
181
- releaseNotes += getReleaseNotesForType ( silentPRs ,
182
- '// Silent - these PRs did not have a changelog or were left out for some other reason, is it on purpose?' ) ;
183
-
184
196
fs . writeFileSync ( `${ process . env . HOME } /Downloads/${ fileNamePrefix } -release-notes_${ newVersion } .txt` , releaseNotes , {
185
197
encoding : 'utf8'
186
198
} ) ;
@@ -194,7 +206,8 @@ async function generateReleaseNotes(latestVersion,
194
206
fileNamePrefix ,
195
207
repo ,
196
208
header = '' ,
197
- tagPrefix = '' ) {
209
+ tagPrefix = '' ,
210
+ categories = [ ] ) {
198
211
let latestVer , newVer ;
199
212
const rl = readline . createInterface ( {
200
213
input : process . stdin ,
@@ -212,7 +225,7 @@ async function generateReleaseNotes(latestVersion,
212
225
rl . on ( 'close' , ( ) => {
213
226
console . info ( `Current latest version is v${ latestVer } ` ) ;
214
227
console . info ( `Generating release notes out or PRs for v${ newVer } ` ) ;
215
- _generateReleaseNotes ( latestVer , newVer , githubToken , fileNamePrefix , repo , header , tagPrefix ) ;
228
+ _generateReleaseNotes ( latestVer , newVer , githubToken , fileNamePrefix , repo , header , tagPrefix , categories ) ;
216
229
} ) ;
217
230
}
218
231
0 commit comments