Skip to content

Commit

Permalink
Add eslint and fix eslint issues (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
jetersen authored Jul 25, 2022
1 parent b6652ff commit 00fbd39
Show file tree
Hide file tree
Showing 7 changed files with 2,393 additions and 96 deletions.
23 changes: 23 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"env": {
"commonjs": true,
"es6": true,
"jest": true,
"node": true
},
"ignorePatterns": ["**/node_modules/", "coverage/**"],
"extends": [
"eslint:recommended",
"plugin:prettier/recommended",
"plugin:unicorn/recommended"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2022,
"sourceType": "module"
},
"rules": {}
}
2 changes: 1 addition & 1 deletion app/converters.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export function extractUsersAndTeams(orgName, reviewers) {
const split = reviewers.split(/[,\s]/).filter(Boolean);
const split = reviewers.split(/[\s,]/).filter(Boolean);

return {
teams: split.filter((reviewer) => reviewer.includes("/")),
Expand Down
42 changes: 21 additions & 21 deletions app/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export async function addLabel(token, login, repository, labelableId, labels) {
}
);

if (invalidLabels.length || invalidLabels.length) {
if (invalidLabels.length > 0) {
const comment = `I wasn't able to add the following labels: ${invalidLabels.join(
","
)}
Expand All @@ -55,10 +55,10 @@ Check that [the label exists](https://github.com/${login}/${repository}/labels)

await reportError(token, labelableId, comment);
}
} catch (err) {
console.error("Failed to add label", err);
} catch (error) {
console.error("Failed to add label", error);

console.error(JSON.stringify(err.errors));
console.error(JSON.stringify(error.errors));
}
}

Expand Down Expand Up @@ -131,7 +131,7 @@ export async function removeLabel(
}
);

if (invalidLabels.length || invalidLabels.length) {
if (invalidLabels.length > 0) {
const comment = `I wasn't able to remove the following labels: ${invalidLabels.join(
","
)}
Expand All @@ -141,10 +141,10 @@ Check that [the label exists](https://github.com/${login}/${repository}/labels)

await reportError(token, labelableId, comment);
}
} catch (err) {
console.error("Failed to add label", err);
} catch (error) {
console.error("Failed to add label", error);

console.error(JSON.stringify(err.errors));
console.error(JSON.stringify(error.errors));
}
}

Expand Down Expand Up @@ -253,10 +253,10 @@ export async function reopenIssue(token, sourceRepo, issueId) {
},
}
);
} catch (err) {
console.error("Failed to reopen issue", err);
} catch (error) {
console.error("Failed to reopen issue", error);

console.error(JSON.stringify(err.errors));
console.error(JSON.stringify(error.errors));
}
}

Expand Down Expand Up @@ -345,7 +345,7 @@ export async function requestReviewers(
}
);

if (invalidUsers.length || invalidTeams.length) {
if (invalidUsers.length > 0 || invalidTeams.length > 0) {
const invalidReviewers = [...invalidUsers, ...invalidTeams];

const comment = `I wasn't able to request review for the following reviewer(s): ${invalidReviewers.join(
Expand All @@ -357,10 +357,10 @@ Check that the reviewer is spelt right and try again.

await reportError(token, issueId, comment);
}
} catch (err) {
console.error("Failed to request reviewers", err);
} catch (error) {
console.error("Failed to request reviewers", error);

console.error(JSON.stringify(err.errors));
console.error(JSON.stringify(error.errors));
}
}

Expand All @@ -384,10 +384,10 @@ export async function closeIssue(token, sourceRepo, issueId, reason) {
},
}
);
} catch (err) {
console.error("Failed to close issue", err);
} catch (error) {
console.error("Failed to close issue", error);

console.error(JSON.stringify(err.errors));
console.error(JSON.stringify(error.errors));
}
}

Expand Down Expand Up @@ -434,9 +434,9 @@ export async function transferIssue(
},
}
);
} catch (err) {
console.error("Failed to transfer issue", err);
} catch (error) {
console.error("Failed to transfer issue", error);

console.error(JSON.stringify(err.errors));
console.error(JSON.stringify(error.errors));
}
}
8 changes: 4 additions & 4 deletions app/matchers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export function transferMatcher(text) {
return text.match(/\/transfer ([a-zA-Z\d-]+)/);
return text.match(/\/transfer ([\dA-Za-z-]+)/);
}

export function closeMatcher(text) {
Expand All @@ -11,13 +11,13 @@ export function reopenMatcher(text) {
}

export function labelMatcher(text) {
return text.match(/\/label ([a-zA-Z\d-, ]+)/);
return text.match(/\/label ([\sA-Za-z\d-,]+)/);
}

export function removeLabelMatcher(text) {
return text.match(/\/remove-label ([a-zA-Z\d-, ]+)/);
return text.match(/\/remove-label ([\sA-Za-z\d-,]+)/);
}

export function reviewerMatcher(text) {
return text.match(/\/reviewers? ([@a-z/A-Z\d-, ]+)/);
return text.match(/\/reviewers? ([\s/@A-Za-z\d-,]+)/);
}
12 changes: 6 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env node
import { createServer } from "http";
import { createServer } from "node:http";
import { createNodeMiddleware, Webhooks } from "@octokit/webhooks";
import { createAppAuth } from "@octokit/auth-app";

Expand All @@ -8,7 +8,7 @@ import { router } from "./app/router.js";
const verbose = process.env.VERBOSE === "true";

const secret = process.env.WEBHOOK_SECRET;
const port = parseInt(process.env.PORT || "3000", 10);
const port = Number.parseInt(process.env.PORT || "3000", 10);

const webhooks = new Webhooks({
secret,
Expand All @@ -26,10 +26,10 @@ webhooks.on("issue_comment.created", async ({ id, payload }) => {
createServer(
createNodeMiddleware(webhooks, {
// Return 200 for health probes
onUnhandledRequest: (request, res) => {
res.setHeader("Content-Type", "text/plain");
res.write("For webhooks POST to path /api/github/webhooks\n");
res.end();
onUnhandledRequest: (request, response) => {
response.setHeader("Content-Type", "text/plain");
response.write("For webhooks POST to path /api/github/webhooks\n");
response.end();
},
})
).listen(port, () => {
Expand Down
Loading

0 comments on commit 00fbd39

Please sign in to comment.