mirror of
https://github.com/wagoid/commitlint-github-action.git
synced 2025-11-07 08:06:54 +00:00
fix: getting events from first push using push event payload
This commit is contained in:
parent
af788c8486
commit
2831766869
2 changed files with 44 additions and 4 deletions
|
|
@ -12,6 +12,7 @@ const pullRequestTargetEvent = 'pull_request_target'
|
|||
const pullRequestEvents = [pullRequestEvent, pullRequestTargetEvent]
|
||||
|
||||
const { GITHUB_EVENT_NAME } = process.env
|
||||
const FIRST_COMMIT_SHA = '0000000000000000000000000000000000000000'
|
||||
|
||||
const configPath = resolve(process.env.GITHUB_WORKSPACE, getInput('configFile'))
|
||||
|
||||
|
|
@ -26,6 +27,14 @@ const getPushEventCommits = async () => {
|
|||
const octokit = getOctokit(getInput('token'))
|
||||
const { owner, repo } = eventContext.issue
|
||||
const { before, after } = eventContext.payload
|
||||
|
||||
if (before === FIRST_COMMIT_SHA) {
|
||||
return eventContext.payload.commits.map((commit) => ({
|
||||
message: commit.message,
|
||||
hash: commit.id,
|
||||
}))
|
||||
}
|
||||
|
||||
const { data: comparison } = await octokit.rest.repos.compareCommits({
|
||||
owner,
|
||||
repo,
|
||||
|
|
|
|||
|
|
@ -4,11 +4,11 @@ import { git } from '@commitlint/test'
|
|||
import { jest, describe, it } from '@jest/globals'
|
||||
import * as td from 'testdouble'
|
||||
import {
|
||||
updatePushEnvVars,
|
||||
createPushEventPayload,
|
||||
createPullRequestEventPayload,
|
||||
updatePullRequestEnvVars,
|
||||
buildResponseCommit,
|
||||
createPullRequestEventPayload,
|
||||
createPushEventPayload,
|
||||
updatePullRequestEnvVars,
|
||||
updatePushEnvVars,
|
||||
} from './testUtils.mjs'
|
||||
|
||||
const resultsOutputId = 'results'
|
||||
|
|
@ -451,6 +451,37 @@ describe('Commit Linter action', () => {
|
|||
td.verify(console.log('Lint free! 🎉'))
|
||||
})
|
||||
|
||||
it('should get commits from event for a first push', async () => {
|
||||
const commit = {
|
||||
id: '0000000000000000000000000000000000000000',
|
||||
message: 'chore: correct message',
|
||||
}
|
||||
|
||||
cwd = await git.bootstrap('fixtures/conventional', process.cwd())
|
||||
await createPushEventPayload(
|
||||
cwd,
|
||||
{ commits: [commit] },
|
||||
'0000000000000000000000000000000000000000',
|
||||
)
|
||||
updatePushEnvVars(cwd)
|
||||
td.when(
|
||||
mockCompareCommits({
|
||||
owner: 'wagoid',
|
||||
repo: 'commitlint-github-action',
|
||||
head: 'aaaaa',
|
||||
base: '0000000000000000000000000000000000000000',
|
||||
per_page: 100,
|
||||
}),
|
||||
).thenResolve({
|
||||
data: { commits: [buildResponseCommit(commit.id, commit.message)] },
|
||||
})
|
||||
td.replace(process, 'cwd', () => cwd)
|
||||
td.replace(console, 'log')
|
||||
|
||||
td.verify(mockCore.setFailed(), { times: 0, ignoreExtraArgs: true })
|
||||
td.verify(mockCompareCommits(), { times: 0 })
|
||||
})
|
||||
|
||||
describe.each(['pull_request', 'pull_request_target'])(
|
||||
'when there are multiple commits failing in the %s event',
|
||||
(eventName) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue