diff --git a/.eslintrc.json b/.eslintrc.json index 8be52d4..0948fef 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -33,6 +33,7 @@ "curly": ["error", "all"], "default-case": 1, "eol-last": ["warn", "always"], + "eqeqeq": ["error", "smart"], "indent": ["warn", 4, { "SwitchCase": 1 }], @@ -55,6 +56,7 @@ "objectsInObjects": true, "arraysInObjects": true }], + "object-shorthand": ["warn", "consistent"], "quotes": ["warn", "double", { "avoidEscape": false }], diff --git a/src/class/issuesComment.ts b/src/class/issuesComment.ts index 804a242..7b30d1a 100644 --- a/src/class/issuesComment.ts +++ b/src/class/issuesComment.ts @@ -27,17 +27,17 @@ export default class IssuesComment { * @returns {Promise} */ public async userPRsComment(): Promise { - if (this.context.payload.comment.body.toLowerCase() == "ready to merge") { + if (this.context.payload.comment.body.toLowerCase() === "ready to merge") { await this.context.octokit.pulls.get({ repo: this.context.payload.repository.name, owner: this.context.payload.repository.owner.login, pull_number: this.context.payload.issue.number }).then(async (res) => { - if (res.data.mergeable_state.toLowerCase() == "clean" || res.data.mergeable == true) { - if (this.context.payload.issue.user.login == this.context.payload.comment.user.login) { + if (res.data.mergeable_state.toLowerCase() === "clean" || res.data.mergeable === true) { + if (this.context.payload.issue.user.login === this.context.payload.comment.user.login) { let i: number; for (i = 0; i < this.context.payload.issue.labels.length; i++) { - if (this.context.payload.issue.labels[i].name == "Approved") { + if (this.context.payload.issue.labels[i].name === "Approved") { console.log("Merging"); await this.context.octokit.pulls.merge({ repo: this.context.payload.repository.name, @@ -53,7 +53,7 @@ export default class IssuesComment { }) ); break; - } else if (this.context.payload.issue.labels[i].name == "Requested Changes") { + } else if (this.context.payload.issue.labels[i].name === "Requested Changes") { console.log("PRs Blocked"); await this.context.octokit.issues.createComment( this.context.issue({ @@ -68,7 +68,7 @@ export default class IssuesComment { } else { return; } - } else if (res.data.mergeable_state.toLowerCase() == "dirty" || res.data.mergeable == false) { + } else if (res.data.mergeable_state.toLowerCase() === "dirty" || res.data.mergeable === false) { await this.context.octokit.issues.createComment( this.context.issue({ body: `Merging blocked because PRs has merge conflict! @${this.context.payload.comment.user.login}` @@ -84,8 +84,8 @@ export default class IssuesComment { }); } - if (this.context.payload.comment.body.toLowerCase() == "merge") { - if (this.context.payload.sender.login == this.context.payload.repository.owner.login) { + if (this.context.payload.comment.body.toLowerCase() === "merge") { + if (this.context.payload.sender.login === this.context.payload.repository.owner.login) { await this.context.octokit.pulls.merge({ repo: this.context.payload.repository.name, owner: this.context.payload.repository.owner.login, @@ -140,8 +140,8 @@ export default class IssuesComment { * @returns {Promise} */ public async botPRsComment(): Promise { - if (this.context.payload.comment.body.toLowerCase() == "merge") { - if (this.context.payload.sender.login == this.context.payload.repository.owner.login) { + if (this.context.payload.comment.body.toLowerCase() === "merge") { + if (this.context.payload.sender.login === this.context.payload.repository.owner.login) { await this.context.octokit.pulls.merge({ repo: this.context.payload.repository.name, owner: this.context.payload.repository.owner.login, diff --git a/src/class/prsOpen.ts b/src/class/prsOpen.ts index a64cbe2..449823b 100644 --- a/src/class/prsOpen.ts +++ b/src/class/prsOpen.ts @@ -98,7 +98,7 @@ export default class PullRequestOpen { */ public async open(): Promise { - if (this.context.payload.sender.login != this.context.payload.repository.owner.login) { + if (this.context.payload.sender.login !== this.context.payload.repository.owner.login) { const propened = this.context.issue({ body: `Hello @${this.context.payload.sender.login} Thank you for submitting Pull Request, please wait for next notification after we review your Pull Request` }); diff --git a/src/class/prsReview.ts b/src/class/prsReview.ts index f3b2c46..617a213 100644 --- a/src/class/prsReview.ts +++ b/src/class/prsReview.ts @@ -68,34 +68,34 @@ export default class PullRequestReview { * @returns {Promise} */ public async userPRs(): Promise { - if (this.context.payload.sender.login == this.context.payload.repository.owner.login) { + if (this.context.payload.sender.login === this.context.payload.repository.owner.login) { // Owner - if (this.context.payload.review.state == "approved") { + if (this.context.payload.review.state === "approved") { const reviewMessage = `@${this.context.payload.pull_request.user.login} your pull request has been approved by @${this.context.payload.review.user.login}, please type \`Ready to merge\` for merging`; - if (this.context.payload.pull_request.labels.find((a) => a.name == "Requested Changes")) { + if (this.context.payload.pull_request.labels.find((a) => a.name === "Requested Changes")) { await this.createReview(reviewMessage, ["Approved"], ["Requested Changes", "Pending"]); } else { await this.createReview(reviewMessage, ["Approved"], ["Pending"]); } - } else if (this.context.payload.review.state == "changes_requested") { + } else if (this.context.payload.review.state === "changes_requested") { const reviewMessage = `Pull request has requested changes by @${this.context.payload.review.user.login}. PING! @${this.context.payload.pull_request.user.login} Please address their comments before I'm merging this PR, thanks!`; - if (this.context.payload.pull_request.labels.find((a) => a.name == "Approved")) { + if (this.context.payload.pull_request.labels.find((a) => a.name === "Approved")) { await this.createReview(reviewMessage, ["Requested Changes"], ["Approved", "Pending"]); } else { await this.createReview(reviewMessage, ["Requested Changes"], ["Pending"]); } } - } else if (this.context.payload.pull_request.author_association == "MEMBER" || this.context.payload.pull_request.author_association == "COLLABORATOR") { - if (this.context.payload.review.state == "approved") { + } else if (this.context.payload.pull_request.author_association === "MEMBER" || this.context.payload.pull_request.author_association === "COLLABORATOR") { + if (this.context.payload.review.state === "approved") { const reviewMessage = `@${this.context.payload.pull_request.user.login} your pull request has been approved by \`[MAINTAINER]\`@${this.context.payload.review.user.login}, please type \`Ready to merge\` for merging`; - if (this.context.payload.pull_request.labels.find((a) => a.name == "Requested Changes")) { + if (this.context.payload.pull_request.labels.find((a) => a.name === "Requested Changes")) { await this.createReview(reviewMessage, ["Approved"], ["Requested Changes", "Pending"]); } else { await this.createReview(reviewMessage, ["Approved"], ["Pending"]); } - } else if (this.context.payload.review.state == "changes_requested") { + } else if (this.context.payload.review.state === "changes_requested") { const reviewMessage = `Pull request has requested changes by @${this.context.payload.review.user.login}. PING! @${this.context.payload.pull_request.user.login} Please address their comments before I'm merging this PR, thanks!`; - if (this.context.payload.pull_request.labels.find((a) => a.name == "Approved")) { + if (this.context.payload.pull_request.labels.find((a) => a.name === "Approved")) { await this.createReview(reviewMessage, ["Requested Changes"], ["Approved", "Pending"]); } else { await this.createReview(reviewMessage, ["Requested Changes"], ["Pending"]); @@ -103,16 +103,16 @@ export default class PullRequestReview { } } else { // Others Approved - if (this.context.payload.review.state == "approved") { + if (this.context.payload.review.state === "approved") { const reviewMessage = `@${this.context.payload.pull_request.user.login} your pull request has been approved by @${this.context.payload.review.user.login}, even though please wait for the \`MAINTAINERS\`/\`CODEOWNERS\` to review`; - if (this.context.payload.pull_request.labels.find((a) => a.name == "Requested Changes")) { + if (this.context.payload.pull_request.labels.find((a) => a.name === "Requested Changes")) { await this.createReview(reviewMessage, ["Others Approved"], ["Requested Changes", "Pending"]); } else { await this.createReview(reviewMessage, ["Others Approved"], ["Pending"]); } - } else if (this.context.payload.review.state == "changes_requested") { + } else if (this.context.payload.review.state === "changes_requested") { const reviewMessage = `Pull request has requested changes by @${this.context.payload.review.user.login}. PING! @${this.context.payload.pull_request.user.login} Please address their comments before I'm merging this PR, thanks!`; - if (this.context.payload.pull_request.labels.find((a) => a.name == "Others Approved")) { + if (this.context.payload.pull_request.labels.find((a) => a.name === "Others Approved")) { await this.createReview(reviewMessage, ["Requested Changes"], ["Others Approved", "Pending"]); } else { await this.createReview(reviewMessage, ["Requested Changes"], ["Pending"]); @@ -127,34 +127,34 @@ export default class PullRequestReview { * @returns {Promise} */ public async botPRs(): Promise { - if (this.context.payload.sender.login == this.context.payload.repository.owner.login) { + if (this.context.payload.sender.login === this.context.payload.repository.owner.login) { // Owner - if (this.context.payload.review.state == "approved") { + if (this.context.payload.review.state === "approved") { const reviewMessage = `@${this.context.payload.pull_request.user.login} Pull request has been approved by \`[OWNER]\`@${this.context.payload.review.user.login}, please type \`Merge\` for merging @${this.context.payload.review.user.login}`; - if (this.context.payload.pull_request.labels.find((a) => a.name == "Requested Changes")) { + if (this.context.payload.pull_request.labels.find((a) => a.name === "Requested Changes")) { await this.createReview(reviewMessage, ["Approved"], ["Requested Changes", "Pending"]); } else { await this.createReview(reviewMessage, ["Approved"], ["Pending"]); } - } else if (this.context.payload.review.state == "changes_requested") { + } else if (this.context.payload.review.state === "changes_requested") { const reviewMessage = `@${this.context.payload.pull_request.user.login} your pull request has requested changes by \`[OWNER]\`@${this.context.payload.review.user.login}. Please address their comments before I'm merging this PR, thanks!`; - if (this.context.payload.pull_request.labels.find((a) => a.name == "Approved")) { + if (this.context.payload.pull_request.labels.find((a) => a.name === "Approved")) { await this.createReview(reviewMessage, ["Requested Changes"], ["Approved", "Pending"]); } else { await this.createReview(reviewMessage, ["Requested Changes"], ["Pending"]); } } - } else if (this.context.payload.pull_request.author_association == "MEMBER" || this.context.payload.pull_request.author_association == "COLLABORATOR") { - if (this.context.payload.review.state == "approved") { + } else if (this.context.payload.pull_request.author_association === "MEMBER" || this.context.payload.pull_request.author_association === "COLLABORATOR") { + if (this.context.payload.review.state === "approved") { const reviewMessage = `@${this.context.payload.pull_request.user.login} Pull request has been approved by \`[MAINTAINER]\`@${this.context.payload.review.user.login}, please type \`Merge\` for merging @${this.context.payload.review.user.login}`; - if (this.context.payload.pull_request.labels.find((a) => a.name == "Requested Changes")) { + if (this.context.payload.pull_request.labels.find((a) => a.name === "Requested Changes")) { await this.createReview(reviewMessage, ["Approved"], ["Requested Changes", "Pending"]); } else { await this.createReview(reviewMessage, ["Approved"], ["Pending"]); } - } else if (this.context.payload.review.state == "changes_requested") { + } else if (this.context.payload.review.state === "changes_requested") { const reviewMessage = `Pull request has requested changes by \`[MAINTAINER]\`@${this.context.payload.review.user.login}. PING! @${this.context.payload.pull_request.user.login} Please address their comments before I"m merging this PR, thanks!`; - if (this.context.payload.pull_request.labels.find((a) => a.name == "Approved")) { + if (this.context.payload.pull_request.labels.find((a) => a.name === "Approved")) { await this.createReview(reviewMessage, ["Requested Changes"], ["Approved", "Pending"]); } else { await this.createReview(reviewMessage, ["Requested Changes"], ["Pending"]); @@ -162,16 +162,16 @@ export default class PullRequestReview { } } else { // Others Approved - if (this.context.payload.review.state == "approved") { + if (this.context.payload.review.state === "approved") { const reviewMessage = `@${this.context.payload.pull_request.user.login} your pull request has been approved by @${this.context.payload.review.user.login}, even though please wait for the \`MAINTAINERS\`/\`CODEOWNERS\` to review`; - if (this.context.payload.pull_request.labels.find((a) => a.name == "Requested Changes")) { + if (this.context.payload.pull_request.labels.find((a) => a.name === "Requested Changes")) { await this.createReview(reviewMessage, ["Others Approved"], ["Requested Changes", "Pending"]); } else { await this.createReview(reviewMessage, ["Others Approved"], ["Pending"]); } - } else if (this.context.payload.review.state == "changes_requested") { + } else if (this.context.payload.review.state === "changes_requested") { const reviewMessage = `Pull request has requested changes by @${this.context.payload.review.user.login}. PING! @${this.context.payload.pull_request.user.login} Please address their comments before I'm merging this PR, thanks!`; - if (this.context.payload.pull_request.labels.find((a) => a.name == "Others Approved")) { + if (this.context.payload.pull_request.labels.find((a) => a.name === "Others Approved")) { await this.createReview(reviewMessage, ["Requested Changes"], ["Others Approved", "Pending"]); } else { await this.createReview(reviewMessage, ["Requested Changes"], ["Pending"]); diff --git a/src/class/prsStale.ts b/src/class/prsStale.ts index a7b9712..e48a851 100644 --- a/src/class/prsStale.ts +++ b/src/class/prsStale.ts @@ -34,8 +34,8 @@ export default class PRsStale { const currentRepo = res.data[i].base.repo.name; const currentOwner = res.data[i].base.repo.owner.login; const currentPRs = res.data[i].number; - if (res.data[i].state.toLowerCase() == "open" && res.data[i].draft == false) { - if (res.data[i].user?.type.toLowerCase() == "user") { + if (res.data[i].state.toLowerCase() === "open" && res.data[i].draft === false) { + if (res.data[i].user?.type.toLowerCase() === "user") { await octokit.rest.pulls.listCommits({ owner: currentOwner, repo: currentRepo, @@ -53,7 +53,7 @@ export default class PRsStale { pull_number: currentPRs, state: "closed" }).then(async (res) => { - if (res.data.labels.find((a) => a.name == "Stale")) { + if (res.data.labels.find((a) => a.name === "Stale")) { await octokit.rest.issues.addLabels({ owner: res.data.base.repo.owner.login, repo: res.data.base.repo.name, @@ -88,7 +88,7 @@ export default class PRsStale { repo: currentRepo, pull_number: currentPRs }).then(async (res) => { - if (res.data.labels.find((a) => a.name == "Stale")) { + if (res.data.labels.find((a) => a.name === "Stale")) { return; } else { const prsReviewers: string[] = []; diff --git a/src/class/push.ts b/src/class/push.ts index 1079cbc..78bf164 100644 --- a/src/class/push.ts +++ b/src/class/push.ts @@ -47,11 +47,11 @@ export default class Push { }).then((res: [getEvent]) => { let i: number; for (i = 0; i < res.length; i++) { - if (res[i].type == "PushEvent") { + if (res[i].type === "PushEvent") { if (arrayActivity.userData.length < 5) { let commitsI: number; for (commitsI = 0; commitsI < res[i].payload.commits.length; commitsI++) { - if (res[i].payload.commits[commitsI].author.name == "Muunatic") { + if (res[i].payload.commits[commitsI].author.name === "Muunatic") { if (arrayActivity.userData.length < 5) { arrayActivity.userData.push({ event: `Commit on [${res[i].payload.commits[commitsI].sha.slice(0, 7)}](https://github.com/${res[i].repo.name}/commit/${res[i].payload.commits[commitsI].sha}) in [${res[i].repo.name}](https://github.com/${res[i].repo.name})` }); } else { @@ -64,9 +64,9 @@ export default class Push { } else { break; } - } else if (res[i].type == "PullRequestEvent") { + } else if (res[i].type === "PullRequestEvent") { if (arrayActivity.userData.length < 5) { - if (res[i].payload.pull_request.user.login == "Muunatic") { + if (res[i].payload.pull_request.user.login === "Muunatic") { arrayActivity.userData.push({ event: `Pull Request on [\#${res[i].payload.pull_request.number.toString()}](https://github.com/${res[i].repo.name}/pull/${res[i].payload.pull_request.number}) in [${res[i].repo.name}](https://github.com/${res[i].repo.name})` }); } else { continue; @@ -82,8 +82,8 @@ export default class Push { return; }); } - if (this.context.payload.repository.owner.login == "Muunatic") { - if (this.context.payload.sender.login == "Muunatic") { + if (this.context.payload.repository.owner.login === "Muunatic") { + if (this.context.payload.sender.login === "Muunatic") { await userActivity(); await this.context.octokit.repos.getContent({ owner: "Muunatic", @@ -106,8 +106,8 @@ export default class Push { return; } }); - } else if (this.context.payload.sender.login == "typeslint-cli[bot]") { - if (this.context.payload.repository.name == "Muunatic") { + } else if (this.context.payload.sender.login === "typeslint-cli[bot]") { + if (this.context.payload.repository.name === "Muunatic") { await octokit.rest.checks.create({ owner: "Muunatic", repo: "Muunatic", diff --git a/src/class/workflowCheck.ts b/src/class/workflowCheck.ts index b802681..2daf35d 100644 --- a/src/class/workflowCheck.ts +++ b/src/class/workflowCheck.ts @@ -27,7 +27,7 @@ export default class WorkflowCheck { * @returns {Promise} */ public async checkCI(): Promise { - if (this.context.payload.workflow_run.conclusion == "failure") { + if (this.context.payload.workflow_run.conclusion === "failure") { await this.context.octokit.issues.addLabels( this.context.issue({ owner: this.context.payload.repository.owner.login, @@ -62,13 +62,13 @@ export default class WorkflowCheck { state: "open" }).then(async (res) => { const prsNumber = res.data.find((a) => a.head.sha === this.context.payload.workflow_run.head_sha)?.number as number; - if (this.context.payload.workflow_run.conclusion == "success") { + if (this.context.payload.workflow_run.conclusion === "success") { await this.context.octokit.pulls.get({ owner: this.context.payload.repository.owner.login, repo: this.context.payload.repository.name, pull_number: prsNumber }).then(async (res) => { - if (res.data.labels.find((a) => a.name == "CI Failed")) { + if (res.data.labels.find((a) => a.name === "CI Failed")) { await this.context.octokit.issues.removeLabel( this.context.issue({ owner: this.context.payload.repository.owner.login, @@ -82,7 +82,7 @@ export default class WorkflowCheck { return; } }); - } else if (this.context.payload.workflow_run.conclusion == "failure") { + } else if (this.context.payload.workflow_run.conclusion === "failure") { console.log("CI Failure!"); await this.context.octokit.issues.addLabels( this.context.issue({ diff --git a/src/index.ts b/src/index.ts index ca6ad48..0e327ce 100644 --- a/src/index.ts +++ b/src/index.ts @@ -30,7 +30,7 @@ module.exports = (app: Probot) => { }); app.on("issue_comment.created", async (context): Promise => { - if (context.payload.comment.user.type == "User") { + if (context.payload.comment.user.type === "User") { switch (context.payload.issue.user.type) { case "User": await new IssuesComment(context).userPRsComment(); @@ -45,7 +45,7 @@ module.exports = (app: Probot) => { }); app.on("issues.closed", async (context): Promise => { - if (context.payload.issue.state_reason == "not_planned") { + if (context.payload.issue.state_reason === "not_planned") { await new IssuesClose(context).invalid(); } else { await new IssuesClose(context).closed(); @@ -53,8 +53,8 @@ module.exports = (app: Probot) => { }); app.on("pull_request.opened", async (context): Promise => { - if (context.payload.sender.type == "User") { - if (context.payload.repository.html_url == "https://github.com/Typeslint/github-AutoResponse") { + if (context.payload.sender.type === "User") { + if (context.payload.repository.html_url === "https://github.com/Typeslint/github-AutoResponse") { await new PullRequestOpen(context).openCore(); } else { await new PullRequestOpen(context).open(); @@ -65,7 +65,7 @@ module.exports = (app: Probot) => { }); app.on("pull_request_review.submitted", async (context): Promise => { - if (context.payload.sender.type == "User") { + if (context.payload.sender.type === "User") { switch (context.payload.pull_request.user.type) { case "User": await new PullRequestReview(context).userPRs(); @@ -80,8 +80,8 @@ module.exports = (app: Probot) => { }); app.on("pull_request.synchronize", async (context): Promise => { - if (context.payload.pull_request.user.type == "User") { - if (context.payload.repository.homepage == "https://github.com/Typeslint/github-AutoResponse") { + if (context.payload.pull_request.user.type === "User") { + if (context.payload.repository.homepage === "https://github.com/Typeslint/github-AutoResponse") { await new PullRequestSynchronize(context).synchronizeCore(); } await new PullRequestSynchronize(context).sync(); @@ -91,8 +91,8 @@ module.exports = (app: Probot) => { }); app.on("workflow_run.completed", async (context): Promise => { - if (context.payload.workflow_run.event == "pull_request") { - if (context.payload.sender.type == "User") { + if (context.payload.workflow_run.event === "pull_request") { + if (context.payload.sender.type === "User") { await new WorkflowCheck(context).checkUserCI(); } else { await new WorkflowCheck(context).checkCI();