From 70e22e95384c0028a4a5a9679a729c3ac9224dcd Mon Sep 17 00:00:00 2001 From: brian-triplett Date: Mon, 19 Aug 2024 11:01:00 -0400 Subject: [PATCH 1/5] feat: updating push event trigger to use rest API (OctoKit) vs push event --- src/action.mjs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/action.mjs b/src/action.mjs index 6c74eb17..7d3d17ae 100644 --- a/src/action.mjs +++ b/src/action.mjs @@ -22,13 +22,20 @@ const getCommitDepth = () => { return Number.isNaN(commitDepth) ? null : Math.max(commitDepth, 0) } -const getPushEventCommits = () => { - const mappedCommits = eventContext.payload.commits.map((commit) => ({ - message: commit.message, - hash: commit.id, - })) +const getPushEventCommits = async () => { + const octokit = getOctokit(getInput('token')) + const { owner, repo, before } = eventContext.issue + const { data: commits } = await octokit.rest.repos.listCommits({ + owner, + repo, + sha: before, + per_page: 100, + }) - return mappedCommits + return commits.map((commit) => ({ + message: commit.commit.message, + hash: commit.sha, + })) } const getPullRequestEventCommits = async () => { From c3ab7fd301c536b0e96211a1dde49b6aabbfa8fd Mon Sep 17 00:00:00 2001 From: brian-triplett Date: Tue, 20 Aug 2024 15:57:45 -0400 Subject: [PATCH 2/5] fix: updating unit tests with mocking push octokit list commits --- src/action.mjs | 3 +- src/action.test.mjs | 344 +++++++++++++++++++++++++++++--------------- src/testUtils.mjs | 20 ++- 3 files changed, 248 insertions(+), 119 deletions(-) diff --git a/src/action.mjs b/src/action.mjs index 7d3d17ae..64761f5d 100644 --- a/src/action.mjs +++ b/src/action.mjs @@ -24,7 +24,8 @@ const getCommitDepth = () => { const getPushEventCommits = async () => { const octokit = getOctokit(getInput('token')) - const { owner, repo, before } = eventContext.issue + const { owner, repo } = eventContext.issue + const { before } = eventContext.payload const { data: commits } = await octokit.rest.repos.listCommits({ owner, repo, diff --git a/src/action.test.mjs b/src/action.test.mjs index 4eaaa10b..43e16ca0 100644 --- a/src/action.test.mjs +++ b/src/action.test.mjs @@ -19,7 +19,8 @@ const { const initialEnv = { ...process.env } -const mockListCommits = td.func('listCommits') +const mockListPullCommits = td.func('listCommits') +const mockListPushCommits = td.func('listCommits') const mockCore = td.object(['getInput', 'setFailed', 'setOutput']) @@ -30,7 +31,10 @@ jest.unstable_mockModule('@actions/github', () => { constructor() { this.rest = { pulls: { - listCommits: mockListCommits, + listCommits: mockListPullCommits, + }, + repos: { + listCommits: mockListPushCommits, }, } } @@ -72,15 +76,18 @@ describe('Commit Linter action', () => { './not-existing-config.mjs', ) cwd = await git.bootstrap('fixtures/conventional', process.cwd()) - await createPushEventPayload(cwd, { - commits: [ - { - id: 'wrong-message', - message: 'wrong message', - }, - ], - }) + await createPushEventPayload(cwd) updatePushEnvVars(cwd) + td.when( + mockListPushCommits({ + owner: 'wagoid', + repo: 'commitlint-github-action', + per_page: 100, + sha: '00000', + }), + ).thenResolve({ + data: [buildResponseCommit('wrong-message', 'wrong message')], + }) td.replace(process, 'cwd', () => cwd) await runAction() @@ -102,15 +109,18 @@ describe('Commit Linter action', () => { './commitlint.config.js', ) cwd = await git.bootstrap('fixtures/conventional', process.cwd()) - await createPushEventPayload(cwd, { - commits: [ - { - id: 'wrong-message', - message: 'wrong message', - }, - ], - }) + await createPushEventPayload(cwd) updatePushEnvVars(cwd) + td.when( + mockListPushCommits({ + owner: 'wagoid', + repo: 'commitlint-github-action', + per_page: 100, + sha: '00000', + }), + ).thenResolve({ + data: [buildResponseCommit('wrong-message', 'wrong message')], + }) td.replace(process, 'cwd', () => cwd) await runAction() @@ -120,15 +130,19 @@ describe('Commit Linter action', () => { it('should fail for single push with incorrect message', async () => { cwd = await git.bootstrap('fixtures/conventional', process.cwd()) - await createPushEventPayload(cwd, { - commits: [ - { - id: 'wrong-message', - message: 'wrong message', - }, - ], - }) + await createPushEventPayload(cwd) updatePushEnvVars(cwd) + td.when( + mockListPushCommits({ + owner: 'wagoid', + repo: 'commitlint-github-action', + per_page: 100, + sha: '00000', + }), + ).thenResolve({ + data: [buildResponseCommit('wrong-message', 'wrong message')], + }) + td.replace(process, 'cwd', () => cwd) await runAction() @@ -140,19 +154,21 @@ describe('Commit Linter action', () => { it('should fail for push range with wrong messages', async () => { cwd = await git.bootstrap('fixtures/conventional', process.cwd()) - await createPushEventPayload(cwd, { - commits: [ - { - id: 'wrong-message-1', - message: 'wrong message 1', - }, - { - id: 'wrong-message-2', - message: 'wrong message 2', - }, + await createPushEventPayload(cwd) + updatePushEnvVars(cwd) + td.when( + mockListPushCommits({ + owner: 'wagoid', + repo: 'commitlint-github-action', + per_page: 100, + sha: '00000', + }), + ).thenResolve({ + data: [ + buildResponseCommit('wrong-message-1', 'wrong message 1'), + buildResponseCommit('wrong-message-2', 'wrong message 2'), ], }) - updatePushEnvVars(cwd) td.replace(process, 'cwd', () => cwd) await runAction() @@ -163,19 +179,21 @@ describe('Commit Linter action', () => { it('should pass for push range with wrong messages with failOnErrors set to false', async () => { td.when(mockCore.getInput('failOnErrors')).thenReturn('false') cwd = await git.bootstrap('fixtures/conventional', process.cwd()) - await createPushEventPayload(cwd, { - commits: [ - { - id: 'wrong-message-1', - message: 'wrong message 1', - }, - { - id: 'wrong-message-2', - message: 'wrong message 2', - }, + await createPushEventPayload(cwd) + updatePushEnvVars(cwd) + td.when( + mockListPushCommits({ + owner: 'wagoid', + repo: 'commitlint-github-action', + per_page: 100, + sha: '00000', + }), + ).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(console, 'log') @@ -190,19 +208,21 @@ describe('Commit Linter action', () => { it('should pass for push range with correct messages with failOnErrors set to false', async () => { td.when(mockCore.getInput('failOnErrors')).thenReturn('false') cwd = await git.bootstrap('fixtures/conventional', process.cwd()) - await createPushEventPayload(cwd, { - commits: [ - { - id: 'correct-message-1', - message: 'chore: correct message 1', - }, - { - id: 'correct-message-2', - message: 'chore: correct message 2', - }, + await createPushEventPayload(cwd) + updatePushEnvVars(cwd) + td.when( + mockListPushCommits({ + owner: 'wagoid', + repo: 'commitlint-github-action', + per_page: 100, + sha: '00000', + }), + ).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(console, 'log') @@ -214,19 +234,21 @@ describe('Commit Linter action', () => { it('should pass for push range with correct messages', async () => { cwd = await git.bootstrap('fixtures/conventional', process.cwd()) - await createPushEventPayload(cwd, { - commits: [ - { - id: 'correct-message-1', - message: 'chore: correct message 1', - }, - { - id: 'correct-message-2', - message: 'chore: correct message 2', - }, + await createPushEventPayload(cwd) + updatePushEnvVars(cwd) + td.when( + mockListPushCommits({ + owner: 'wagoid', + repo: 'commitlint-github-action', + per_page: 100, + sha: '00000', + }), + ).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(console, 'log') @@ -241,14 +263,23 @@ describe('Commit Linter action', () => { td.when(mockCore.getInput('configFile')).thenReturn( './commitlint.config.yml', ) - await createPushEventPayload(cwd, { - commits: [ - { - message: 'chore(wrong): not including package scope', - }, + await createPushEventPayload(cwd) + updatePushEnvVars(cwd) + td.when( + mockListPushCommits({ + 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) await runAction() @@ -263,15 +294,23 @@ describe('Commit Linter action', () => { td.when(mockCore.getInput('configFile')).thenReturn( './commitlint.config.yml', ) - await createPushEventPayload(cwd, { - commits: [ - { - id: 'correct-message', - message: 'chore(second-package): this works', - }, + await createPushEventPayload(cwd) + updatePushEnvVars(cwd) + td.when( + mockListPushCommits({ + owner: 'wagoid', + 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(console, 'log') @@ -285,12 +324,20 @@ describe('Commit Linter action', () => { td.when(mockCore.getInput('configFile')).thenReturn( './commitlint.config.mjs', ) - await createPushEventPayload(cwd, { - commits: [ - { - id: 'wrong-message', - message: 'ib-21212121212121: without jira ticket', - }, + await createPushEventPayload(cwd) + td.when( + mockListPushCommits({ + owner: 'wagoid', + repo: 'commitlint-github-action', + per_page: 100, + sha: '00000', + }), + ).thenResolve({ + data: [ + buildResponseCommit( + 'wrong-message', + 'ib-21212121212121: without jira ticket', + ), ], }) updatePushEnvVars(cwd) @@ -325,8 +372,18 @@ describe('Commit Linter action', () => { './commitlint.config.mjs', ) cwd = await git.bootstrap('fixtures/conventional', process.cwd()) - await createPushEventPayload(cwd, {}) + await createPushEventPayload(cwd, { commits: [] }, '12345') 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(console, 'log') @@ -354,7 +411,7 @@ describe('Commit Linter action', () => { await createPullRequestEventPayload(cwd) updatePullRequestEnvVars(cwd, { eventName }) td.when( - mockListCommits({ + mockListPullCommits({ owner: 'wagoid', repo: 'commitlint-github-action', pull_number: '1', @@ -420,7 +477,7 @@ describe('Commit Linter action', () => { await createPullRequestEventPayload(cwd) updatePullRequestEnvVars(cwd) td.when( - mockListCommits({ + mockListPullCommits({ owner: 'wagoid', repo: 'commitlint-github-action', pull_number: '1', @@ -448,15 +505,25 @@ describe('Commit Linter action', () => { }) describe("when there's a single commit with correct message", () => { - const commit = { - id: 'correct-message', - message: 'chore: correct message', - } + const commit = buildResponseCommit( + 'correct-commit', + 'chore: correct message', + ) beforeEach(async () => { cwd = await git.bootstrap('fixtures/conventional', process.cwd()) - await createPushEventPayload(cwd, { commits: [commit] }) + await createPushEventPayload(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(console, 'log') }) @@ -476,8 +543,8 @@ describe('Commit Linter action', () => { it('should generate a JSON output of the messages', async () => { const expectedResultsOutput = [ { - hash: commit.id, - message: commit.message, + hash: commit.sha, + message: commit.commit.message, valid: true, errors: [], warnings: [], @@ -507,6 +574,19 @@ describe('Commit Linter action', () => { await createPushEventPayload(cwd, { 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) td.replace(process, 'cwd', () => cwd) td.replace(console, 'log') @@ -580,6 +660,20 @@ describe('Commit Linter action', () => { await createPushEventPayload(cwd, { 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) td.replace(process, 'cwd', () => cwd) td.replace(console, 'log') @@ -635,15 +729,23 @@ describe('Commit Linter action', () => { describe('when commit contains required signed-off-by message', () => { beforeEach(async () => { cwd = await git.bootstrap('fixtures/signed-off-by', process.cwd()) - await createPushEventPayload(cwd, { - commits: [ - { - id: 'correct-commit', - message: - 'chore: correct message\n\nsome context without leading blank line.\n\nSigned-off-by: John Doe ', - }, + await createPushEventPayload(cwd) + td.when( + mockListPushCommits({ + owner: 'wagoid', + repo: 'commitlint-github-action', + per_page: 100, + sha: '00000', + }), + ).thenResolve({ + data: [ + buildResponseCommit( + 'correct-commit', + 'chore: correct message\n\nsome context without leading blank line.\n\nSigned-off-by: John Doe ', + ), ], }) + updatePushEnvVars(cwd) td.replace(process, 'cwd', () => cwd) td.replace(console, 'log') @@ -660,13 +762,16 @@ describe('Commit Linter action', () => { describe('when a different helpUrl is provided in the config', () => { beforeEach(async () => { cwd = await git.bootstrap('fixtures/custom-help-url', process.cwd()) - await createPushEventPayload(cwd, { - commits: [ - { - id: 'wrong-commit', - message: 'wrong message', - }, - ], + await createPushEventPayload(cwd) + td.when( + mockListPushCommits({ + owner: 'wagoid', + repo: 'commitlint-github-action', + per_page: 100, + sha: '00000', + }), + ).thenResolve({ + data: [buildResponseCommit('wrong-commit', 'wrong message')], }) updatePushEnvVars(cwd) td.replace(process, 'cwd', () => cwd) @@ -698,6 +803,19 @@ describe('Commit Linter action', () => { ], }) 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(console, 'log') }) diff --git a/src/testUtils.mjs b/src/testUtils.mjs index 33abb10d..47b678b1 100644 --- a/src/testUtils.mjs +++ b/src/testUtils.mjs @@ -19,16 +19,26 @@ export const updatePushEnvVars = (cwd) => { export const createPushEventPayload = async ( cwd, - { forced = false, headCommit = null, commits = [] }, + commits = null, + before = null, ) => { const payload = { - forced, - head_commit: headCommit, - commits, + forced: false, + head_commit: null, + before: before || '00000', + commits: commits || [ + { + id: 'ignored', + message: 'but needed for triggering', + }, + ], } const eventPath = path.join(cwd, 'pushEventPayload.json') - updateEnvVars({ GITHUB_EVENT_PATH: eventPath }) + updateEnvVars({ + GITHUB_EVENT_PATH: eventPath, + GITHUB_REPOSITORY: 'wagoid/commitlint-github-action', + }) await writeFile(eventPath, JSON.stringify(payload), 'utf8') } From dbd4ecd47d0256b6587d1d0c5737082cc439f2c5 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Tue, 20 Aug 2024 22:04:25 +0000 Subject: [PATCH 3/5] chore(release): publish 6.1.0 [skip-ci] --- CHANGELOG.md | 12 ++++++++++++ action.yml | 2 +- package-lock.json | 4 ++-- package.json | 2 +- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9992007..fb510d96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,18 @@ All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines. +## [6.1.0](https://github.com/wagoid/commitlint-github-action/compare/v6.0.2...v6.1.0) (2024-08-20) + + +### Features + +* updating push event trigger to use rest API (OctoKit) vs push event ([70e22e9](https://github.com/wagoid/commitlint-github-action/commit/70e22e95384c0028a4a5a9679a729c3ac9224dcd)) + + +### Bug Fixes + +* updating unit tests with mocking push octokit list commits ([c3ab7fd](https://github.com/wagoid/commitlint-github-action/commit/c3ab7fd301c536b0e96211a1dde49b6aabbfa8fd)) + ## [6.0.2](https://github.com/wagoid/commitlint-github-action/compare/v6.0.1...v6.0.2) (2024-08-05) ## [6.0.1](https://github.com/wagoid/commitlint-github-action/compare/v6.0.0...v6.0.1) (2024-04-10) diff --git a/action.yml b/action.yml index 2890ef6a..7372623a 100644 --- a/action.yml +++ b/action.yml @@ -35,7 +35,7 @@ outputs: description: The error and warning messages for each one of the analyzed commits runs: using: docker - image: docker://wagoid/commitlint-github-action:6.0.2 + image: docker://wagoid/commitlint-github-action:6.1.0 branding: icon: check-square color: blue diff --git a/package-lock.json b/package-lock.json index 85599e6f..fd183259 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "commitlint-github-action", - "version": "6.0.2", + "version": "6.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "commitlint-github-action", - "version": "6.0.2", + "version": "6.1.0", "hasInstallScript": true, "license": "ISC", "dependencies": { diff --git a/package.json b/package.json index bbbcc2a6..defcde8c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "commitlint-github-action", - "version": "6.0.2", + "version": "6.1.0", "description": "commitlint github action", "private": true, "module": "./dist/run.mjs", From 09a8abb7577d5d8ba5690a59587ad7acf90bce37 Mon Sep 17 00:00:00 2001 From: Wagner Santos <7467450+wagoid@users.noreply.github.com> Date: Wed, 21 Aug 2024 04:30:36 -0300 Subject: [PATCH 4/5] Revert "feat: updating push event trigger to use rest API (OctoKit) vs push event" --- src/action.mjs | 20 +-- src/action.test.mjs | 344 +++++++++++++++----------------------------- src/testUtils.mjs | 20 +-- 3 files changed, 124 insertions(+), 260 deletions(-) diff --git a/src/action.mjs b/src/action.mjs index 64761f5d..6c74eb17 100644 --- a/src/action.mjs +++ b/src/action.mjs @@ -22,21 +22,13 @@ const getCommitDepth = () => { return Number.isNaN(commitDepth) ? null : Math.max(commitDepth, 0) } -const getPushEventCommits = async () => { - const octokit = getOctokit(getInput('token')) - const { owner, repo } = eventContext.issue - const { before } = eventContext.payload - 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, +const getPushEventCommits = () => { + const mappedCommits = eventContext.payload.commits.map((commit) => ({ + message: commit.message, + hash: commit.id, })) + + return mappedCommits } const getPullRequestEventCommits = async () => { diff --git a/src/action.test.mjs b/src/action.test.mjs index 43e16ca0..4eaaa10b 100644 --- a/src/action.test.mjs +++ b/src/action.test.mjs @@ -19,8 +19,7 @@ const { const initialEnv = { ...process.env } -const mockListPullCommits = td.func('listCommits') -const mockListPushCommits = td.func('listCommits') +const mockListCommits = td.func('listCommits') const mockCore = td.object(['getInput', 'setFailed', 'setOutput']) @@ -31,10 +30,7 @@ jest.unstable_mockModule('@actions/github', () => { constructor() { this.rest = { pulls: { - listCommits: mockListPullCommits, - }, - repos: { - listCommits: mockListPushCommits, + listCommits: mockListCommits, }, } } @@ -76,18 +72,15 @@ describe('Commit Linter action', () => { './not-existing-config.mjs', ) cwd = await git.bootstrap('fixtures/conventional', process.cwd()) - await createPushEventPayload(cwd) - updatePushEnvVars(cwd) - td.when( - mockListPushCommits({ - owner: 'wagoid', - repo: 'commitlint-github-action', - per_page: 100, - sha: '00000', - }), - ).thenResolve({ - data: [buildResponseCommit('wrong-message', 'wrong message')], + await createPushEventPayload(cwd, { + commits: [ + { + id: 'wrong-message', + message: 'wrong message', + }, + ], }) + updatePushEnvVars(cwd) td.replace(process, 'cwd', () => cwd) await runAction() @@ -109,18 +102,15 @@ describe('Commit Linter action', () => { './commitlint.config.js', ) cwd = await git.bootstrap('fixtures/conventional', process.cwd()) - await createPushEventPayload(cwd) - updatePushEnvVars(cwd) - td.when( - mockListPushCommits({ - owner: 'wagoid', - repo: 'commitlint-github-action', - per_page: 100, - sha: '00000', - }), - ).thenResolve({ - data: [buildResponseCommit('wrong-message', 'wrong message')], + await createPushEventPayload(cwd, { + commits: [ + { + id: 'wrong-message', + message: 'wrong message', + }, + ], }) + updatePushEnvVars(cwd) td.replace(process, 'cwd', () => cwd) await runAction() @@ -130,19 +120,15 @@ describe('Commit Linter action', () => { it('should fail for single push with incorrect message', async () => { cwd = await git.bootstrap('fixtures/conventional', process.cwd()) - await createPushEventPayload(cwd) - updatePushEnvVars(cwd) - td.when( - mockListPushCommits({ - owner: 'wagoid', - repo: 'commitlint-github-action', - per_page: 100, - sha: '00000', - }), - ).thenResolve({ - data: [buildResponseCommit('wrong-message', 'wrong message')], + await createPushEventPayload(cwd, { + commits: [ + { + id: 'wrong-message', + message: 'wrong message', + }, + ], }) - + updatePushEnvVars(cwd) td.replace(process, 'cwd', () => cwd) await runAction() @@ -154,21 +140,19 @@ describe('Commit Linter action', () => { it('should fail for push range with wrong messages', async () => { cwd = await git.bootstrap('fixtures/conventional', process.cwd()) - await createPushEventPayload(cwd) - updatePushEnvVars(cwd) - td.when( - mockListPushCommits({ - owner: 'wagoid', - repo: 'commitlint-github-action', - per_page: 100, - sha: '00000', - }), - ).thenResolve({ - data: [ - buildResponseCommit('wrong-message-1', 'wrong message 1'), - buildResponseCommit('wrong-message-2', 'wrong message 2'), + await createPushEventPayload(cwd, { + commits: [ + { + id: 'wrong-message-1', + message: 'wrong message 1', + }, + { + id: 'wrong-message-2', + message: 'wrong message 2', + }, ], }) + updatePushEnvVars(cwd) td.replace(process, 'cwd', () => cwd) 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 () => { td.when(mockCore.getInput('failOnErrors')).thenReturn('false') cwd = await git.bootstrap('fixtures/conventional', process.cwd()) - await createPushEventPayload(cwd) - updatePushEnvVars(cwd) - td.when( - mockListPushCommits({ - owner: 'wagoid', - repo: 'commitlint-github-action', - per_page: 100, - sha: '00000', - }), - ).thenResolve({ - data: [ - buildResponseCommit('wrong-message-1', 'wrong message 1'), - buildResponseCommit('wrong-message-2', 'wrong message 2'), + await createPushEventPayload(cwd, { + commits: [ + { + id: 'wrong-message-1', + message: 'wrong message 1', + }, + { + id: 'wrong-message-2', + message: 'wrong message 2', + }, ], }) + updatePushEnvVars(cwd) td.replace(process, 'cwd', () => cwd) 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 () => { td.when(mockCore.getInput('failOnErrors')).thenReturn('false') cwd = await git.bootstrap('fixtures/conventional', process.cwd()) - await createPushEventPayload(cwd) - updatePushEnvVars(cwd) - td.when( - mockListPushCommits({ - owner: 'wagoid', - repo: 'commitlint-github-action', - per_page: 100, - sha: '00000', - }), - ).thenResolve({ - data: [ - buildResponseCommit('correct-message-1', 'chore: correct message 1'), - buildResponseCommit('correct-message-2', 'chore: correct message 2'), + await createPushEventPayload(cwd, { + commits: [ + { + id: 'correct-message-1', + message: 'chore: correct message 1', + }, + { + id: 'correct-message-2', + message: 'chore: correct message 2', + }, ], }) + updatePushEnvVars(cwd) td.replace(process, 'cwd', () => cwd) td.replace(console, 'log') @@ -234,21 +214,19 @@ describe('Commit Linter action', () => { it('should pass for push range with correct messages', async () => { cwd = await git.bootstrap('fixtures/conventional', process.cwd()) - await createPushEventPayload(cwd) - updatePushEnvVars(cwd) - td.when( - mockListPushCommits({ - owner: 'wagoid', - repo: 'commitlint-github-action', - per_page: 100, - sha: '00000', - }), - ).thenResolve({ - data: [ - buildResponseCommit('correct-message-1', 'chore: correct message 1'), - buildResponseCommit('correct-message-2', 'chore: correct message 2'), + await createPushEventPayload(cwd, { + commits: [ + { + id: 'correct-message-1', + message: 'chore: correct message 1', + }, + { + id: 'correct-message-2', + message: 'chore: correct message 2', + }, ], }) + updatePushEnvVars(cwd) td.replace(process, 'cwd', () => cwd) td.replace(console, 'log') @@ -263,23 +241,14 @@ describe('Commit Linter action', () => { td.when(mockCore.getInput('configFile')).thenReturn( './commitlint.config.yml', ) - await createPushEventPayload(cwd) - updatePushEnvVars(cwd) - td.when( - mockListPushCommits({ - owner: 'wagoid', - repo: 'commitlint-github-action', - per_page: 100, - sha: '00000', - }), - ).thenResolve({ - data: [ - buildResponseCommit( - 'correct-message', - 'chore(wrong): not including package scope', - ), + await createPushEventPayload(cwd, { + commits: [ + { + message: 'chore(wrong): not including package scope', + }, ], }) + updatePushEnvVars(cwd) td.replace(process, 'cwd', () => cwd) await runAction() @@ -294,23 +263,15 @@ describe('Commit Linter action', () => { td.when(mockCore.getInput('configFile')).thenReturn( './commitlint.config.yml', ) - await createPushEventPayload(cwd) - updatePushEnvVars(cwd) - td.when( - mockListPushCommits({ - owner: 'wagoid', - repo: 'commitlint-github-action', - per_page: 100, - sha: '00000', - }), - ).thenResolve({ - data: [ - buildResponseCommit( - 'correct-message', - 'chore(second-package): this works', - ), + await createPushEventPayload(cwd, { + commits: [ + { + id: 'correct-message', + message: 'chore(second-package): this works', + }, ], }) + updatePushEnvVars(cwd) td.replace(process, 'cwd', () => cwd) td.replace(console, 'log') @@ -324,20 +285,12 @@ describe('Commit Linter action', () => { td.when(mockCore.getInput('configFile')).thenReturn( './commitlint.config.mjs', ) - await createPushEventPayload(cwd) - td.when( - mockListPushCommits({ - owner: 'wagoid', - repo: 'commitlint-github-action', - per_page: 100, - sha: '00000', - }), - ).thenResolve({ - data: [ - buildResponseCommit( - 'wrong-message', - 'ib-21212121212121: without jira ticket', - ), + await createPushEventPayload(cwd, { + commits: [ + { + id: 'wrong-message', + message: 'ib-21212121212121: without jira ticket', + }, ], }) updatePushEnvVars(cwd) @@ -372,18 +325,8 @@ describe('Commit Linter action', () => { './commitlint.config.mjs', ) cwd = await git.bootstrap('fixtures/conventional', process.cwd()) - await createPushEventPayload(cwd, { commits: [] }, '12345') + await createPushEventPayload(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(console, 'log') @@ -411,7 +354,7 @@ describe('Commit Linter action', () => { await createPullRequestEventPayload(cwd) updatePullRequestEnvVars(cwd, { eventName }) td.when( - mockListPullCommits({ + mockListCommits({ owner: 'wagoid', repo: 'commitlint-github-action', pull_number: '1', @@ -477,7 +420,7 @@ describe('Commit Linter action', () => { await createPullRequestEventPayload(cwd) updatePullRequestEnvVars(cwd) td.when( - mockListPullCommits({ + mockListCommits({ owner: 'wagoid', repo: 'commitlint-github-action', pull_number: '1', @@ -505,25 +448,15 @@ describe('Commit Linter action', () => { }) describe("when there's a single commit with correct message", () => { - const commit = buildResponseCommit( - 'correct-commit', - 'chore: correct message', - ) + const commit = { + id: 'correct-message', + message: 'chore: correct message', + } beforeEach(async () => { cwd = await git.bootstrap('fixtures/conventional', process.cwd()) - await createPushEventPayload(cwd) + await createPushEventPayload(cwd, { commits: [commit] }) 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(console, 'log') }) @@ -543,8 +476,8 @@ describe('Commit Linter action', () => { it('should generate a JSON output of the messages', async () => { const expectedResultsOutput = [ { - hash: commit.sha, - message: commit.commit.message, + hash: commit.id, + message: commit.message, valid: true, errors: [], warnings: [], @@ -574,19 +507,6 @@ describe('Commit Linter action', () => { await createPushEventPayload(cwd, { 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) td.replace(process, 'cwd', () => cwd) td.replace(console, 'log') @@ -660,20 +580,6 @@ describe('Commit Linter action', () => { await createPushEventPayload(cwd, { 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) td.replace(process, 'cwd', () => cwd) td.replace(console, 'log') @@ -729,23 +635,15 @@ describe('Commit Linter action', () => { describe('when commit contains required signed-off-by message', () => { beforeEach(async () => { cwd = await git.bootstrap('fixtures/signed-off-by', process.cwd()) - await createPushEventPayload(cwd) - td.when( - mockListPushCommits({ - owner: 'wagoid', - repo: 'commitlint-github-action', - per_page: 100, - sha: '00000', - }), - ).thenResolve({ - data: [ - buildResponseCommit( - 'correct-commit', - 'chore: correct message\n\nsome context without leading blank line.\n\nSigned-off-by: John Doe ', - ), + await createPushEventPayload(cwd, { + commits: [ + { + id: 'correct-commit', + message: + 'chore: correct message\n\nsome context without leading blank line.\n\nSigned-off-by: John Doe ', + }, ], }) - updatePushEnvVars(cwd) td.replace(process, 'cwd', () => cwd) td.replace(console, 'log') @@ -762,16 +660,13 @@ describe('Commit Linter action', () => { describe('when a different helpUrl is provided in the config', () => { beforeEach(async () => { cwd = await git.bootstrap('fixtures/custom-help-url', process.cwd()) - await createPushEventPayload(cwd) - td.when( - mockListPushCommits({ - owner: 'wagoid', - repo: 'commitlint-github-action', - per_page: 100, - sha: '00000', - }), - ).thenResolve({ - data: [buildResponseCommit('wrong-commit', 'wrong message')], + await createPushEventPayload(cwd, { + commits: [ + { + id: 'wrong-commit', + message: 'wrong message', + }, + ], }) updatePushEnvVars(cwd) td.replace(process, 'cwd', () => cwd) @@ -803,19 +698,6 @@ describe('Commit Linter action', () => { ], }) 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(console, 'log') }) diff --git a/src/testUtils.mjs b/src/testUtils.mjs index 47b678b1..33abb10d 100644 --- a/src/testUtils.mjs +++ b/src/testUtils.mjs @@ -19,26 +19,16 @@ export const updatePushEnvVars = (cwd) => { export const createPushEventPayload = async ( cwd, - commits = null, - before = null, + { forced = false, headCommit = null, commits = [] }, ) => { const payload = { - forced: false, - head_commit: null, - before: before || '00000', - commits: commits || [ - { - id: 'ignored', - message: 'but needed for triggering', - }, - ], + forced, + head_commit: headCommit, + commits, } const eventPath = path.join(cwd, 'pushEventPayload.json') - updateEnvVars({ - GITHUB_EVENT_PATH: eventPath, - GITHUB_REPOSITORY: 'wagoid/commitlint-github-action', - }) + updateEnvVars({ GITHUB_EVENT_PATH: eventPath }) await writeFile(eventPath, JSON.stringify(payload), 'utf8') } From a2bc521d745b1ba127ee2f8b02d6afaa4eed035c Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Wed, 21 Aug 2024 07:37:39 +0000 Subject: [PATCH 5/5] chore(release): publish 6.1.1 [skip-ci] --- CHANGELOG.md | 2 ++ action.yml | 2 +- package-lock.json | 4 ++-- package.json | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb510d96..d707ac67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines. +## [6.1.1](https://github.com/wagoid/commitlint-github-action/compare/v6.1.0...v6.1.1) (2024-08-21) + ## [6.1.0](https://github.com/wagoid/commitlint-github-action/compare/v6.0.2...v6.1.0) (2024-08-20) diff --git a/action.yml b/action.yml index 7372623a..ebfe50d8 100644 --- a/action.yml +++ b/action.yml @@ -35,7 +35,7 @@ outputs: description: The error and warning messages for each one of the analyzed commits runs: using: docker - image: docker://wagoid/commitlint-github-action:6.1.0 + image: docker://wagoid/commitlint-github-action:6.1.1 branding: icon: check-square color: blue diff --git a/package-lock.json b/package-lock.json index fd183259..180f74cc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "commitlint-github-action", - "version": "6.1.0", + "version": "6.1.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "commitlint-github-action", - "version": "6.1.0", + "version": "6.1.1", "hasInstallScript": true, "license": "ISC", "dependencies": { diff --git a/package.json b/package.json index defcde8c..bda6fb01 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "commitlint-github-action", - "version": "6.1.0", + "version": "6.1.1", "description": "commitlint github action", "private": true, "module": "./dist/run.mjs",