Skip to content

Commit edecd25

Browse files
committed
test: merge_group event
1 parent 73812a8 commit edecd25

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

src/action.test.mjs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import { jest, describe, it } from '@jest/globals'
55
import * as td from 'testdouble'
66
import {
77
buildResponseCommit,
8+
createMergeGroupEventPayload,
89
createPullRequestEventPayload,
910
createPushEventPayload,
11+
updateMergeGroupEnvVars,
1012
updatePullRequestEnvVars,
1113
updatePushEnvVars,
1214
} from './testUtils.mjs'
@@ -952,4 +954,56 @@ describe('Commit Linter action', () => {
952954
td.verify(mockCore.setFailed(contains(incorrectCommit.message)))
953955
})
954956
})
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+
})
9551009
})

src/testUtils.mjs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,32 @@ export const buildResponseCommit = (sha, message) => ({
7777
message,
7878
},
7979
})
80+
81+
export const createMergeGroupEventPayload = async (cwd, mergeGroupData) => {
82+
const payload = {
83+
action: 'checks_requested',
84+
merge_group: mergeGroupData,
85+
repository: {
86+
owner: {
87+
login: 'wagoid',
88+
},
89+
name: 'commitlint-github-action',
90+
},
91+
}
92+
93+
const eventPath = path.join(cwd, 'mergeGroupEventPayload.json')
94+
95+
updateEnvVars({
96+
GITHUB_EVENT_PATH: eventPath,
97+
GITHUB_EVENT_NAME: 'merge_group',
98+
GITHUB_REPOSITORY: 'wagoid/commitlint-github-action',
99+
})
100+
await writeFile(eventPath, JSON.stringify(payload), 'utf8')
101+
}
102+
103+
export const updateMergeGroupEnvVars = (cwd) => {
104+
updateEnvVars({
105+
GITHUB_WORKSPACE: cwd,
106+
GITHUB_EVENT_NAME: 'merge_group',
107+
})
108+
}

0 commit comments

Comments
 (0)