Implement dot option

This commit is contained in:
Alexander Kachkaev
2022-02-04 13:26:54 +00:00
parent 3194b4b6ce
commit b0d9292064
5 changed files with 109 additions and 27 deletions

View File

@@ -18,10 +18,24 @@ const yamlFixtures = {
"only_pdfs.yml": fs.readFileSync("__tests__/fixtures/only_pdfs.yml"),
};
const configureInput = (
mockInput: Partial<{
"repo-token": string;
"configuration-path": string;
"sync-labels": boolean;
dot: boolean;
}>
) => {
jest
.spyOn(core, "getInput")
.mockImplementation((name: string, ...opts) => mockInput[name]);
};
afterAll(() => jest.restoreAllMocks());
describe("run", () => {
it("adds labels to PRs that match our glob patterns", async () => {
it("(with dot: false) adds labels to PRs that match our glob patterns", async () => {
configureInput({});
usingLabelerConfigYaml("only_pdfs.yml");
mockGitHubResponseChangedFiles("foo.pdf");
@@ -37,7 +51,36 @@ describe("run", () => {
});
});
it("does not add labels to PRs that do not match our glob patterns", async () => {
it("(with dot: true) adds labels to PRs that match our glob patterns", async () => {
configureInput({ dot: true });
usingLabelerConfigYaml("only_pdfs.yml");
mockGitHubResponseChangedFiles(".foo.pdf");
await run();
expect(removeLabelMock).toHaveBeenCalledTimes(0);
expect(addLabelsMock).toHaveBeenCalledTimes(1);
expect(addLabelsMock).toHaveBeenCalledWith({
owner: "monalisa",
repo: "helloworld",
issue_number: 123,
labels: ["touched-a-pdf-file"],
});
});
it("(with dot: false) does not add labels to PRs that do not match our glob patterns", async () => {
configureInput({});
usingLabelerConfigYaml("only_pdfs.yml");
mockGitHubResponseChangedFiles(".foo.pdf");
await run();
expect(removeLabelMock).toHaveBeenCalledTimes(0);
expect(addLabelsMock).toHaveBeenCalledTimes(0);
});
it("(with dot: true) does not add labels to PRs that do not match our glob patterns", async () => {
configureInput({ dot: true });
usingLabelerConfigYaml("only_pdfs.yml");
mockGitHubResponseChangedFiles("foo.txt");
@@ -48,15 +91,11 @@ describe("run", () => {
});
it("(with sync-labels: true) it deletes preexisting PR labels that no longer match the glob pattern", async () => {
let mockInput = {
configureInput({
"repo-token": "foo",
"configuration-path": "bar",
"sync-labels": true,
};
jest
.spyOn(core, "getInput")
.mockImplementation((name: string, ...opts) => mockInput[name]);
});
usingLabelerConfigYaml("only_pdfs.yml");
mockGitHubResponseChangedFiles("foo.txt");
@@ -79,15 +118,11 @@ describe("run", () => {
});
it("(with sync-labels: false) it issues no delete calls even when there are preexisting PR labels that no longer match the glob pattern", async () => {
let mockInput = {
configureInput({
"repo-token": "foo",
"configuration-path": "bar",
"sync-labels": false,
};
jest
.spyOn(core, "getInput")
.mockImplementation((name: string, ...opts) => mockInput[name]);
});
usingLabelerConfigYaml("only_pdfs.yml");
mockGitHubResponseChangedFiles("foo.txt");