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

Fix 'sync-labels' setting #113

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 26 additions & 2 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe("run", () => {
let mockInput = {
"repo-token": "foo",
"configuration-path": "bar",
"sync-labels": true,
"sync-labels": "true",
};

jest
Expand Down Expand Up @@ -82,7 +82,31 @@ describe("run", () => {
let mockInput = {
"repo-token": "foo",
"configuration-path": "bar",
"sync-labels": false,
"sync-labels": "false",
};

jest
.spyOn(core, "getInput")
.mockImplementation((name: string, ...opts) => mockInput[name]);

usingLabelerConfigYaml("only_pdfs.yml");
mockGitHubResponseChangedFiles("foo.txt");
getPullMock.mockResolvedValue(<any>{
data: {
labels: [{ name: "touched-a-pdf-file" }],
},
});

await run();

expect(addLabelsMock).toHaveBeenCalledTimes(0);
expect(removeLabelMock).toHaveBeenCalledTimes(0);
});

it("(with sync-labels not specified) it behaves like sync-labels: false", async () => {
let mockInput = {
"repo-token": "foo",
"configuration-path": "bar",
};

jest
Expand Down
3 changes: 2 additions & 1 deletion src/labeler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export async function run() {
try {
const token = core.getInput("repo-token", { required: true });
const configPath = core.getInput("configuration-path", { required: true });
const syncLabels = !!core.getInput("sync-labels", { required: false });
const syncLabels =
core.getInput("sync-labels", { required: false }) === "true";
Comment on lines +18 to +19
Copy link
Contributor

Choose a reason for hiding this comment

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

We can use the getBooleanInput core function to parse a boolean input:

Suggested change
const syncLabels =
core.getInput("sync-labels", { required: false }) === "true";
const syncLabels = core.getBooleanInput('sync-labels');

Copy link
Contributor

Choose a reason for hiding this comment

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

The problem with using getBooleanInput is that it will reject an empty string argument, which will break everyone currently using the workaround of setting sync-labels: ''. That's why in #480 (which yes, is a duplicate) I did something more complex to get around that. While that's still technically a breaking change, it's unlikely to break anyone who wasn't already broken.


const prNumber = getPrNumber();
if (!prNumber) {
Expand Down