diff --git a/__mocks__/@actions/github.ts b/__mocks__/@actions/github.ts index d3da92e97..5ff9a868f 100644 --- a/__mocks__/@actions/github.ts +++ b/__mocks__/@actions/github.ts @@ -1,32 +1,32 @@ export const context = { payload: { pull_request: { - number: 123 - } + number: 123, + }, }, repo: { owner: "monalisa", - repo: "helloworld" - } + repo: "helloworld", + }, }; const mockApi = { issues: { addLabels: jest.fn(), - removeLabel: jest.fn() + removeLabel: jest.fn(), }, paginate: jest.fn(), pulls: { get: jest.fn().mockResolvedValue({}), listFiles: { endpoint: { - merge: jest.fn().mockReturnValue({}) - } - } + merge: jest.fn().mockReturnValue({}), + }, + }, }, repos: { - getContents: jest.fn() - } + getContents: jest.fn(), + }, }; export const GitHub = jest.fn().mockImplementation(() => mockApi); diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 58c578f6d..f4e895d97 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -15,7 +15,7 @@ const paginateMock = jest.spyOn(gh, "paginate"); const getPullMock = jest.spyOn(gh.pulls, "get"); 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()); @@ -33,7 +33,7 @@ describe("run", () => { owner: "monalisa", repo: "helloworld", issue_number: 123, - labels: ["touched-a-pdf-file"] + labels: ["touched-a-pdf-file"], }); }); @@ -51,7 +51,7 @@ describe("run", () => { let mockInput = { "repo-token": "foo", "configuration-path": "bar", - "sync-labels": true + "sync-labels": true, }; jest @@ -62,8 +62,8 @@ describe("run", () => { mockGitHubResponseChangedFiles("foo.txt"); getPullMock.mockResolvedValue({ data: { - labels: [{ name: "touched-a-pdf-file" }] - } + labels: [{ name: "touched-a-pdf-file" }], + }, }); await run(); @@ -74,7 +74,7 @@ describe("run", () => { owner: "monalisa", repo: "helloworld", issue_number: 123, - name: "touched-a-pdf-file" + name: "touched-a-pdf-file", }); }); @@ -82,7 +82,7 @@ describe("run", () => { let mockInput = { "repo-token": "foo", "configuration-path": "bar", - "sync-labels": false + "sync-labels": false, }; jest @@ -93,8 +93,8 @@ describe("run", () => { mockGitHubResponseChangedFiles("foo.txt"); getPullMock.mockResolvedValue({ data: { - labels: [{ name: "touched-a-pdf-file" }] - } + labels: [{ name: "touched-a-pdf-file" }], + }, }); await run(); @@ -106,11 +106,11 @@ describe("run", () => { function usingLabelerConfigYaml(fixtureName: keyof typeof yamlFixtures): void { reposMock.mockResolvedValue({ - data: { content: yamlFixtures[fixtureName], encoding: "utf8" } + data: { content: yamlFixtures[fixtureName], encoding: "utf8" }, }); } function mockGitHubResponseChangedFiles(...files: string[]): void { - const returnValue = files.map(f => ({ filename: f })); + const returnValue = files.map((f) => ({ filename: f })); paginateMock.mockReturnValue(returnValue); } diff --git a/dist/index.js b/dist/index.js index 597f5e1a1..1177ff6e3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -19859,7 +19859,7 @@ function run() { const { data: pullRequest } = yield client.pulls.get({ owner: github.context.repo.owner, repo: github.context.repo.repo, - pull_number: prNumber + pull_number: prNumber, }); core.debug(`fetching changed files for pr #${prNumber}`); const changedFiles = yield getChangedFiles(client, prNumber); @@ -19871,7 +19871,7 @@ function run() { if (checkGlobs(changedFiles, globs)) { labels.push(label); } - else if (pullRequest.labels.find(l => l.name === label)) { + else if (pullRequest.labels.find((l) => l.name === label)) { labelsToRemove.push(label); } } @@ -19901,10 +19901,10 @@ function getChangedFiles(client, prNumber) { const listFilesOptions = client.pulls.listFiles.endpoint.merge({ owner: github.context.repo.owner, repo: github.context.repo.repo, - pull_number: prNumber + pull_number: prNumber, }); const listFilesResponse = yield client.paginate(listFilesOptions); - const changedFiles = listFilesResponse.map(f => f.filename); + const changedFiles = listFilesResponse.map((f) => f.filename); core.debug("found changed files:"); for (const file of changedFiles) { core.debug(" " + file); @@ -19927,7 +19927,7 @@ function fetchContent(client, repoPath) { owner: github.context.repo.owner, repo: github.context.repo.repo, path: repoPath, - ref: github.context.sha + ref: github.context.sha, }); return Buffer.from(response.data.content, response.data.encoding).toString(); }); @@ -19950,7 +19950,7 @@ function getLabelGlobMapFromObject(configObject) { function toMatchConfig(config) { if (typeof config === "string") { return { - any: [config] + any: [config], }; } return config; @@ -19983,7 +19983,7 @@ function isMatch(changedFile, matchers) { } // equivalent to "Array.some()" but expanded for debugging and clarity function checkAny(changedFiles, globs) { - const matchers = globs.map(g => new minimatch_1.Minimatch(g)); + const matchers = globs.map((g) => new minimatch_1.Minimatch(g)); core.debug(` checking "any" patterns`); for (const changedFile of changedFiles) { if (isMatch(changedFile, matchers)) { @@ -19996,7 +19996,7 @@ function checkAny(changedFiles, globs) { } // equivalent to "Array.every()" but expanded for debugging and clarity function checkAll(changedFiles, globs) { - const matchers = globs.map(g => new minimatch_1.Minimatch(g)); + const matchers = globs.map((g) => new minimatch_1.Minimatch(g)); core.debug(` checking "all" patterns`); for (const changedFile of changedFiles) { if (!isMatch(changedFile, matchers)) { @@ -20026,17 +20026,17 @@ function addLabels(client, prNumber, labels) { owner: github.context.repo.owner, repo: github.context.repo.repo, issue_number: prNumber, - labels: labels + labels: labels, }); }); } function removeLabels(client, prNumber, labels) { return __awaiter(this, void 0, void 0, function* () { - yield Promise.all(labels.map(label => client.issues.removeLabel({ + yield Promise.all(labels.map((label) => client.issues.removeLabel({ owner: github.context.repo.owner, repo: github.context.repo.repo, issue_number: prNumber, - name: label + name: label, }))); }); } diff --git a/package-lock.json b/package-lock.json index 9393a688e..c0fb65ade 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23,7 +23,7 @@ "@vercel/ncc": "^0.23.0", "jest": "^24.8.0", "jest-circus": "^24.7.1", - "prettier": "^1.17.1", + "prettier": "^2.3.0", "ts-jest": "^24.0.2", "typescript": "^3.5.1" } @@ -5013,15 +5013,15 @@ } }, "node_modules/prettier": { - "version": "1.19.1", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz", - "integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==", + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.3.0.tgz", + "integrity": "sha512-kXtO4s0Lz/DW/IJ9QdWhAf7/NmPWQXkFr/r/WkR3vyI+0v8amTDxiaQSLzs8NBlytfLWX/7uQUMIW677yLKl4w==", "dev": true, "bin": { "prettier": "bin-prettier.js" }, "engines": { - "node": ">=4" + "node": ">=10.13.0" } }, "node_modules/pretty-format": { @@ -10536,9 +10536,9 @@ "dev": true }, "prettier": { - "version": "1.19.1", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz", - "integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==", + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.3.0.tgz", + "integrity": "sha512-kXtO4s0Lz/DW/IJ9QdWhAf7/NmPWQXkFr/r/WkR3vyI+0v8amTDxiaQSLzs8NBlytfLWX/7uQUMIW677yLKl4w==", "dev": true }, "pretty-format": { diff --git a/package.json b/package.json index c443826fc..c2eb4a7a5 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "@vercel/ncc": "^0.23.0", "jest": "^24.8.0", "jest-circus": "^24.7.1", - "prettier": "^1.17.1", + "prettier": "^2.3.0", "ts-jest": "^24.0.2", "typescript": "^3.5.1" } diff --git a/src/labeler.ts b/src/labeler.ts index f7054a4df..a81d6850f 100644 --- a/src/labeler.ts +++ b/src/labeler.ts @@ -27,7 +27,7 @@ export async function run() { const { data: pullRequest } = await client.pulls.get({ owner: github.context.repo.owner, repo: github.context.repo.repo, - pull_number: prNumber + pull_number: prNumber, }); core.debug(`fetching changed files for pr #${prNumber}`); @@ -43,7 +43,7 @@ export async function run() { core.debug(`processing ${label}`); if (checkGlobs(changedFiles, globs)) { labels.push(label); - } else if (pullRequest.labels.find(l => l.name === label)) { + } else if (pullRequest.labels.find((l) => l.name === label)) { labelsToRemove.push(label); } } @@ -77,11 +77,11 @@ async function getChangedFiles( const listFilesOptions = client.pulls.listFiles.endpoint.merge({ owner: github.context.repo.owner, repo: github.context.repo.repo, - pull_number: prNumber + pull_number: prNumber, }); const listFilesResponse = await client.paginate(listFilesOptions); - const changedFiles = listFilesResponse.map(f => f.filename); + const changedFiles = listFilesResponse.map((f) => f.filename); core.debug("found changed files:"); for (const file of changedFiles) { @@ -115,7 +115,7 @@ async function fetchContent( owner: github.context.repo.owner, repo: github.context.repo.repo, path: repoPath, - ref: github.context.sha + ref: github.context.sha, }); return Buffer.from(response.data.content, response.data.encoding).toString(); @@ -143,7 +143,7 @@ function getLabelGlobMapFromObject( function toMatchConfig(config: StringOrMatchConfig): MatchConfig { if (typeof config === "string") { return { - any: [config] + any: [config], }; } @@ -184,7 +184,7 @@ function isMatch(changedFile: string, matchers: IMinimatch[]): boolean { // equivalent to "Array.some()" but expanded for debugging and clarity function checkAny(changedFiles: string[], globs: string[]): boolean { - const matchers = globs.map(g => new Minimatch(g)); + const matchers = globs.map((g) => new Minimatch(g)); core.debug(` checking "any" patterns`); for (const changedFile of changedFiles) { if (isMatch(changedFile, matchers)) { @@ -199,7 +199,7 @@ function checkAny(changedFiles: string[], globs: string[]): boolean { // equivalent to "Array.every()" but expanded for debugging and clarity function checkAll(changedFiles: string[], globs: string[]): boolean { - const matchers = globs.map(g => new Minimatch(g)); + const matchers = globs.map((g) => new Minimatch(g)); core.debug(` checking "all" patterns`); for (const changedFile of changedFiles) { if (!isMatch(changedFile, matchers)) { @@ -237,7 +237,7 @@ async function addLabels( owner: github.context.repo.owner, repo: github.context.repo.repo, issue_number: prNumber, - labels: labels + labels: labels, }); } @@ -247,12 +247,12 @@ async function removeLabels( labels: string[] ) { await Promise.all( - labels.map(label => + labels.map((label) => client.issues.removeLabel({ owner: github.context.repo.owner, repo: github.context.repo.repo, issue_number: prNumber, - name: label + name: label, }) ) );