mirror of
https://github.com/wagoid/commitlint-github-action.git
synced 2025-11-07 08:06:54 +00:00
test: merge_group event
This commit is contained in:
parent
fa634960b5
commit
08591292ae
2 changed files with 83 additions and 0 deletions
|
|
@ -5,8 +5,10 @@ import { jest, describe, it } from '@jest/globals'
|
|||
import * as td from 'testdouble'
|
||||
import {
|
||||
buildResponseCommit,
|
||||
createMergeGroupEventPayload,
|
||||
createPullRequestEventPayload,
|
||||
createPushEventPayload,
|
||||
updateMergeGroupEnvVars,
|
||||
updatePullRequestEnvVars,
|
||||
updatePushEnvVars,
|
||||
} from './testUtils.mjs'
|
||||
|
|
@ -952,4 +954,56 @@ describe('Commit Linter action', () => {
|
|||
td.verify(mockCore.setFailed(contains(incorrectCommit.message)))
|
||||
})
|
||||
})
|
||||
|
||||
describe('when handling merge_group event', () => {
|
||||
beforeEach(async () => {
|
||||
cwd = await git.bootstrap('fixtures/conventional', process.cwd())
|
||||
td.when(mockCore.getInput('configFile')).thenReturn(
|
||||
'./commitlint.config.mjs',
|
||||
)
|
||||
|
||||
td.replace(process, 'cwd', () => cwd)
|
||||
td.replace(console, 'log')
|
||||
})
|
||||
|
||||
it('should lint the squashed commit message successfully', async () => {
|
||||
const mergeGroupData = {
|
||||
head_sha: 'merge-group-head-sha',
|
||||
head_commit: {
|
||||
id: 'merge-group-head-sha',
|
||||
message: 'feat: add new feature\n\nThis is a detailed description.',
|
||||
tree_id: 'tree-sha',
|
||||
},
|
||||
}
|
||||
|
||||
await createMergeGroupEventPayload(cwd, mergeGroupData)
|
||||
updateMergeGroupEnvVars(cwd)
|
||||
|
||||
await runAction()
|
||||
|
||||
td.verify(mockCore.setFailed(), { times: 0, ignoreExtraArgs: true })
|
||||
td.verify(console.log('Lint free! 🎉'))
|
||||
})
|
||||
|
||||
it('should fail if the squashed commit message has linting errors', async () => {
|
||||
const mergeGroupData = {
|
||||
head_sha: 'merge-group-head-sha',
|
||||
head_commit: {
|
||||
id: 'merge-group-head-sha',
|
||||
message: 'bad commit message',
|
||||
tree_id: 'tree-sha',
|
||||
},
|
||||
}
|
||||
|
||||
await createMergeGroupEventPayload(cwd, mergeGroupData)
|
||||
updateMergeGroupEnvVars(cwd)
|
||||
|
||||
await runAction()
|
||||
|
||||
td.verify(
|
||||
mockCore.setFailed(contains('You have commit messages with errors')),
|
||||
)
|
||||
td.verify(mockCore.setFailed(contains('bad commit message')))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -77,3 +77,32 @@ export const buildResponseCommit = (sha, message) => ({
|
|||
message,
|
||||
},
|
||||
})
|
||||
|
||||
export const createMergeGroupEventPayload = async (cwd, mergeGroupData) => {
|
||||
const payload = {
|
||||
action: 'checks_requested',
|
||||
merge_group: mergeGroupData,
|
||||
repository: {
|
||||
owner: {
|
||||
login: 'wagoid',
|
||||
},
|
||||
name: 'commitlint-github-action',
|
||||
},
|
||||
}
|
||||
|
||||
const eventPath = path.join(cwd, 'mergeGroupEventPayload.json')
|
||||
|
||||
updateEnvVars({
|
||||
GITHUB_EVENT_PATH: eventPath,
|
||||
GITHUB_EVENT_NAME: 'merge_group',
|
||||
GITHUB_REPOSITORY: 'wagoid/commitlint-github-action',
|
||||
})
|
||||
await writeFile(eventPath, JSON.stringify(payload), 'utf8')
|
||||
}
|
||||
|
||||
export const updateMergeGroupEnvVars = (cwd) => {
|
||||
updateEnvVars({
|
||||
GITHUB_WORKSPACE: cwd,
|
||||
GITHUB_EVENT_NAME: 'merge_group',
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue