mirror of
https://github.com/actions/labeler.git
synced 2025-12-12 12:37:48 +00:00
Merge pull request #150 from actions/fix-format-script-globbing
Fix recursive globbing in our npm `format` script command and run all ts files through prettier 💅
This commit is contained in:
@@ -1,32 +1,32 @@
|
|||||||
export const context = {
|
export const context = {
|
||||||
payload: {
|
payload: {
|
||||||
pull_request: {
|
pull_request: {
|
||||||
number: 123,
|
number: 123
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
repo: {
|
repo: {
|
||||||
owner: "monalisa",
|
owner: "monalisa",
|
||||||
repo: "helloworld",
|
repo: "helloworld"
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const mockApi = {
|
const mockApi = {
|
||||||
issues: {
|
issues: {
|
||||||
addLabels: jest.fn(),
|
addLabels: jest.fn(),
|
||||||
removeLabel: jest.fn(),
|
removeLabel: jest.fn()
|
||||||
},
|
},
|
||||||
paginate: jest.fn(),
|
paginate: jest.fn(),
|
||||||
pulls: {
|
pulls: {
|
||||||
get: jest.fn().mockResolvedValue({}),
|
get: jest.fn().mockResolvedValue({}),
|
||||||
listFiles: {
|
listFiles: {
|
||||||
endpoint: {
|
endpoint: {
|
||||||
merge: jest.fn().mockReturnValue({}),
|
merge: jest.fn().mockReturnValue({})
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
repos: {
|
repos: {
|
||||||
getContents: jest.fn(),
|
getContents: jest.fn()
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const GitHub = jest.fn().mockImplementation(() => mockApi);
|
export const GitHub = jest.fn().mockImplementation(() => mockApi);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { checkGlobs } from '../src/labeler'
|
import { checkGlobs } from "../src/labeler";
|
||||||
|
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
|
|
||||||
@@ -12,15 +12,15 @@ beforeAll(() => {
|
|||||||
|
|
||||||
const matchConfig = [{ any: ["*.txt"] }];
|
const matchConfig = [{ any: ["*.txt"] }];
|
||||||
|
|
||||||
describe('checkGlobs', () => {
|
describe("checkGlobs", () => {
|
||||||
it('returns true when our pattern does match changed files', () => {
|
it("returns true when our pattern does match changed files", () => {
|
||||||
const changedFiles = ["foo.txt", "bar.txt"];
|
const changedFiles = ["foo.txt", "bar.txt"];
|
||||||
const result = checkGlobs(changedFiles, matchConfig);
|
const result = checkGlobs(changedFiles, matchConfig);
|
||||||
|
|
||||||
expect(result).toBeTruthy();
|
expect(result).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns false when our pattern does not match changed files', () => {
|
it("returns false when our pattern does not match changed files", () => {
|
||||||
const changedFiles = ["foo.docx"];
|
const changedFiles = ["foo.docx"];
|
||||||
const result = checkGlobs(changedFiles, matchConfig);
|
const result = checkGlobs(changedFiles, matchConfig);
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ const paginateMock = jest.spyOn(gh, "paginate");
|
|||||||
const getPullMock = jest.spyOn(gh.pulls, "get");
|
const getPullMock = jest.spyOn(gh.pulls, "get");
|
||||||
|
|
||||||
const yamlFixtures = {
|
const yamlFixtures = {
|
||||||
"only_pdfs.yml": fs.readFileSync("__tests__/fixtures/only_pdfs.yml"),
|
"only_pdfs.yml": fs.readFileSync("__tests__/fixtures/only_pdfs.yml")
|
||||||
};
|
};
|
||||||
|
|
||||||
afterAll(() => jest.restoreAllMocks());
|
afterAll(() => jest.restoreAllMocks());
|
||||||
@@ -33,7 +33,7 @@ describe("run", () => {
|
|||||||
owner: "monalisa",
|
owner: "monalisa",
|
||||||
repo: "helloworld",
|
repo: "helloworld",
|
||||||
issue_number: 123,
|
issue_number: 123,
|
||||||
labels: ["touched-a-pdf-file"],
|
labels: ["touched-a-pdf-file"]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ describe("run", () => {
|
|||||||
let mockInput = {
|
let mockInput = {
|
||||||
"repo-token": "foo",
|
"repo-token": "foo",
|
||||||
"configuration-path": "bar",
|
"configuration-path": "bar",
|
||||||
"sync-labels": true,
|
"sync-labels": true
|
||||||
};
|
};
|
||||||
|
|
||||||
jest
|
jest
|
||||||
@@ -62,8 +62,8 @@ describe("run", () => {
|
|||||||
mockGitHubResponseChangedFiles("foo.txt");
|
mockGitHubResponseChangedFiles("foo.txt");
|
||||||
getPullMock.mockResolvedValue(<any>{
|
getPullMock.mockResolvedValue(<any>{
|
||||||
data: {
|
data: {
|
||||||
labels: [{ name: "touched-a-pdf-file" }],
|
labels: [{ name: "touched-a-pdf-file" }]
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
await run();
|
await run();
|
||||||
@@ -74,7 +74,7 @@ describe("run", () => {
|
|||||||
owner: "monalisa",
|
owner: "monalisa",
|
||||||
repo: "helloworld",
|
repo: "helloworld",
|
||||||
issue_number: 123,
|
issue_number: 123,
|
||||||
name: "touched-a-pdf-file",
|
name: "touched-a-pdf-file"
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ describe("run", () => {
|
|||||||
let mockInput = {
|
let mockInput = {
|
||||||
"repo-token": "foo",
|
"repo-token": "foo",
|
||||||
"configuration-path": "bar",
|
"configuration-path": "bar",
|
||||||
"sync-labels": false,
|
"sync-labels": false
|
||||||
};
|
};
|
||||||
|
|
||||||
jest
|
jest
|
||||||
@@ -93,8 +93,8 @@ describe("run", () => {
|
|||||||
mockGitHubResponseChangedFiles("foo.txt");
|
mockGitHubResponseChangedFiles("foo.txt");
|
||||||
getPullMock.mockResolvedValue(<any>{
|
getPullMock.mockResolvedValue(<any>{
|
||||||
data: {
|
data: {
|
||||||
labels: [{ name: "touched-a-pdf-file" }],
|
labels: [{ name: "touched-a-pdf-file" }]
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
await run();
|
await run();
|
||||||
@@ -106,11 +106,11 @@ describe("run", () => {
|
|||||||
|
|
||||||
function usingLabelerConfigYaml(fixtureName: keyof typeof yamlFixtures): void {
|
function usingLabelerConfigYaml(fixtureName: keyof typeof yamlFixtures): void {
|
||||||
reposMock.mockResolvedValue(<any>{
|
reposMock.mockResolvedValue(<any>{
|
||||||
data: { content: yamlFixtures[fixtureName], encoding: "utf8" },
|
data: { content: yamlFixtures[fixtureName], encoding: "utf8" }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function mockGitHubResponseChangedFiles(...files: string[]): void {
|
function mockGitHubResponseChangedFiles(...files: string[]): void {
|
||||||
const returnValue = files.map((f) => ({ filename: f }));
|
const returnValue = files.map(f => ({ filename: f }));
|
||||||
paginateMock.mockReturnValue(<any>returnValue);
|
paginateMock.mockReturnValue(<any>returnValue);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
"main": "lib/main.js",
|
"main": "lib/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc && ncc build lib/main.js",
|
"build": "tsc && ncc build lib/main.js",
|
||||||
"format": "prettier --write **/*.ts",
|
"format": "prettier --write \"**/*.ts\"",
|
||||||
"format-check": "prettier --check **/*.ts",
|
"format-check": "prettier --check \"**/*.ts\"",
|
||||||
"test": "jest"
|
"test": "jest"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
Reference in New Issue
Block a user