mirror of
https://github.com/wagoid/commitlint-github-action.git
synced 2025-11-07 08:06:54 +00:00
Merge pull request #747 from wagoid/fix/events-without-commits
fix: make sure action passes when event doesn't have commits fixes #746
This commit is contained in:
commit
2bf3b3760a
2 changed files with 25 additions and 4 deletions
|
|
@ -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({
|
||||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue