mirror of
https://github.com/wagoid/commitlint-github-action.git
synced 2025-11-07 08:06:54 +00:00
feat: add support for pull_request_target event
Previously, the action was treating pull_request_target event as a regular push, which was causing some issues.
This commit is contained in:
parent
ab798dde93
commit
de51303046
3 changed files with 71 additions and 61 deletions
|
|
@ -9,6 +9,8 @@ const gitCommits = require('./gitCommits')
|
|||
const generateOutputs = require('./generateOutputs')
|
||||
|
||||
const pullRequestEvent = 'pull_request'
|
||||
const pullRequestTargetEvent = 'pull_request_target'
|
||||
const pullRequestEvents = [pullRequestEvent, pullRequestTargetEvent]
|
||||
|
||||
const { GITHUB_EVENT_NAME, GITHUB_SHA } = process.env
|
||||
|
||||
|
|
@ -45,7 +47,8 @@ const getRangeForPushEvent = () => {
|
|||
}
|
||||
|
||||
const getRangeForEvent = async () => {
|
||||
if (GITHUB_EVENT_NAME !== pullRequestEvent) return getRangeForPushEvent()
|
||||
if (!pullRequestEvents.includes(GITHUB_EVENT_NAME))
|
||||
return getRangeForPushEvent()
|
||||
|
||||
const octokit = github.getOctokit(core.getInput('token'))
|
||||
const { owner, repo, number } = eventContext.issue
|
||||
|
|
|
|||
|
|
@ -261,20 +261,24 @@ describe('Commit Linter action', () => {
|
|||
td.verify(core.setFailed(contains('wrong commit from another branch')))
|
||||
})
|
||||
|
||||
describe('when there are multiple commits failing in the pull request', () => {
|
||||
describe.each(['pull_request', 'pull_request_target'])(
|
||||
'when there are multiple commits failing in the %s event',
|
||||
(eventName) => {
|
||||
let expectedResultsOutput
|
||||
const firstMessage = 'wrong message 1'
|
||||
const secondMessage = 'wrong message 2'
|
||||
|
||||
beforeEach(async () => {
|
||||
cwd = await git.bootstrap('fixtures/conventional')
|
||||
td.when(core.getInput('configFile')).thenReturn('./commitlint.config.js')
|
||||
td.when(core.getInput('configFile')).thenReturn(
|
||||
'./commitlint.config.js',
|
||||
)
|
||||
await gitEmptyCommit(cwd, 'message from before push')
|
||||
await gitEmptyCommit(cwd, firstMessage)
|
||||
await gitEmptyCommit(cwd, secondMessage)
|
||||
await createPullRequestEventPayload(cwd)
|
||||
const [, first, to] = await getCommitHashes(cwd)
|
||||
updatePullRequestEnvVars(cwd, to)
|
||||
updatePullRequestEnvVars(cwd, to, { eventName })
|
||||
td.when(
|
||||
listCommits({
|
||||
owner: 'wagoid',
|
||||
|
|
@ -329,7 +333,8 @@ describe('Commit Linter action', () => {
|
|||
|
||||
td.verify(core.setOutput(resultsOutputId, expectedResultsOutput))
|
||||
})
|
||||
})
|
||||
},
|
||||
)
|
||||
|
||||
describe('when it fails to fetch commits', () => {
|
||||
beforeEach(async () => {
|
||||
|
|
|
|||
|
|
@ -66,10 +66,12 @@ exports.createPullRequestEventPayload = async (cwd) => {
|
|||
await writeFile(eventPath, JSON.stringify(payload), 'utf8')
|
||||
}
|
||||
|
||||
exports.updatePullRequestEnvVars = (cwd, to) => {
|
||||
exports.updatePullRequestEnvVars = (cwd, to, options = {}) => {
|
||||
const { eventName = 'pull_request' } = options
|
||||
|
||||
updateEnvVars({
|
||||
GITHUB_WORKSPACE: cwd,
|
||||
GITHUB_EVENT_NAME: 'pull_request',
|
||||
GITHUB_EVENT_NAME: eventName,
|
||||
GITHUB_SHA: to,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue