Skip to content

Commit

Permalink
feat: add annotations option to action yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
Codex- committed Oct 31, 2023
1 parent 3e23316 commit 56db806
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ The following inputs are supported
| `token` | GitHub Personal Access Token for making API requests. | `false` | `${{ github.token }}` |
| `command_script_name` | The package script that runs knip. | `false` | `knip` |
| `comment_id` | ID to use when updating the PR comment. Spaces will be replaced with dashes. | `false` | `${{ github.workflow }}-knip-reporter` |
| `annotations` | Annotate the project code with the knip results. | `false` | `true` |
| `ignore_result` | Do not fail the action run if knip results are found. | `false` | `false` |

### Issues
Expand Down
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ inputs:
description: ID to use when updating the PR comment.
default: "${{ github.workflow }}-knip-reporter"
required: false
annotations:
description: Annotate the project code with the knip results.
default: true
required: false
ignore_results:
description: Do not fail the action run if knip results are found
description: Do not fail the action run if knip results are found.
default: false
required: false
runs:
Expand Down
8 changes: 8 additions & 0 deletions src/action.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe("Action", () => {
case "token":
case "command_script_name":
case "comment_id":
case "annotations":
case "ignore_results":
return mockEnvConfig[input];
default:
Expand Down Expand Up @@ -97,6 +98,13 @@ describe("Action", () => {
expect(config.commentId).toStrictEqual("Special-Comment-ID");
});

it("should load a custom value for annotations", () => {
mockEnvConfig.annotations = "false";
const config: ActionConfig = getConfig();

expect(config.annotations).toStrictEqual(false);
});

it("should load a custom value for ignoreResults", () => {
mockEnvConfig.ignore_results = "true";
const config: ActionConfig = getConfig();
Expand Down
10 changes: 8 additions & 2 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ export interface ActionConfig {
commandScriptName: string;

/**
* ID to use when updating the PR comment
* ID to use when updating the PR comment.
*/
commentId: string;

/**
* Do not fail the action run if knip results are found
* Annotate the project code with the knip results.
*/
annotations: boolean;

/**
* Do not fail the action run if knip results are found.
*/
ignoreResults: boolean;
}
Expand All @@ -30,6 +35,7 @@ export function getConfig(): ActionConfig {
token: core.getInput("token", { required: true }),
commandScriptName: core.getInput("command_script_name", { required: false }) || "knip",
commentId: core.getInput("comment_id", { required: true }).trim().replaceAll(/\s/g, "-"),
annotations: core.getInput("annotations", { required: false }) === "true",
ignoreResults: core.getInput("ignore_results", { required: false }) === "true",
};
}
Expand Down

0 comments on commit 56db806

Please sign in to comment.