Skip to content

Commit

Permalink
Merge pull request #747 from wagoid/fix/events-without-commits
Browse files Browse the repository at this point in the history
fix: make sure action passes when event doesn't have commits fixes #746
  • Loading branch information
wagoid committed Jul 23, 2023
2 parents 295fb24 + 6249453 commit 2bf3b37
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
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

0 comments on commit 2bf3b37

Please sign in to comment.