From 0946730c3c9f03e02e3b1d45d525df6825203c43 Mon Sep 17 00:00:00 2001 From: Tomoya Kashifuku Date: Wed, 20 Mar 2024 22:57:45 +0900 Subject: [PATCH 1/5] add debug option --- dist/index.js | 8 +++++++- src/option.test.ts | 18 ++++++++++++------ src/option.ts | 12 +++++++++++- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/dist/index.js b/dist/index.js index 87b581b..3cdcfb1 100644 --- a/dist/index.js +++ b/dist/index.js @@ -29217,11 +29217,17 @@ function getOption() { (0, core_1.setFailed)('fail to get pr number'); } const threshold = Number((0, core_1.getInput)('threshold', { required: true })); - return { + const debug = (0, core_1.getInput)('debug', { required: false }) === 'true'; + const option = { token, prNumber, threshold, + debug, }; + if (debug) { + console.log('option', option); + } + return option; } exports.getOption = getOption; diff --git a/src/option.test.ts b/src/option.test.ts index 62d60ae..a458152 100644 --- a/src/option.test.ts +++ b/src/option.test.ts @@ -3,11 +3,15 @@ import { context } from '@actions/github'; const mockedContext = jest.mocked(context); +const OPTIONS = { + github_token: 'token:123', + threshold: 100, + debug: 'false', +}; + jest.mock('@actions/core', () => ({ - getInput: (name: string) => { - if (name === 'threshold') return '100'; - return `value-${name}`; - }, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + getInput: (name: string) => (OPTIONS as any)[name], setFailed: () => { throw new Error(); }, @@ -26,9 +30,10 @@ describe('if the event is triggered by "pull_request_review_comment"', () => { test('return pr number from "context.payload.pull_request.number"', () => { const option = getOption(); expect(option).toStrictEqual({ + token: 'token:123', prNumber: 5, threshold: 100, - token: 'value-github_token', + debug: false, }); }); }); @@ -46,9 +51,10 @@ describe('if the event is triggered by "issue_comment"', () => { test('return pr number from "context.payload.issue.number"', () => { const option = getOption(); expect(option).toStrictEqual({ + token: 'token:123', prNumber: 5, threshold: 100, - token: 'value-github_token', + debug: false, }); }); }); diff --git a/src/option.ts b/src/option.ts index a0b862a..4a0705b 100644 --- a/src/option.ts +++ b/src/option.ts @@ -2,6 +2,7 @@ import { getInput, setFailed } from '@actions/core'; import { context } from '@actions/github'; type Option = { + debug: boolean; token: string; prNumber: number; threshold: number; @@ -26,9 +27,18 @@ export function getOption(): Option { const threshold = Number(getInput('threshold', { required: true })); - return { + const debug = getInput('debug', { required: false }) === 'true'; + + const option = { token, prNumber, threshold, + debug, }; + + if (debug) { + console.log('option', option); + } + + return option; } From 8ecaf7912352f8ba27a0a0a2f0de2dbf45b38616 Mon Sep 17 00:00:00 2001 From: Tomoya Kashifuku Date: Wed, 20 Mar 2024 22:58:39 +0900 Subject: [PATCH 2/5] update workflow --- .github/workflows/test-action.yml | 1 + action.yml | 3 +++ 2 files changed, 4 insertions(+) diff --git a/.github/workflows/test-action.yml b/.github/workflows/test-action.yml index 2a4069b..c3455eb 100644 --- a/.github/workflows/test-action.yml +++ b/.github/workflows/test-action.yml @@ -28,3 +28,4 @@ jobs: uses: ./ with: threshold: 4 + debug: true diff --git a/action.yml b/action.yml index bfb85b8..fe32fc0 100644 --- a/action.yml +++ b/action.yml @@ -13,6 +13,9 @@ inputs: exceeds this' required: true default: 25 + debug: + description: show debug message (for development) + required: false runs: using: node20 From bac84a55cf2ac8f74916944d09f2ce016311171e Mon Sep 17 00:00:00 2001 From: Tomoya Kashifuku Date: Wed, 20 Mar 2024 23:02:43 +0900 Subject: [PATCH 3/5] add debug message --- dist/index.js | 1 + src/option.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/dist/index.js b/dist/index.js index 3cdcfb1..1919d0c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -29225,6 +29225,7 @@ function getOption() { debug, }; if (debug) { + console.log('******* DEBUG is ENABLED *******'); console.log('option', option); } return option; diff --git a/src/option.ts b/src/option.ts index 4a0705b..0d3b4e1 100644 --- a/src/option.ts +++ b/src/option.ts @@ -37,6 +37,7 @@ export function getOption(): Option { }; if (debug) { + console.log('******* DEBUG is ENABLED *******'); console.log('option', option); } From 2f6419f9e198419419d9ee978708f758af77bbfe Mon Sep 17 00:00:00 2001 From: Tomoya Kashifuku Date: Wed, 20 Mar 2024 23:03:07 +0900 Subject: [PATCH 4/5] update script for test, removing "debug: true" --- .github/workflows/test-action.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test-action.yml b/.github/workflows/test-action.yml index c3455eb..2a4069b 100644 --- a/.github/workflows/test-action.yml +++ b/.github/workflows/test-action.yml @@ -28,4 +28,3 @@ jobs: uses: ./ with: threshold: 4 - debug: true From d0f9fff2f3d491e4a2cea3d83abdc6efa8617972 Mon Sep 17 00:00:00 2001 From: Tomoya Kashifuku Date: Wed, 20 Mar 2024 23:05:31 +0900 Subject: [PATCH 5/5] Revert "update script for test, removing "debug: true"" This reverts commit 2f6419f9e198419419d9ee978708f758af77bbfe. --- .github/workflows/test-action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test-action.yml b/.github/workflows/test-action.yml index 2a4069b..c3455eb 100644 --- a/.github/workflows/test-action.yml +++ b/.github/workflows/test-action.yml @@ -28,3 +28,4 @@ jobs: uses: ./ with: threshold: 4 + debug: true