Skip to content

Commit 2bf3b37

Browse files
authored
Merge pull request #747 from wagoid/fix/events-without-commits
fix: make sure action passes when event doesn't have commits fixes #746
2 parents 295fb24 + 6249453 commit 2bf3b37

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

src/action.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ const getPushEventCommits = () => {
3131
return mappedCommits
3232
}
3333

34-
const getEventCommits = async () => {
35-
if (!pullRequestEvents.includes(GITHUB_EVENT_NAME))
36-
return getPushEventCommits()
37-
34+
const getPullRequestEventCommits = async () => {
3835
const octokit = getOctokit(getInput('token'))
3936
const { owner, repo, number } = eventContext.issue
4037
const { data: commits } = await octokit.rest.pulls.listCommits({
@@ -50,6 +47,16 @@ const getEventCommits = async () => {
5047
}))
5148
}
5249

50+
const getEventCommits = async () => {
51+
if (pullRequestEvents.includes(GITHUB_EVENT_NAME)) {
52+
return getPullRequestEventCommits()
53+
}
54+
if (eventContext.payload.commits) {
55+
return getPushEventCommits()
56+
}
57+
return []
58+
}
59+
5360
function getOptsFromConfig(config) {
5461
return {
5562
parserOpts:

src/action.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,20 @@ describe('Commit Linter action', () => {
281281
)
282282
})
283283

284+
it('should pass when commits are not available', async () => {
285+
td.when(core.getInput('configFile')).thenReturn('./commitlint.config.js')
286+
cwd = await git.bootstrap('fixtures/conventional')
287+
await createPushEventPayload(cwd, {})
288+
updatePushEnvVars(cwd)
289+
td.replace(process, 'cwd', () => cwd)
290+
td.replace(console, 'log')
291+
292+
await runAction()
293+
294+
td.verify(core.setFailed(), { times: 0, ignoreExtraArgs: true })
295+
td.verify(console.log('Lint free! 🎉'))
296+
})
297+
284298
describe.each(['pull_request', 'pull_request_target'])(
285299
'when there are multiple commits failing in the %s event',
286300
(eventName) => {

0 commit comments

Comments
 (0)