@@ -80,31 +80,30 @@ function isSilent(pr) {
8080 return false ;
8181}
8282
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+ } ) ;
9089
9190 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 ) ;
102100 } else {
103- others . push ( pr ) ;
101+ const otherCategory = categorizedPRs . find ( cat => cat . name === 'others' ) ;
102+ otherCategory . PRs . push ( pr ) ;
104103 }
105104 } ) ;
106105
107- return { silentPRs , features , web , fixes , infra , others } ;
106+ return categorizedPRs ;
108107}
109108
110109function getLine ( log , requester , prNumber ) {
@@ -153,34 +152,47 @@ function getReleaseNotesForType(PRs, title) {
153152 return releaseNotes ;
154153}
155154
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 ) {
157163 const latestReleaseDate = fetchLatestReleaseDate ( tagPrefix , latestVersion ) ;
158164 const PRs = await fetchMergedPRs ( latestReleaseDate , repo , githubToken ) ;
159165 if ( ! PRs ) {
160166 return ;
161167 }
162168
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+ ] ;
164182
183+ const categorizedPRs = getPRsByType ( PRs , prCategories ) ;
165184 let releaseNotes = header ;
166185
167186 releaseNotes += getTitle ( ':rocket: What’s New?' ) ;
168187
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+ } ) ;
176193
177194 releaseNotes += getTitle ( ':bulb: Deprecations & Migrations' ) ;
178195
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-
184196 fs . writeFileSync ( `${ process . env . HOME } /Downloads/${ fileNamePrefix } -release-notes_${ newVersion } .txt` , releaseNotes , {
185197 encoding : 'utf8'
186198 } ) ;
@@ -194,7 +206,8 @@ async function generateReleaseNotes(latestVersion,
194206 fileNamePrefix ,
195207 repo ,
196208 header = '' ,
197- tagPrefix = '' ) {
209+ tagPrefix = '' ,
210+ categories = [ ] ) {
198211 let latestVer , newVer ;
199212 const rl = readline . createInterface ( {
200213 input : process . stdin ,
@@ -212,7 +225,7 @@ async function generateReleaseNotes(latestVersion,
212225 rl . on ( 'close' , ( ) => {
213226 console . info ( `Current latest version is v${ latestVer } ` ) ;
214227 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 ) ;
216229 } ) ;
217230}
218231
0 commit comments