Skip to content

Commit

Permalink
Allow labels to be provided one per line in input
Browse files Browse the repository at this point in the history
  • Loading branch information
mheap committed Jun 17, 2023
1 parent 1b8424d commit 18f57d7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This action has three required inputs; `labels`, `mode` and `count`

| Name | Description | Required | Default |
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------- | ------------------- |
| `labels` | Comma separated list of labels to match | true |
| `labels` | Comma or new line separated list of labels to match | true |
| `mode` | The mode of comparison to use. One of: exactly, minimum, maximum | true |
| `count` | The required number of labels to match | true |
| `token` | The GitHub token to use when calling the API | false | ${{ github.token }} |
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ async function action() {
const count = parseInt(core.getInput("count", { required: true }), 10);
const providedLabels = core
.getInput("labels", { required: true })
.split("\n")
.join(",")
.split(",")
.map((l) => l.trim())
.filter((r) => r);
Expand Down
28 changes: 28 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,34 @@ describe("Required Labels", () => {
expect(core.setOutput).toBeCalledWith("status", "success");
expect(core.setOutput).toBeCalledWith("labels", "bug");
});

it("supports multiple lines in INPUT_LABELS", async () => {
restoreTest = mockPr({
INPUT_LABELS: "enhancement\nbug",
INPUT_MODE: "exactly",
INPUT_COUNT: "1",
});
mockLabels(["bug"]);

await action();
expect(core.setOutput).toBeCalledTimes(2);
expect(core.setOutput).toBeCalledWith("status", "success");
expect(core.setOutput).toBeCalledWith("labels", "bug");
});

it("supports multiple lines with commas in INPUT_LABELS", async () => {
restoreTest = mockPr({
INPUT_LABELS: "enhancement,\nbug",
INPUT_MODE: "exactly",
INPUT_COUNT: "1",
});
mockLabels(["bug"]);

await action();
expect(core.setOutput).toBeCalledTimes(2);
expect(core.setOutput).toBeCalledWith("status", "success");
expect(core.setOutput).toBeCalledWith("labels", "bug");
});
});

describe("configurable exit code", () => {
Expand Down

0 comments on commit 18f57d7

Please sign in to comment.