@@ -86,20 +86,24 @@ export async function parseCommit(commit: string): Promise<Commit> {
8686 const prNumberMatch = message . match ( / # ( \d + ) / ) ;
8787 const prNumber = prNumberMatch ? parseInt ( prNumberMatch [ 1 ] , 10 ) : 0 ;
8888
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' ;
9492 }
9593
9694 // get the scope of the commit by checking the changes.
9795 // any changes in the folder of a language will be scoped to that language
9896 const diff = await getFileChanges ( hash ) ;
9997 if ( ! diff ) {
98+ // for empty commits, they will be filtered out later
10099 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 ] ,
103107 } ;
104108 }
105109
@@ -111,9 +115,11 @@ export async function parseCommit(commit: string): Promise<Commit> {
111115 }
112116 }
113117
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 ) ) {
115120 return {
116- error : 'missing-language-scope' ,
121+ generated : true ,
122+ languages : [ ...languageScopes ] as Language [ ] ,
117123 message,
118124 } ;
119125 }
@@ -132,11 +138,6 @@ export async function parseCommit(commit: string): Promise<Commit> {
132138 }
133139 }
134140
135- let commitType = typeAndScope ? typeAndScope [ 1 ] : 'fix' ; // default to fix.
136- if ( ! [ 'feat' , 'fix' , 'chore' ] . includes ( commitType ) ) {
137- commitType = 'fix' ;
138- }
139-
140141 return {
141142 hash,
142143 type : commitType as CommitType , // `fix` | `feat` | `chore` | ..., default to `fix`
@@ -246,19 +247,23 @@ async function getCommits(force?: boolean): Promise<{
246247 skippedCommits : string ;
247248} > {
248249 // 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+ )
250253 . split ( '\n' )
251254 . filter ( Boolean ) ;
252255
253- const commitsWithoutLanguageScope : string [ ] = [ ] ;
254- const validCommits : ParsedCommit [ ] = [ ] ;
256+ let validCommits : ParsedCommit [ ] = [ ] ;
255257
256258 for ( const commitMessage of latestCommits ) {
257259 const commit = await parseCommit ( commitMessage ) ;
258260
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+ ] ;
262267 }
263268
264269 continue ;
@@ -267,6 +272,12 @@ async function getCommits(force?: boolean): Promise<{
267272 validCommits . push ( commit ) ;
268273 }
269274
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+
270281 if ( ! force && validCommits . length === 0 ) {
271282 console . log (
272283 chalk . black . bgYellow ( '[INFO]' ) ,
@@ -351,7 +362,7 @@ export async function createReleasePR({
351362
352363 // sometimes the scope of the commits is not set correctly and concerns another language, we can fix it.
353364 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):' ) ;
355366 }
356367
357368 const changelogCommit = [
0 commit comments