@@ -150,102 +150,60 @@ async function readChangesets(options = {}) {
150150 return changesets . filter ( changeset => changeset . branch === branch ) ;
151151}
152152
153- // Ensure consistent formatting for changeset entries
154- function formatChangesetEntry ( changeset ) {
155- // Clean up the title (remove quotes, ensure proper format)
156- const title = changeset . title . replace ( / ^ [ ' " ] | [ ' " ] $ / g, '' ) ;
157-
158- return `* **${ title } ** (#${ changeset . pr } ) - @${ changeset . author } ` ;
153+ /**
154+ * Format a changeset entry for the release notes
155+ * @param {Object } changeset The changeset object
156+ * @returns {string } Formatted entry
157+ */
158+ function formatChangesetEntry ( changeset , repoUrl ) {
159+ return `- **${ changeset . title } ** ([#${ changeset . pr } ](${ repoUrl } /pull/${ changeset . pr } )) - @${ changeset . author } ` ;
159160}
160161
161162// Generate release notes in markdown format
162163async function generateMarkdownReleaseNotes ( changesets , repoUrl , token ) {
163164 // Categorize changesets
164165 const categories = categorizeChangesets ( changesets ) ;
165166
166- // Determine the appropriate version bump type
167- const bumpType = determineBumpType ( changesets ) ;
168-
169167 // Start building the release notes
170168 let notes = `` ;
171169
172170 // Add breaking changes section if there are any
173171 if ( categories . breaking . length > 0 ) {
174172 notes += `### Breaking Changes ⚠️\n\n` ;
175-
176173 for ( const changeset of categories . breaking ) {
177174 const prLink = repoUrl ? `([#${ changeset . pr } ](${ repoUrl } /pull/${ changeset . pr } ))` : `(#${ changeset . pr } )` ;
178- const prefixRegex = / ^ ( f e a t ! ? | f i x ! ? | d o c s ! ? | s t y l e ! ? | r e f a c t o r ! ? | p e r f ! ? | t e s t ! ? | b u i l d ! ? | c i ! ? | c h o r e ! ? | r e v e r t ! ? ) ( \( [ ^ ) ] + \) ) ? : / ;
179- const match = changeset . title . match ( prefixRegex ) ;
180- if ( match ) {
181- const prefix = changeset . title . substring ( 0 , match [ 0 ] . length ) ;
182- const restOfTitle = changeset . title . substring ( match [ 0 ] . length ) . trim ( ) ;
183- notes += `- **${ prefix } ** ${ restOfTitle } ${ prLink } - @${ changeset . author } \n` ;
184- } else {
185- notes += `- **${ changeset . title } ** ${ prLink } - @${ changeset . author } \n` ;
186- }
175+ notes += `- ${ changeset . title } ${ prLink } - @${ changeset . author } \n` ;
187176 }
188-
189177 notes += `\n` ;
190178 }
191179
192180 // Add features section if there are any
193181 if ( categories . features . length > 0 ) {
194182 notes += `### Features ✨\n\n` ;
195-
196183 for ( const changeset of categories . features ) {
197184 const prLink = repoUrl ? `([#${ changeset . pr } ](${ repoUrl } /pull/${ changeset . pr } ))` : `(#${ changeset . pr } )` ;
198- const prefixRegex = / ^ ( f e a t ! ? | f i x ! ? | d o c s ! ? | s t y l e ! ? | r e f a c t o r ! ? | p e r f ! ? | t e s t ! ? | b u i l d ! ? | c i ! ? | c h o r e ! ? | r e v e r t ! ? ) ( \( [ ^ ) ] + \) ) ? : / ;
199- const match = changeset . title . match ( prefixRegex ) ;
200- if ( match ) {
201- const prefix = changeset . title . substring ( 0 , match [ 0 ] . length ) ;
202- const restOfTitle = changeset . title . substring ( match [ 0 ] . length ) . trim ( ) ;
203- notes += `- **${ prefix } ** ${ restOfTitle } ${ prLink } - @${ changeset . author } \n` ;
204- } else {
205- notes += `- **${ changeset . title . replace ( / ^ f e a t : \s * / i, '' ) } ** ${ prLink } - @${ changeset . author } \n` ;
206- }
185+ notes += `- ${ changeset . title } ${ prLink } - @${ changeset . author } \n` ;
207186 }
208-
209187 notes += `\n` ;
210188 }
211189
212190 // Add fixes section if there are any
213191 if ( categories . fixes . length > 0 ) {
214192 notes += `### Fixes 🐛\n\n` ;
215-
216193 for ( const changeset of categories . fixes ) {
217194 const prLink = repoUrl ? `([#${ changeset . pr } ](${ repoUrl } /pull/${ changeset . pr } ))` : `(#${ changeset . pr } )` ;
218- const prefixRegex = / ^ ( f e a t ! ? | f i x ! ? | d o c s ! ? | s t y l e ! ? | r e f a c t o r ! ? | p e r f ! ? | t e s t ! ? | b u i l d ! ? | c i ! ? | c h o r e ! ? | r e v e r t ! ? ) ( \( [ ^ ) ] + \) ) ? : / ;
219- const match = changeset . title . match ( prefixRegex ) ;
220- if ( match ) {
221- const prefix = changeset . title . substring ( 0 , match [ 0 ] . length ) ;
222- const restOfTitle = changeset . title . substring ( match [ 0 ] . length ) . trim ( ) ;
223- notes += `- **${ prefix } ** ${ restOfTitle } ${ prLink } - @${ changeset . author } \n` ;
224- } else {
225- notes += `- **${ changeset . title . replace ( / ^ f i x : \s * / i, '' ) } ** ${ prLink } - @${ changeset . author } \n` ;
226- }
195+ notes += `- ${ changeset . title } ${ prLink } - @${ changeset . author } \n` ;
227196 }
228-
229197 notes += `\n` ;
230198 }
231199
232200 // Add other changes section if there are any
233201 if ( categories . other . length > 0 ) {
234202 notes += `### Other Changes 🔄\n\n` ;
235-
236203 for ( const changeset of categories . other ) {
237204 const prLink = repoUrl ? `([#${ changeset . pr } ](${ repoUrl } /pull/${ changeset . pr } ))` : `(#${ changeset . pr } )` ;
238- const prefixRegex = / ^ ( f e a t ! ? | f i x ! ? | d o c s ! ? | s t y l e ! ? | r e f a c t o r ! ? | p e r f ! ? | t e s t ! ? | b u i l d ! ? | c i ! ? | c h o r e ! ? | r e v e r t ! ? ) ( \( [ ^ ) ] + \) ) ? : / ;
239- const match = changeset . title . match ( prefixRegex ) ;
240- if ( match ) {
241- const prefix = changeset . title . substring ( 0 , match [ 0 ] . length ) ;
242- const restOfTitle = changeset . title . substring ( match [ 0 ] . length ) . trim ( ) ;
243- notes += `- **${ prefix } ** ${ restOfTitle } ${ prLink } - @${ changeset . author } \n` ;
244- } else {
245- notes += `- **${ changeset . title . replace ( / ^ [ ^ : ] + : \s * / i, '' ) } ** ${ prLink } - @${ changeset . author } \n` ;
246- }
205+ notes += `- ${ changeset . title } ${ prLink } - @${ changeset . author } \n` ;
247206 }
248-
249207 notes += `\n` ;
250208 }
251209
@@ -273,7 +231,6 @@ async function generateMarkdownReleaseNotes(changesets, repoUrl, token) {
273231 if ( contributors . size > 0 ) {
274232 notes += `## Contributors\n\n` ;
275233 notes += `Thanks to all the contributors who made this release possible!\n\n` ;
276-
277234 for ( const contributor of contributors ) {
278235 if ( firstTimeContributors . has ( contributor ) ) {
279236 notes += `- @${ contributor } 🎉 (First-time contributor)\n` ;
@@ -359,28 +316,22 @@ async function generateJsonReleaseNotes(changesets, repoUrl, token) {
359316async function generateReleaseNotes ( ) {
360317 // Get repository URL
361318 const repoUrl = await getRepoUrl ( ) ;
362-
363- // Get GitHub token
364319 const token = getGitHubToken ( ) ;
365320
366- // Read all changesets, filtering by branch if specified
321+ // Read changesets with branch filter if specified
367322 const changesets = await readChangesets ( { branch : argv . branch } ) ;
368323
369- // Log the number of changesets found
370- console . log ( `Found ${ changesets . length } changesets${ argv . branch ? ` for branch ${ argv . branch } ` : '' } .` ) ;
371-
372- // Generate release notes in the requested format
373324 if ( argv . format === 'json' ) {
374- const jsonNotes = await generateJsonReleaseNotes ( changesets , repoUrl , token ) ;
375- console . log ( jsonNotes ) ;
376- } else {
377- const markdownNotes = await generateMarkdownReleaseNotes ( changesets , repoUrl , token ) ;
378- console . log ( markdownNotes ) ;
325+ return generateJsonReleaseNotes ( changesets , repoUrl , token ) ;
379326 }
327+
328+ return generateMarkdownReleaseNotes ( changesets , repoUrl , token ) ;
380329}
381330
382- // Run the script
383- generateReleaseNotes ( ) . catch ( err => {
384- console . error ( 'Error generating release notes:' , err ) ;
385- process . exit ( 1 ) ;
386- } ) ;
331+ // Main execution
332+ generateReleaseNotes ( )
333+ . then ( notes => console . log ( notes ) )
334+ . catch ( error => {
335+ console . error ( 'Error generating release notes:' , error ) ;
336+ process . exit ( 1 ) ;
337+ } ) ;
0 commit comments