Skip to content

Commit

Permalink
Add debug option (#22)
Browse files Browse the repository at this point in the history
* add debug option

* update workflow

* add debug message

* update script for test, removing "debug: true"

* Revert "update script for test, removing "debug: true""

This reverts commit 2f6419f.
  • Loading branch information
tnyo43 committed Mar 20, 2024
1 parent 324fcec commit eced567
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ jobs:
uses: ./
with:
threshold: 4
debug: true
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ inputs:
exceeds this'
required: true
default: 25
debug:
description: show debug message (for development)
required: false

runs:
using: node20
Expand Down
9 changes: 8 additions & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions src/option.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
Expand All @@ -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,
});
});
});
Expand All @@ -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,
});
});
});
13 changes: 12 additions & 1 deletion src/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,9 +27,19 @@ 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('******* DEBUG is ENABLED *******');
console.log('option', option);
}

return option;
}

0 comments on commit eced567

Please sign in to comment.