Skip to content

Commit

Permalink
Merge pull request #151 from actions/prettier-2.3.0
Browse files Browse the repository at this point in the history
Update prettier to the latest version and re-prettify everything
  • Loading branch information
pje authored Jun 4, 2021
2 parents ca69a1e + c97a958 commit 8469b2c
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 52 deletions.
20 changes: 10 additions & 10 deletions __mocks__/@actions/github.ts
Original file line number Diff line number Diff line change
@@ -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);
22 changes: 11 additions & 11 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -33,7 +33,7 @@ describe("run", () => {
owner: "monalisa",
repo: "helloworld",
issue_number: 123,
labels: ["touched-a-pdf-file"]
labels: ["touched-a-pdf-file"],
});
});

Expand All @@ -51,7 +51,7 @@ describe("run", () => {
let mockInput = {
"repo-token": "foo",
"configuration-path": "bar",
"sync-labels": true
"sync-labels": true,
};

jest
Expand All @@ -62,8 +62,8 @@ describe("run", () => {
mockGitHubResponseChangedFiles("foo.txt");
getPullMock.mockResolvedValue(<any>{
data: {
labels: [{ name: "touched-a-pdf-file" }]
}
labels: [{ name: "touched-a-pdf-file" }],
},
});

await run();
Expand All @@ -74,15 +74,15 @@ describe("run", () => {
owner: "monalisa",
repo: "helloworld",
issue_number: 123,
name: "touched-a-pdf-file"
name: "touched-a-pdf-file",
});
});

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 = {
"repo-token": "foo",
"configuration-path": "bar",
"sync-labels": false
"sync-labels": false,
};

jest
Expand All @@ -93,8 +93,8 @@ describe("run", () => {
mockGitHubResponseChangedFiles("foo.txt");
getPullMock.mockResolvedValue(<any>{
data: {
labels: [{ name: "touched-a-pdf-file" }]
}
labels: [{ name: "touched-a-pdf-file" }],
},
});

await run();
Expand All @@ -106,11 +106,11 @@ describe("run", () => {

function usingLabelerConfigYaml(fixtureName: keyof typeof yamlFixtures): void {
reposMock.mockResolvedValue(<any>{
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(<any>returnValue);
}
22 changes: 11 additions & 11 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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);
Expand All @@ -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();
});
Expand All @@ -19950,7 +19950,7 @@ function getLabelGlobMapFromObject(configObject) {
function toMatchConfig(config) {
if (typeof config === "string") {
return {
any: [config]
any: [config],
};
}
return config;
Expand Down Expand Up @@ -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)) {
Expand All @@ -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)) {
Expand Down Expand Up @@ -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,
})));
});
}
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
22 changes: 11 additions & 11 deletions src/labeler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -143,7 +143,7 @@ function getLabelGlobMapFromObject(
function toMatchConfig(config: StringOrMatchConfig): MatchConfig {
if (typeof config === "string") {
return {
any: [config]
any: [config],
};
}

Expand Down Expand Up @@ -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)) {
Expand All @@ -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)) {
Expand Down Expand Up @@ -237,7 +237,7 @@ async function addLabels(
owner: github.context.repo.owner,
repo: github.context.repo.repo,
issue_number: prNumber,
labels: labels
labels: labels,
});
}

Expand All @@ -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,
})
)
);
Expand Down

0 comments on commit 8469b2c

Please sign in to comment.