Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ const getPushEventCommits = () => {
return mappedCommits
}

const getEventCommits = async () => {
if (!pullRequestEvents.includes(GITHUB_EVENT_NAME))
return getPushEventCommits()

const getPullRequestEventCommits = async () => {
const octokit = getOctokit(getInput('token'))
const { owner, repo, number } = eventContext.issue
const { data: commits } = await octokit.rest.pulls.listCommits({
Expand All @@ -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) {
return {
parserOpts:
Expand Down
14 changes: 14 additions & 0 deletions src/action.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'])(
'when there are multiple commits failing in the %s event',
(eventName) => {
Expand Down