File tree 4 files changed +40
-7
lines changed 4 files changed +40
-7
lines changed Original file line number Diff line number Diff line change 1
1
import { LANGUAGES } from '../../../common' ;
2
2
import { decideWhereToSpread , cleanUpCommitMessage } from '../spreadGeneration' ;
3
+ import text from '../text' ;
3
4
4
5
describe ( 'spread generation' , ( ) => {
5
6
it ( 'skips in case of release commit' , ( ) => {
@@ -45,4 +46,13 @@ describe('spread generation', () => {
45
46
https://github.com/algolia/api-clients-automation/pull/200"
46
47
` ) ;
47
48
} ) ;
49
+
50
+ it ( 'provides a link to the automation repo for commit with hash' , ( ) => {
51
+ const commitMessage = `${ text . commitStartMessage } ed33e02f3e45fd72b4f420a56e4be7c6929fca9f. [skip ci]` ;
52
+ expect ( cleanUpCommitMessage ( commitMessage ) ) . toMatchInlineSnapshot ( `
53
+ "chore: generated code for commit ed33e02f. [skip ci]
54
+
55
+ https://github.com/algolia/api-clients-automation/commit/ed33e02f3e45fd72b4f420a56e4be7c6929fca9f"
56
+ ` ) ;
57
+ } ) ;
48
58
} ) ;
Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ import { MAIN_BRANCH, run } from '../../common';
3
3
import { configureGitHubAuthor } from '../../release/common' ;
4
4
import { getNbGitDiff } from '../utils' ;
5
5
6
+ import text from './text' ;
7
+
6
8
const PR_NUMBER = parseInt ( process . env . PR_NUMBER || '0' , 10 ) ;
7
9
const FOLDERS_TO_CHECK = 'yarn.lock openapitools.json clients specs/bundled' ;
8
10
@@ -48,10 +50,9 @@ export async function pushGeneratedCode(): Promise<void> {
48
50
await run ( `git checkout -b ${ branchToPush } ` ) ;
49
51
}
50
52
51
- const commitMessage =
52
- await run ( `git show -s ${ baseBranch } --format="chore: generated code for commit %H. ${
53
- isMainBranch ? '[skip ci]' : ''
54
- }
53
+ const commitMessage = await run ( `git show -s ${ baseBranch } --format="${
54
+ text . commitStartMessage
55
+ } %H. ${ isMainBranch ? '[skip ci]' : '' }
55
56
56
57
Co-authored-by: %an <%ae>
57
58
%(trailers:key=Co-authored-by)"` ) ;
Original file line number Diff line number Diff line change @@ -13,6 +13,8 @@ import { getLanguageFolder } from '../../config';
13
13
import { cloneRepository , configureGitHubAuthor } from '../../release/common' ;
14
14
import { getNbGitDiff } from '../utils' ;
15
15
16
+ import text from './text' ;
17
+
16
18
export function decideWhereToSpread ( commitMessage : string ) : string [ ] {
17
19
if ( commitMessage . startsWith ( 'chore: release' ) ) {
18
20
return [ ] ;
@@ -29,12 +31,31 @@ export function decideWhereToSpread(commitMessage: string): string[] {
29
31
}
30
32
31
33
export function cleanUpCommitMessage ( commitMessage : string ) : string {
32
- const result = commitMessage . match ( / ( .+ ) \s \( # ( \d + ) \) $ / ) ;
33
- if ( ! result ) {
34
+ const isCodeGenCommit = commitMessage . startsWith ( text . commitStartMessage ) ;
35
+
36
+ if ( isCodeGenCommit ) {
37
+ const hash = commitMessage
38
+ . split ( text . commitStartMessage ) [ 1 ]
39
+ . replace ( '. [skip ci]' , '' )
40
+ . trim ( ) ;
41
+
42
+ if ( ! hash ) {
43
+ return commitMessage ;
44
+ }
45
+
46
+ return [
47
+ `${ text . commitStartMessage } ${ hash . substring ( 0 , 8 ) } . [skip ci]` ,
48
+ `${ REPO_URL } /commit/${ hash } ` ,
49
+ ] . join ( '\n\n' ) ;
50
+ }
51
+
52
+ const prCommit = commitMessage . match ( / ( .+ ) \s \( # ( \d + ) \) $ / ) ;
53
+
54
+ if ( ! prCommit ) {
34
55
return commitMessage ;
35
56
}
36
57
37
- return [ result [ 1 ] , `${ REPO_URL } /pull/${ result [ 2 ] } ` ] . join ( '\n\n' ) ;
58
+ return [ prCommit [ 1 ] , `${ REPO_URL } /pull/${ prCommit [ 2 ] } ` ] . join ( '\n\n' ) ;
38
59
}
39
60
40
61
async function spreadGeneration ( ) : Promise < void > {
Original file line number Diff line number Diff line change 1
1
import { MAIN_BRANCH , REPO_URL } from '../../common' ;
2
2
3
3
export default {
4
+ commitStartMessage : 'chore: generated code for commit' ,
4
5
notification : {
5
6
header : '### 🔨 The codegen job will run at the end of the CI.' ,
6
7
body : '_Make sure your last commit does not contains generated code, it will be automatically pushed by our CI._' ,
You can’t perform that action at this time.
0 commit comments