5
0
Fork 0
mirror of https://github.com/wagoid/commitlint-github-action.git synced 2025-11-07 08:06:54 +00:00

fix: make sure action passes when event doesn't have commits fixes #746

This commit is contained in:
Wagner Santos 2023-07-23 07:31:18 -03:00
parent 295fb249a8
commit 624945381b
2 changed files with 25 additions and 4 deletions

View file

@ -31,10 +31,7 @@ const getPushEventCommits = () => {
return mappedCommits return mappedCommits
} }
const getEventCommits = async () => { const getPullRequestEventCommits = async () => {
if (!pullRequestEvents.includes(GITHUB_EVENT_NAME))
return getPushEventCommits()
const octokit = getOctokit(getInput('token')) const octokit = getOctokit(getInput('token'))
const { owner, repo, number } = eventContext.issue const { owner, repo, number } = eventContext.issue
const { data: commits } = await octokit.rest.pulls.listCommits({ const { data: commits } = await octokit.rest.pulls.listCommits({
@ -50,6 +47,16 @@ const getEventCommits = async () => {
})) }))
} }
const getEventCommits = async () => {
if (pullRequestEvents.includes(GITHUB_EVENT_NAME)) {
return getPullRequestEventCommits()
}
if (eventContext.payload.commits) {
return getPushEventCommits()
}
return []
}
function getOptsFromConfig(config) { function getOptsFromConfig(config) {
return { return {
parserOpts: parserOpts:

View file

@ -281,6 +281,20 @@ describe('Commit Linter action', () => {
) )
}) })
it('should pass when commits are not available', async () => {
td.when(core.getInput('configFile')).thenReturn('./commitlint.config.js')
cwd = await git.bootstrap('fixtures/conventional')
await createPushEventPayload(cwd, {})
updatePushEnvVars(cwd)
td.replace(process, 'cwd', () => cwd)
td.replace(console, 'log')
await runAction()
td.verify(core.setFailed(), { times: 0, ignoreExtraArgs: true })
td.verify(console.log('Lint free! 🎉'))
})
describe.each(['pull_request', 'pull_request_target'])( describe.each(['pull_request', 'pull_request_target'])(
'when there are multiple commits failing in the %s event', 'when there are multiple commits failing in the %s event',
(eventName) => { (eventName) => {