@@ -5,8 +5,10 @@ import { jest, describe, it } from '@jest/globals'
5
5
import * as td from 'testdouble'
6
6
import {
7
7
buildResponseCommit ,
8
+ createMergeGroupEventPayload ,
8
9
createPullRequestEventPayload ,
9
10
createPushEventPayload ,
11
+ updateMergeGroupEnvVars ,
10
12
updatePullRequestEnvVars ,
11
13
updatePushEnvVars ,
12
14
} from './testUtils.mjs'
@@ -952,4 +954,56 @@ describe('Commit Linter action', () => {
952
954
td . verify ( mockCore . setFailed ( contains ( incorrectCommit . message ) ) )
953
955
} )
954
956
} )
957
+
958
+ describe ( 'when handling merge_group event' , ( ) => {
959
+ beforeEach ( async ( ) => {
960
+ cwd = await git . bootstrap ( 'fixtures/conventional' , process . cwd ( ) )
961
+ td . when ( mockCore . getInput ( 'configFile' ) ) . thenReturn (
962
+ './commitlint.config.mjs' ,
963
+ )
964
+
965
+ td . replace ( process , 'cwd' , ( ) => cwd )
966
+ td . replace ( console , 'log' )
967
+ } )
968
+
969
+ it ( 'should lint the squashed commit message successfully' , async ( ) => {
970
+ const mergeGroupData = {
971
+ head_sha : 'merge-group-head-sha' ,
972
+ head_commit : {
973
+ id : 'merge-group-head-sha' ,
974
+ message : 'feat: add new feature\n\nThis is a detailed description.' ,
975
+ tree_id : 'tree-sha' ,
976
+ } ,
977
+ }
978
+
979
+ await createMergeGroupEventPayload ( cwd , mergeGroupData )
980
+ updateMergeGroupEnvVars ( cwd )
981
+
982
+ await runAction ( )
983
+
984
+ td . verify ( mockCore . setFailed ( ) , { times : 0 , ignoreExtraArgs : true } )
985
+ td . verify ( console . log ( 'Lint free! 🎉' ) )
986
+ } )
987
+
988
+ it ( 'should fail if the squashed commit message has linting errors' , async ( ) => {
989
+ const mergeGroupData = {
990
+ head_sha : 'merge-group-head-sha' ,
991
+ head_commit : {
992
+ id : 'merge-group-head-sha' ,
993
+ message : 'bad commit message' ,
994
+ tree_id : 'tree-sha' ,
995
+ } ,
996
+ }
997
+
998
+ await createMergeGroupEventPayload ( cwd , mergeGroupData )
999
+ updateMergeGroupEnvVars ( cwd )
1000
+
1001
+ await runAction ( )
1002
+
1003
+ td . verify (
1004
+ mockCore . setFailed ( contains ( 'You have commit messages with errors' ) ) ,
1005
+ )
1006
+ td . verify ( mockCore . setFailed ( contains ( 'bad commit message' ) ) )
1007
+ } )
1008
+ } )
955
1009
} )
0 commit comments