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

Allow labels to be provided one per line in input #59

Merged
merged 1 commit into from
Jun 17, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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