@@ -150,102 +150,60 @@ async function readChangesets(options = {}) {
150
150
return changesets . filter ( changeset => changeset . branch === branch ) ;
151
151
}
152
152
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 } ` ;
159
160
}
160
161
161
162
// Generate release notes in markdown format
162
163
async function generateMarkdownReleaseNotes ( changesets , repoUrl , token ) {
163
164
// Categorize changesets
164
165
const categories = categorizeChangesets ( changesets ) ;
165
166
166
- // Determine the appropriate version bump type
167
- const bumpType = determineBumpType ( changesets ) ;
168
-
169
167
// Start building the release notes
170
168
let notes = `` ;
171
169
172
170
// Add breaking changes section if there are any
173
171
if ( categories . breaking . length > 0 ) {
174
172
notes += `### Breaking Changes ⚠️\n\n` ;
175
-
176
173
for ( const changeset of categories . breaking ) {
177
174
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` ;
187
176
}
188
-
189
177
notes += `\n` ;
190
178
}
191
179
192
180
// Add features section if there are any
193
181
if ( categories . features . length > 0 ) {
194
182
notes += `### Features ✨\n\n` ;
195
-
196
183
for ( const changeset of categories . features ) {
197
184
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` ;
207
186
}
208
-
209
187
notes += `\n` ;
210
188
}
211
189
212
190
// Add fixes section if there are any
213
191
if ( categories . fixes . length > 0 ) {
214
192
notes += `### Fixes 🐛\n\n` ;
215
-
216
193
for ( const changeset of categories . fixes ) {
217
194
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` ;
227
196
}
228
-
229
197
notes += `\n` ;
230
198
}
231
199
232
200
// Add other changes section if there are any
233
201
if ( categories . other . length > 0 ) {
234
202
notes += `### Other Changes 🔄\n\n` ;
235
-
236
203
for ( const changeset of categories . other ) {
237
204
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` ;
247
206
}
248
-
249
207
notes += `\n` ;
250
208
}
251
209
@@ -273,7 +231,6 @@ async function generateMarkdownReleaseNotes(changesets, repoUrl, token) {
273
231
if ( contributors . size > 0 ) {
274
232
notes += `## Contributors\n\n` ;
275
233
notes += `Thanks to all the contributors who made this release possible!\n\n` ;
276
-
277
234
for ( const contributor of contributors ) {
278
235
if ( firstTimeContributors . has ( contributor ) ) {
279
236
notes += `- @${ contributor } 🎉 (First-time contributor)\n` ;
@@ -359,28 +316,22 @@ async function generateJsonReleaseNotes(changesets, repoUrl, token) {
359
316
async function generateReleaseNotes ( ) {
360
317
// Get repository URL
361
318
const repoUrl = await getRepoUrl ( ) ;
362
-
363
- // Get GitHub token
364
319
const token = getGitHubToken ( ) ;
365
320
366
- // Read all changesets, filtering by branch if specified
321
+ // Read changesets with branch filter if specified
367
322
const changesets = await readChangesets ( { branch : argv . branch } ) ;
368
323
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
373
324
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 ) ;
379
326
}
327
+
328
+ return generateMarkdownReleaseNotes ( changesets , repoUrl , token ) ;
380
329
}
381
330
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