@@ -86,20 +86,24 @@ export async function parseCommit(commit: string): Promise<Commit> {
86
86
const prNumberMatch = message . match ( / # ( \d + ) / ) ;
87
87
const prNumber = prNumberMatch ? parseInt ( prNumberMatch [ 1 ] , 10 ) : 0 ;
88
88
89
- // We skip generation commits as they do not appear in changelogs
90
- if ( isGeneratedCommit ( message ) ) {
91
- return {
92
- error : 'generation-commit' ,
93
- } ;
89
+ let commitType = typeAndScope ? typeAndScope [ 1 ] : 'fix' ; // default to fix.
90
+ if ( ! [ 'feat' , 'fix' , 'chore' ] . includes ( commitType ) ) {
91
+ commitType = 'fix' ;
94
92
}
95
93
96
94
// get the scope of the commit by checking the changes.
97
95
// any changes in the folder of a language will be scoped to that language
98
96
const diff = await getFileChanges ( hash ) ;
99
97
if ( ! diff ) {
98
+ // for empty commits, they will be filtered out later
100
99
return {
101
- error : 'missing-language-scope' ,
102
- message,
100
+ hash,
101
+ type : commitType as CommitType ,
102
+ languages : [ ] ,
103
+ scope : typeAndScope ? ( typeAndScope [ 2 ] as Scope ) : undefined ,
104
+ message : message . replace ( `(#${ prNumber } )` , '' ) . trim ( ) ,
105
+ prNumber,
106
+ author : fetchedUsers [ authorEmail ] ,
103
107
} ;
104
108
}
105
109
@@ -111,9 +115,11 @@ export async function parseCommit(commit: string): Promise<Commit> {
111
115
}
112
116
}
113
117
114
- if ( languageScopes . size === 0 ) {
118
+ // for generated commits, we just report the languages so that the changes are attributed to the correct language and commit
119
+ if ( isGeneratedCommit ( message ) ) {
115
120
return {
116
- error : 'missing-language-scope' ,
121
+ generated : true ,
122
+ languages : [ ...languageScopes ] as Language [ ] ,
117
123
message,
118
124
} ;
119
125
}
@@ -132,11 +138,6 @@ export async function parseCommit(commit: string): Promise<Commit> {
132
138
}
133
139
}
134
140
135
- let commitType = typeAndScope ? typeAndScope [ 1 ] : 'fix' ; // default to fix.
136
- if ( ! [ 'feat' , 'fix' , 'chore' ] . includes ( commitType ) ) {
137
- commitType = 'fix' ;
138
- }
139
-
140
141
return {
141
142
hash,
142
143
type : commitType as CommitType , // `fix` | `feat` | `chore` | ..., default to `fix`
@@ -246,19 +247,23 @@ async function getCommits(force?: boolean): Promise<{
246
247
skippedCommits : string ;
247
248
} > {
248
249
// Reading commits since last release
249
- const latestCommits = ( await run ( `git log --pretty=format:"%h|%ae|%s" ${ await getLastReleasedTag ( ) } ..${ MAIN_BRANCH } ` ) )
250
+ const latestCommits = (
251
+ await run ( `git log --reverse --pretty=format:"%h|%ae|%s" ${ await getLastReleasedTag ( ) } ..${ MAIN_BRANCH } ` )
252
+ )
250
253
. split ( '\n' )
251
254
. filter ( Boolean ) ;
252
255
253
- const commitsWithoutLanguageScope : string [ ] = [ ] ;
254
- const validCommits : ParsedCommit [ ] = [ ] ;
256
+ let validCommits : ParsedCommit [ ] = [ ] ;
255
257
256
258
for ( const commitMessage of latestCommits ) {
257
259
const commit = await parseCommit ( commitMessage ) ;
258
260
259
- if ( 'error' in commit ) {
260
- if ( commit . error === 'missing-language-scope' ) {
261
- commitsWithoutLanguageScope . push ( commit . message ) ;
261
+ if ( 'generated' in commit ) {
262
+ const originalCommit = validCommits . findIndex ( ( c ) => commit . message . includes ( c . message ) ) ;
263
+ if ( originalCommit !== - 1 ) {
264
+ validCommits [ originalCommit ] . languages = [
265
+ ...new Set ( [ ...validCommits [ originalCommit ] . languages , ...commit . languages ] ) ,
266
+ ] ;
262
267
}
263
268
264
269
continue ;
@@ -267,6 +272,12 @@ async function getCommits(force?: boolean): Promise<{
267
272
validCommits . push ( commit ) ;
268
273
}
269
274
275
+ // redo a pass to filter out commits without language scope
276
+ const commitsWithoutLanguageScope = validCommits
277
+ . filter ( ( commit ) => commit . languages . length === 0 )
278
+ . map ( ( commit ) => commit . message ) ;
279
+ validCommits = validCommits . filter ( ( commit ) => commit . languages . length > 0 ) ;
280
+
270
281
if ( ! force && validCommits . length === 0 ) {
271
282
console . log (
272
283
chalk . black . bgYellow ( '[INFO]' ) ,
@@ -351,7 +362,7 @@ export async function createReleasePR({
351
362
352
363
// sometimes the scope of the commits is not set correctly and concerns another language, we can fix it.
353
364
if ( LANGUAGES . includes ( validCommit . scope as Language ) && validCommit . scope !== lang ) {
354
- validCommit . message = validCommit . message . replace ( `(${ validCommit . scope } ):` , `( ${ lang } ):` ) ;
365
+ validCommit . message = validCommit . message . replace ( `(${ validCommit . scope } ):` , '(clients):' ) ;
355
366
}
356
367
357
368
const changelogCommit = [
0 commit comments