Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add debug option #22

Merged
merged 5 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Owner Author

@tnyo43 tnyo43 Mar 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test comment

it shows the option 👍

option {
token: '***',
prNumber: 22,
threshold: 4,
debug: true
}
https://github.com/tnyo43/recommend-mobpro-action/actions/runs/8360187697/job/22885284100

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:
Copy link
Owner Author

@tnyo43 tnyo43 Mar 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test comment

Because I removed "debug: true" in 2f6419f, it doesn't show the option 👍
https://github.com/tnyo43/recommend-mobpro-action/actions/runs/8360274711/job/22885574892

description: show debug message (for development)
required: false

runs:
using: node20
Expand Down
8 changes: 7 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,
});
});
});
12 changes: 11 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,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;
}
Loading