mirror of
https://github.com/wagoid/commitlint-github-action.git
synced 2025-11-07 08:06:54 +00:00
Revert "feat: updating push event trigger to use rest API (OctoKit) vs push event"
This commit is contained in:
parent
dbd4ecd47d
commit
09a8abb757
3 changed files with 124 additions and 260 deletions
|
|
@ -22,21 +22,13 @@ const getCommitDepth = () => {
|
||||||
return Number.isNaN(commitDepth) ? null : Math.max(commitDepth, 0)
|
return Number.isNaN(commitDepth) ? null : Math.max(commitDepth, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
const getPushEventCommits = async () => {
|
const getPushEventCommits = () => {
|
||||||
const octokit = getOctokit(getInput('token'))
|
const mappedCommits = eventContext.payload.commits.map((commit) => ({
|
||||||
const { owner, repo } = eventContext.issue
|
message: commit.message,
|
||||||
const { before } = eventContext.payload
|
hash: commit.id,
|
||||||
const { data: commits } = await octokit.rest.repos.listCommits({
|
|
||||||
owner,
|
|
||||||
repo,
|
|
||||||
sha: before,
|
|
||||||
per_page: 100,
|
|
||||||
})
|
|
||||||
|
|
||||||
return commits.map((commit) => ({
|
|
||||||
message: commit.commit.message,
|
|
||||||
hash: commit.sha,
|
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
return mappedCommits
|
||||||
}
|
}
|
||||||
|
|
||||||
const getPullRequestEventCommits = async () => {
|
const getPullRequestEventCommits = async () => {
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,7 @@ const {
|
||||||
|
|
||||||
const initialEnv = { ...process.env }
|
const initialEnv = { ...process.env }
|
||||||
|
|
||||||
const mockListPullCommits = td.func('listCommits')
|
const mockListCommits = td.func('listCommits')
|
||||||
const mockListPushCommits = td.func('listCommits')
|
|
||||||
|
|
||||||
const mockCore = td.object(['getInput', 'setFailed', 'setOutput'])
|
const mockCore = td.object(['getInput', 'setFailed', 'setOutput'])
|
||||||
|
|
||||||
|
|
@ -31,10 +30,7 @@ jest.unstable_mockModule('@actions/github', () => {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.rest = {
|
this.rest = {
|
||||||
pulls: {
|
pulls: {
|
||||||
listCommits: mockListPullCommits,
|
listCommits: mockListCommits,
|
||||||
},
|
|
||||||
repos: {
|
|
||||||
listCommits: mockListPushCommits,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -76,18 +72,15 @@ describe('Commit Linter action', () => {
|
||||||
'./not-existing-config.mjs',
|
'./not-existing-config.mjs',
|
||||||
)
|
)
|
||||||
cwd = await git.bootstrap('fixtures/conventional', process.cwd())
|
cwd = await git.bootstrap('fixtures/conventional', process.cwd())
|
||||||
await createPushEventPayload(cwd)
|
await createPushEventPayload(cwd, {
|
||||||
updatePushEnvVars(cwd)
|
commits: [
|
||||||
td.when(
|
{
|
||||||
mockListPushCommits({
|
id: 'wrong-message',
|
||||||
owner: 'wagoid',
|
message: 'wrong message',
|
||||||
repo: 'commitlint-github-action',
|
},
|
||||||
per_page: 100,
|
],
|
||||||
sha: '00000',
|
|
||||||
}),
|
|
||||||
).thenResolve({
|
|
||||||
data: [buildResponseCommit('wrong-message', 'wrong message')],
|
|
||||||
})
|
})
|
||||||
|
updatePushEnvVars(cwd)
|
||||||
td.replace(process, 'cwd', () => cwd)
|
td.replace(process, 'cwd', () => cwd)
|
||||||
|
|
||||||
await runAction()
|
await runAction()
|
||||||
|
|
@ -109,18 +102,15 @@ describe('Commit Linter action', () => {
|
||||||
'./commitlint.config.js',
|
'./commitlint.config.js',
|
||||||
)
|
)
|
||||||
cwd = await git.bootstrap('fixtures/conventional', process.cwd())
|
cwd = await git.bootstrap('fixtures/conventional', process.cwd())
|
||||||
await createPushEventPayload(cwd)
|
await createPushEventPayload(cwd, {
|
||||||
updatePushEnvVars(cwd)
|
commits: [
|
||||||
td.when(
|
{
|
||||||
mockListPushCommits({
|
id: 'wrong-message',
|
||||||
owner: 'wagoid',
|
message: 'wrong message',
|
||||||
repo: 'commitlint-github-action',
|
},
|
||||||
per_page: 100,
|
],
|
||||||
sha: '00000',
|
|
||||||
}),
|
|
||||||
).thenResolve({
|
|
||||||
data: [buildResponseCommit('wrong-message', 'wrong message')],
|
|
||||||
})
|
})
|
||||||
|
updatePushEnvVars(cwd)
|
||||||
td.replace(process, 'cwd', () => cwd)
|
td.replace(process, 'cwd', () => cwd)
|
||||||
|
|
||||||
await runAction()
|
await runAction()
|
||||||
|
|
@ -130,19 +120,15 @@ describe('Commit Linter action', () => {
|
||||||
|
|
||||||
it('should fail for single push with incorrect message', async () => {
|
it('should fail for single push with incorrect message', async () => {
|
||||||
cwd = await git.bootstrap('fixtures/conventional', process.cwd())
|
cwd = await git.bootstrap('fixtures/conventional', process.cwd())
|
||||||
await createPushEventPayload(cwd)
|
await createPushEventPayload(cwd, {
|
||||||
updatePushEnvVars(cwd)
|
commits: [
|
||||||
td.when(
|
{
|
||||||
mockListPushCommits({
|
id: 'wrong-message',
|
||||||
owner: 'wagoid',
|
message: 'wrong message',
|
||||||
repo: 'commitlint-github-action',
|
},
|
||||||
per_page: 100,
|
],
|
||||||
sha: '00000',
|
|
||||||
}),
|
|
||||||
).thenResolve({
|
|
||||||
data: [buildResponseCommit('wrong-message', 'wrong message')],
|
|
||||||
})
|
})
|
||||||
|
updatePushEnvVars(cwd)
|
||||||
td.replace(process, 'cwd', () => cwd)
|
td.replace(process, 'cwd', () => cwd)
|
||||||
|
|
||||||
await runAction()
|
await runAction()
|
||||||
|
|
@ -154,21 +140,19 @@ describe('Commit Linter action', () => {
|
||||||
|
|
||||||
it('should fail for push range with wrong messages', async () => {
|
it('should fail for push range with wrong messages', async () => {
|
||||||
cwd = await git.bootstrap('fixtures/conventional', process.cwd())
|
cwd = await git.bootstrap('fixtures/conventional', process.cwd())
|
||||||
await createPushEventPayload(cwd)
|
await createPushEventPayload(cwd, {
|
||||||
updatePushEnvVars(cwd)
|
commits: [
|
||||||
td.when(
|
{
|
||||||
mockListPushCommits({
|
id: 'wrong-message-1',
|
||||||
owner: 'wagoid',
|
message: 'wrong message 1',
|
||||||
repo: 'commitlint-github-action',
|
},
|
||||||
per_page: 100,
|
{
|
||||||
sha: '00000',
|
id: 'wrong-message-2',
|
||||||
}),
|
message: 'wrong message 2',
|
||||||
).thenResolve({
|
},
|
||||||
data: [
|
|
||||||
buildResponseCommit('wrong-message-1', 'wrong message 1'),
|
|
||||||
buildResponseCommit('wrong-message-2', 'wrong message 2'),
|
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
updatePushEnvVars(cwd)
|
||||||
td.replace(process, 'cwd', () => cwd)
|
td.replace(process, 'cwd', () => cwd)
|
||||||
|
|
||||||
await runAction()
|
await runAction()
|
||||||
|
|
@ -179,21 +163,19 @@ describe('Commit Linter action', () => {
|
||||||
it('should pass for push range with wrong messages with failOnErrors set to false', async () => {
|
it('should pass for push range with wrong messages with failOnErrors set to false', async () => {
|
||||||
td.when(mockCore.getInput('failOnErrors')).thenReturn('false')
|
td.when(mockCore.getInput('failOnErrors')).thenReturn('false')
|
||||||
cwd = await git.bootstrap('fixtures/conventional', process.cwd())
|
cwd = await git.bootstrap('fixtures/conventional', process.cwd())
|
||||||
await createPushEventPayload(cwd)
|
await createPushEventPayload(cwd, {
|
||||||
updatePushEnvVars(cwd)
|
commits: [
|
||||||
td.when(
|
{
|
||||||
mockListPushCommits({
|
id: 'wrong-message-1',
|
||||||
owner: 'wagoid',
|
message: 'wrong message 1',
|
||||||
repo: 'commitlint-github-action',
|
},
|
||||||
per_page: 100,
|
{
|
||||||
sha: '00000',
|
id: 'wrong-message-2',
|
||||||
}),
|
message: 'wrong message 2',
|
||||||
).thenResolve({
|
},
|
||||||
data: [
|
|
||||||
buildResponseCommit('wrong-message-1', 'wrong message 1'),
|
|
||||||
buildResponseCommit('wrong-message-2', 'wrong message 2'),
|
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
updatePushEnvVars(cwd)
|
||||||
td.replace(process, 'cwd', () => cwd)
|
td.replace(process, 'cwd', () => cwd)
|
||||||
td.replace(console, 'log')
|
td.replace(console, 'log')
|
||||||
|
|
||||||
|
|
@ -208,21 +190,19 @@ describe('Commit Linter action', () => {
|
||||||
it('should pass for push range with correct messages with failOnErrors set to false', async () => {
|
it('should pass for push range with correct messages with failOnErrors set to false', async () => {
|
||||||
td.when(mockCore.getInput('failOnErrors')).thenReturn('false')
|
td.when(mockCore.getInput('failOnErrors')).thenReturn('false')
|
||||||
cwd = await git.bootstrap('fixtures/conventional', process.cwd())
|
cwd = await git.bootstrap('fixtures/conventional', process.cwd())
|
||||||
await createPushEventPayload(cwd)
|
await createPushEventPayload(cwd, {
|
||||||
updatePushEnvVars(cwd)
|
commits: [
|
||||||
td.when(
|
{
|
||||||
mockListPushCommits({
|
id: 'correct-message-1',
|
||||||
owner: 'wagoid',
|
message: 'chore: correct message 1',
|
||||||
repo: 'commitlint-github-action',
|
},
|
||||||
per_page: 100,
|
{
|
||||||
sha: '00000',
|
id: 'correct-message-2',
|
||||||
}),
|
message: 'chore: correct message 2',
|
||||||
).thenResolve({
|
},
|
||||||
data: [
|
|
||||||
buildResponseCommit('correct-message-1', 'chore: correct message 1'),
|
|
||||||
buildResponseCommit('correct-message-2', 'chore: correct message 2'),
|
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
updatePushEnvVars(cwd)
|
||||||
td.replace(process, 'cwd', () => cwd)
|
td.replace(process, 'cwd', () => cwd)
|
||||||
td.replace(console, 'log')
|
td.replace(console, 'log')
|
||||||
|
|
||||||
|
|
@ -234,21 +214,19 @@ describe('Commit Linter action', () => {
|
||||||
|
|
||||||
it('should pass for push range with correct messages', async () => {
|
it('should pass for push range with correct messages', async () => {
|
||||||
cwd = await git.bootstrap('fixtures/conventional', process.cwd())
|
cwd = await git.bootstrap('fixtures/conventional', process.cwd())
|
||||||
await createPushEventPayload(cwd)
|
await createPushEventPayload(cwd, {
|
||||||
updatePushEnvVars(cwd)
|
commits: [
|
||||||
td.when(
|
{
|
||||||
mockListPushCommits({
|
id: 'correct-message-1',
|
||||||
owner: 'wagoid',
|
message: 'chore: correct message 1',
|
||||||
repo: 'commitlint-github-action',
|
},
|
||||||
per_page: 100,
|
{
|
||||||
sha: '00000',
|
id: 'correct-message-2',
|
||||||
}),
|
message: 'chore: correct message 2',
|
||||||
).thenResolve({
|
},
|
||||||
data: [
|
|
||||||
buildResponseCommit('correct-message-1', 'chore: correct message 1'),
|
|
||||||
buildResponseCommit('correct-message-2', 'chore: correct message 2'),
|
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
updatePushEnvVars(cwd)
|
||||||
td.replace(process, 'cwd', () => cwd)
|
td.replace(process, 'cwd', () => cwd)
|
||||||
td.replace(console, 'log')
|
td.replace(console, 'log')
|
||||||
|
|
||||||
|
|
@ -263,23 +241,14 @@ describe('Commit Linter action', () => {
|
||||||
td.when(mockCore.getInput('configFile')).thenReturn(
|
td.when(mockCore.getInput('configFile')).thenReturn(
|
||||||
'./commitlint.config.yml',
|
'./commitlint.config.yml',
|
||||||
)
|
)
|
||||||
await createPushEventPayload(cwd)
|
await createPushEventPayload(cwd, {
|
||||||
updatePushEnvVars(cwd)
|
commits: [
|
||||||
td.when(
|
{
|
||||||
mockListPushCommits({
|
message: 'chore(wrong): not including package scope',
|
||||||
owner: 'wagoid',
|
},
|
||||||
repo: 'commitlint-github-action',
|
|
||||||
per_page: 100,
|
|
||||||
sha: '00000',
|
|
||||||
}),
|
|
||||||
).thenResolve({
|
|
||||||
data: [
|
|
||||||
buildResponseCommit(
|
|
||||||
'correct-message',
|
|
||||||
'chore(wrong): not including package scope',
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
updatePushEnvVars(cwd)
|
||||||
td.replace(process, 'cwd', () => cwd)
|
td.replace(process, 'cwd', () => cwd)
|
||||||
|
|
||||||
await runAction()
|
await runAction()
|
||||||
|
|
@ -294,23 +263,15 @@ describe('Commit Linter action', () => {
|
||||||
td.when(mockCore.getInput('configFile')).thenReturn(
|
td.when(mockCore.getInput('configFile')).thenReturn(
|
||||||
'./commitlint.config.yml',
|
'./commitlint.config.yml',
|
||||||
)
|
)
|
||||||
await createPushEventPayload(cwd)
|
await createPushEventPayload(cwd, {
|
||||||
updatePushEnvVars(cwd)
|
commits: [
|
||||||
td.when(
|
{
|
||||||
mockListPushCommits({
|
id: 'correct-message',
|
||||||
owner: 'wagoid',
|
message: 'chore(second-package): this works',
|
||||||
repo: 'commitlint-github-action',
|
},
|
||||||
per_page: 100,
|
|
||||||
sha: '00000',
|
|
||||||
}),
|
|
||||||
).thenResolve({
|
|
||||||
data: [
|
|
||||||
buildResponseCommit(
|
|
||||||
'correct-message',
|
|
||||||
'chore(second-package): this works',
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
updatePushEnvVars(cwd)
|
||||||
td.replace(process, 'cwd', () => cwd)
|
td.replace(process, 'cwd', () => cwd)
|
||||||
td.replace(console, 'log')
|
td.replace(console, 'log')
|
||||||
|
|
||||||
|
|
@ -324,20 +285,12 @@ describe('Commit Linter action', () => {
|
||||||
td.when(mockCore.getInput('configFile')).thenReturn(
|
td.when(mockCore.getInput('configFile')).thenReturn(
|
||||||
'./commitlint.config.mjs',
|
'./commitlint.config.mjs',
|
||||||
)
|
)
|
||||||
await createPushEventPayload(cwd)
|
await createPushEventPayload(cwd, {
|
||||||
td.when(
|
commits: [
|
||||||
mockListPushCommits({
|
{
|
||||||
owner: 'wagoid',
|
id: 'wrong-message',
|
||||||
repo: 'commitlint-github-action',
|
message: 'ib-21212121212121: without jira ticket',
|
||||||
per_page: 100,
|
},
|
||||||
sha: '00000',
|
|
||||||
}),
|
|
||||||
).thenResolve({
|
|
||||||
data: [
|
|
||||||
buildResponseCommit(
|
|
||||||
'wrong-message',
|
|
||||||
'ib-21212121212121: without jira ticket',
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
updatePushEnvVars(cwd)
|
updatePushEnvVars(cwd)
|
||||||
|
|
@ -372,18 +325,8 @@ describe('Commit Linter action', () => {
|
||||||
'./commitlint.config.mjs',
|
'./commitlint.config.mjs',
|
||||||
)
|
)
|
||||||
cwd = await git.bootstrap('fixtures/conventional', process.cwd())
|
cwd = await git.bootstrap('fixtures/conventional', process.cwd())
|
||||||
await createPushEventPayload(cwd, { commits: [] }, '12345')
|
await createPushEventPayload(cwd, {})
|
||||||
updatePushEnvVars(cwd)
|
updatePushEnvVars(cwd)
|
||||||
td.when(
|
|
||||||
mockListPushCommits({
|
|
||||||
owner: 'wagoid',
|
|
||||||
repo: 'commitlint-github-action',
|
|
||||||
per_page: 100,
|
|
||||||
sha: '12345',
|
|
||||||
}),
|
|
||||||
).thenResolve({
|
|
||||||
data: [],
|
|
||||||
})
|
|
||||||
td.replace(process, 'cwd', () => cwd)
|
td.replace(process, 'cwd', () => cwd)
|
||||||
td.replace(console, 'log')
|
td.replace(console, 'log')
|
||||||
|
|
||||||
|
|
@ -411,7 +354,7 @@ describe('Commit Linter action', () => {
|
||||||
await createPullRequestEventPayload(cwd)
|
await createPullRequestEventPayload(cwd)
|
||||||
updatePullRequestEnvVars(cwd, { eventName })
|
updatePullRequestEnvVars(cwd, { eventName })
|
||||||
td.when(
|
td.when(
|
||||||
mockListPullCommits({
|
mockListCommits({
|
||||||
owner: 'wagoid',
|
owner: 'wagoid',
|
||||||
repo: 'commitlint-github-action',
|
repo: 'commitlint-github-action',
|
||||||
pull_number: '1',
|
pull_number: '1',
|
||||||
|
|
@ -477,7 +420,7 @@ describe('Commit Linter action', () => {
|
||||||
await createPullRequestEventPayload(cwd)
|
await createPullRequestEventPayload(cwd)
|
||||||
updatePullRequestEnvVars(cwd)
|
updatePullRequestEnvVars(cwd)
|
||||||
td.when(
|
td.when(
|
||||||
mockListPullCommits({
|
mockListCommits({
|
||||||
owner: 'wagoid',
|
owner: 'wagoid',
|
||||||
repo: 'commitlint-github-action',
|
repo: 'commitlint-github-action',
|
||||||
pull_number: '1',
|
pull_number: '1',
|
||||||
|
|
@ -505,25 +448,15 @@ describe('Commit Linter action', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("when there's a single commit with correct message", () => {
|
describe("when there's a single commit with correct message", () => {
|
||||||
const commit = buildResponseCommit(
|
const commit = {
|
||||||
'correct-commit',
|
id: 'correct-message',
|
||||||
'chore: correct message',
|
message: 'chore: correct message',
|
||||||
)
|
}
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
cwd = await git.bootstrap('fixtures/conventional', process.cwd())
|
cwd = await git.bootstrap('fixtures/conventional', process.cwd())
|
||||||
await createPushEventPayload(cwd)
|
await createPushEventPayload(cwd, { commits: [commit] })
|
||||||
updatePushEnvVars(cwd)
|
updatePushEnvVars(cwd)
|
||||||
td.when(
|
|
||||||
mockListPushCommits({
|
|
||||||
owner: 'wagoid',
|
|
||||||
repo: 'commitlint-github-action',
|
|
||||||
per_page: 100,
|
|
||||||
sha: '00000',
|
|
||||||
}),
|
|
||||||
).thenResolve({
|
|
||||||
data: [commit],
|
|
||||||
})
|
|
||||||
td.replace(process, 'cwd', () => cwd)
|
td.replace(process, 'cwd', () => cwd)
|
||||||
td.replace(console, 'log')
|
td.replace(console, 'log')
|
||||||
})
|
})
|
||||||
|
|
@ -543,8 +476,8 @@ describe('Commit Linter action', () => {
|
||||||
it('should generate a JSON output of the messages', async () => {
|
it('should generate a JSON output of the messages', async () => {
|
||||||
const expectedResultsOutput = [
|
const expectedResultsOutput = [
|
||||||
{
|
{
|
||||||
hash: commit.sha,
|
hash: commit.id,
|
||||||
message: commit.commit.message,
|
message: commit.message,
|
||||||
valid: true,
|
valid: true,
|
||||||
errors: [],
|
errors: [],
|
||||||
warnings: [],
|
warnings: [],
|
||||||
|
|
@ -574,19 +507,6 @@ describe('Commit Linter action', () => {
|
||||||
await createPushEventPayload(cwd, {
|
await createPushEventPayload(cwd, {
|
||||||
commits: [commitWithWarning, correctCommit],
|
commits: [commitWithWarning, correctCommit],
|
||||||
})
|
})
|
||||||
td.when(
|
|
||||||
mockListPushCommits({
|
|
||||||
owner: 'wagoid',
|
|
||||||
repo: 'commitlint-github-action',
|
|
||||||
per_page: 100,
|
|
||||||
sha: '00000',
|
|
||||||
}),
|
|
||||||
).thenResolve({
|
|
||||||
data: [
|
|
||||||
buildResponseCommit(commitWithWarning.id, commitWithWarning.message),
|
|
||||||
buildResponseCommit(correctCommit.id, correctCommit.message),
|
|
||||||
],
|
|
||||||
})
|
|
||||||
updatePushEnvVars(cwd)
|
updatePushEnvVars(cwd)
|
||||||
td.replace(process, 'cwd', () => cwd)
|
td.replace(process, 'cwd', () => cwd)
|
||||||
td.replace(console, 'log')
|
td.replace(console, 'log')
|
||||||
|
|
@ -660,20 +580,6 @@ describe('Commit Linter action', () => {
|
||||||
await createPushEventPayload(cwd, {
|
await createPushEventPayload(cwd, {
|
||||||
commits: [wrongCommit, commitWithWarning],
|
commits: [wrongCommit, commitWithWarning],
|
||||||
})
|
})
|
||||||
td.when(
|
|
||||||
mockListPushCommits({
|
|
||||||
owner: 'wagoid',
|
|
||||||
repo: 'commitlint-github-action',
|
|
||||||
per_page: 100,
|
|
||||||
sha: '00000',
|
|
||||||
}),
|
|
||||||
).thenResolve({
|
|
||||||
data: [
|
|
||||||
buildResponseCommit(wrongCommit.id, wrongCommit.message),
|
|
||||||
buildResponseCommit(commitWithWarning.id, commitWithWarning.message),
|
|
||||||
],
|
|
||||||
})
|
|
||||||
|
|
||||||
updatePushEnvVars(cwd)
|
updatePushEnvVars(cwd)
|
||||||
td.replace(process, 'cwd', () => cwd)
|
td.replace(process, 'cwd', () => cwd)
|
||||||
td.replace(console, 'log')
|
td.replace(console, 'log')
|
||||||
|
|
@ -729,23 +635,15 @@ describe('Commit Linter action', () => {
|
||||||
describe('when commit contains required signed-off-by message', () => {
|
describe('when commit contains required signed-off-by message', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
cwd = await git.bootstrap('fixtures/signed-off-by', process.cwd())
|
cwd = await git.bootstrap('fixtures/signed-off-by', process.cwd())
|
||||||
await createPushEventPayload(cwd)
|
await createPushEventPayload(cwd, {
|
||||||
td.when(
|
commits: [
|
||||||
mockListPushCommits({
|
{
|
||||||
owner: 'wagoid',
|
id: 'correct-commit',
|
||||||
repo: 'commitlint-github-action',
|
message:
|
||||||
per_page: 100,
|
'chore: correct message\n\nsome context without leading blank line.\n\nSigned-off-by: John Doe <john.doe@example.com>',
|
||||||
sha: '00000',
|
},
|
||||||
}),
|
|
||||||
).thenResolve({
|
|
||||||
data: [
|
|
||||||
buildResponseCommit(
|
|
||||||
'correct-commit',
|
|
||||||
'chore: correct message\n\nsome context without leading blank line.\n\nSigned-off-by: John Doe <john.doe@example.com>',
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
updatePushEnvVars(cwd)
|
updatePushEnvVars(cwd)
|
||||||
td.replace(process, 'cwd', () => cwd)
|
td.replace(process, 'cwd', () => cwd)
|
||||||
td.replace(console, 'log')
|
td.replace(console, 'log')
|
||||||
|
|
@ -762,16 +660,13 @@ describe('Commit Linter action', () => {
|
||||||
describe('when a different helpUrl is provided in the config', () => {
|
describe('when a different helpUrl is provided in the config', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
cwd = await git.bootstrap('fixtures/custom-help-url', process.cwd())
|
cwd = await git.bootstrap('fixtures/custom-help-url', process.cwd())
|
||||||
await createPushEventPayload(cwd)
|
await createPushEventPayload(cwd, {
|
||||||
td.when(
|
commits: [
|
||||||
mockListPushCommits({
|
{
|
||||||
owner: 'wagoid',
|
id: 'wrong-commit',
|
||||||
repo: 'commitlint-github-action',
|
message: 'wrong message',
|
||||||
per_page: 100,
|
},
|
||||||
sha: '00000',
|
],
|
||||||
}),
|
|
||||||
).thenResolve({
|
|
||||||
data: [buildResponseCommit('wrong-commit', 'wrong message')],
|
|
||||||
})
|
})
|
||||||
updatePushEnvVars(cwd)
|
updatePushEnvVars(cwd)
|
||||||
td.replace(process, 'cwd', () => cwd)
|
td.replace(process, 'cwd', () => cwd)
|
||||||
|
|
@ -803,19 +698,6 @@ describe('Commit Linter action', () => {
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
updatePushEnvVars(cwd)
|
updatePushEnvVars(cwd)
|
||||||
td.when(
|
|
||||||
mockListPushCommits({
|
|
||||||
owner: 'wagoid',
|
|
||||||
repo: 'commitlint-github-action',
|
|
||||||
per_page: 100,
|
|
||||||
sha: '00000',
|
|
||||||
}),
|
|
||||||
).thenResolve({
|
|
||||||
data: [
|
|
||||||
buildResponseCommit('correct-commit', 'chore: correct message 2'),
|
|
||||||
buildResponseCommit(incorrectCommit.id, incorrectCommit.message),
|
|
||||||
],
|
|
||||||
})
|
|
||||||
td.replace(process, 'cwd', () => cwd)
|
td.replace(process, 'cwd', () => cwd)
|
||||||
td.replace(console, 'log')
|
td.replace(console, 'log')
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -19,26 +19,16 @@ export const updatePushEnvVars = (cwd) => {
|
||||||
|
|
||||||
export const createPushEventPayload = async (
|
export const createPushEventPayload = async (
|
||||||
cwd,
|
cwd,
|
||||||
commits = null,
|
{ forced = false, headCommit = null, commits = [] },
|
||||||
before = null,
|
|
||||||
) => {
|
) => {
|
||||||
const payload = {
|
const payload = {
|
||||||
forced: false,
|
forced,
|
||||||
head_commit: null,
|
head_commit: headCommit,
|
||||||
before: before || '00000',
|
commits,
|
||||||
commits: commits || [
|
|
||||||
{
|
|
||||||
id: 'ignored',
|
|
||||||
message: 'but needed for triggering',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
const eventPath = path.join(cwd, 'pushEventPayload.json')
|
const eventPath = path.join(cwd, 'pushEventPayload.json')
|
||||||
|
|
||||||
updateEnvVars({
|
updateEnvVars({ GITHUB_EVENT_PATH: eventPath })
|
||||||
GITHUB_EVENT_PATH: eventPath,
|
|
||||||
GITHUB_REPOSITORY: 'wagoid/commitlint-github-action',
|
|
||||||
})
|
|
||||||
await writeFile(eventPath, JSON.stringify(payload), 'utf8')
|
await writeFile(eventPath, JSON.stringify(payload), 'utf8')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue