Skip to content

Commit

Permalink
Add a new pr-number input
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist committed Aug 2, 2022
1 parent 74e99cd commit 983b979
Show file tree
Hide file tree
Showing 5 changed files with 2,653 additions and 180 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ Various inputs are defined in [`action.yml`](action.yml) to let you configure th
| `repo-token` | Token to use to authorize label changes. Typically the GITHUB_TOKEN secret, with `contents:read` and `pull-requests:write` access | N/A |
| `configuration-path` | The path to the label configuration file | `.github/labeler.yml` |
| `sync-labels` | Whether or not to remove labels when matching files are reverted or no longer changed by the PR | `false`
| `pr-number` | Pull request number to label instead of the inferred number from the context |

# Contributions

Expand Down
31 changes: 31 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,37 @@ describe("run", () => {
expect(addLabelsMock).toHaveBeenCalledTimes(0);
expect(removeLabelMock).toHaveBeenCalledTimes(0);
});

it("(with pr-number) adds labels to PRs that match our glob patterns", async () => {
let mockInput = {
"repo-token": "foo",
"configuration-path": "bar",
"pr-number": "789",
};

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

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

await run();

expect(removeLabelMock).toHaveBeenCalledTimes(0);
expect(addLabelsMock).toHaveBeenCalledTimes(1);
expect(addLabelsMock).toHaveBeenCalledWith({
owner: "monalisa",
repo: "helloworld",
issue_number: 789,
labels: ["touched-a-pdf-file"],
});
});
});

function usingLabelerConfigYaml(fixtureName: keyof typeof yamlFixtures): void {
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ inputs:
description: 'Whether or not to remove labels when matching files are reverted'
default: false
required: false
pr-number:
description: 'Pull request number to label instead of the inferred number from the context'
required: false

runs:
using: 'node16'
Expand Down
Loading

0 comments on commit 983b979

Please sign in to comment.