diff --git a/eslint.config.ts b/eslint.config.ts new file mode 100644 index 0000000..4ca2802 --- /dev/null +++ b/eslint.config.ts @@ -0,0 +1,136 @@ +import { defineConfig } from "eslint/config"; +import eslint from "@eslint/js"; +import tseslint, { parser, plugin } from "typescript-eslint"; +import stylistic from "@stylistic/eslint-plugin"; + +export default defineConfig( + { + files: ["**/*.ts"], + languageOptions: { + ecmaVersion: 15, + parser: parser, + parserOptions: { + ecmaVersion: 15, + sourceType: "module", + project: true + } + }, + plugins: { + "@typescript-eslint": plugin, + "@stylistic": stylistic + }, + extends: [ + eslint.configs.recommended, + tseslint.configs.recommended, + tseslint.configs.recommendedTypeChecked + ], + rules: { + "camelcase": ["warn", { + "properties": "never", + "ignoreImports": true + }], + "curly": ["error", "all"], + "default-case": 1, + "eqeqeq": ["error", "smart"], + "no-unreachable": 2, + "no-useless-escape": 0, + "sort-imports": ["warn", { + "ignoreCase": false, + "ignoreDeclarationSort": true + }], + "@stylistic/arrow-parens": ["warn", "always"], + "@stylistic/brace-style": ["warn", "1tbs"], + "@stylistic/comma-dangle": ["error", "never"], + "@stylistic/comma-spacing": ["warn", { + "after": true, + "before": false + }], + "@stylistic/comma-style": ["warn", "last"], + "@stylistic/eol-last": ["warn", "always"], + "@stylistic/indent": ["warn", 4, { + "SwitchCase": 1 + }], + "@stylistic/key-spacing": ["warn", { + "mode": "strict" + }], + "@stylistic/keyword-spacing": ["warn", { + "after": true, + "before": true + }], + "@stylistic/lines-between-class-members": ["warn", "always"], + "@stylistic/no-extra-semi": 2, + "@stylistic/no-multi-spaces": 1, + "@stylistic/no-multiple-empty-lines": ["warn", { + "max": 1 + }], + "@stylistic/no-tabs": 1, + "@stylistic/no-trailing-spaces": 1, + "@stylistic/object-curly-spacing": ["error", "always", { + "arraysInObjects": true, + "objectsInObjects": true + }], + "@stylistic/quotes": ["warn", "double", { + "avoidEscape": false + }], + "@stylistic/semi": 2, + "@stylistic/semi-style": ["warn", "last"], + "@stylistic/member-delimiter-style": ["warn", { + "multiline": { + "delimiter": "semi", + "requireLast": true + }, + "singleline": { + "delimiter": "semi", + "requireLast": false + }, + "multilineDetection": "brackets" + }], + "@typescript-eslint/naming-convention": ["warn", + { + "selector": "default", + "format": ["camelCase"] + }, + { + "selector": "classProperty", + "modifiers": ["private"], + "format": ["camelCase"], + "leadingUnderscore": "require" + }, + { + "selector": "property", + "format": null + }, + { + "selector": "import", + "format": ["camelCase", "PascalCase"] + }, + { + "selector": "memberLike", + "format": ["camelCase"] + }, + { + "selector": "variableLike", + "format": ["camelCase"] + }, + { + "selector": "typeLike", + "format": ["PascalCase"] + } + ], + "@typescript-eslint/explicit-function-return-type": ["warn", { + "allowExpressions": true + }], + "@typescript-eslint/no-unnecessary-condition": 2, + "@typescript-eslint/no-unused-expressions": 0, + "@typescript-eslint/no-unused-vars": 2, + "@typescript-eslint/no-require-imports": 2, + "@typescript-eslint/no-var-requires": 1 + } + }, + { + ignores: [ + "node_modules", + "dist" + ] + } +); diff --git a/src/class/issuesClose.ts b/src/class/issuesClose.ts index daa6b32..973ca9b 100644 --- a/src/class/issuesClose.ts +++ b/src/class/issuesClose.ts @@ -1,4 +1,4 @@ -import Context from "../index"; +import { Context } from "../index.js"; /** * @class @@ -11,14 +11,14 @@ export default class IssuesClose { * @private * @type Context<"issues.closed"> */ - private context: Context<"issues.closed">; + private _context: Context<"issues.closed">; /** * @constructor * @param {Context<"issues.closed">} context */ constructor(context: Context<"issues.closed">) { - this.context = context; + this._context = context; } /** @@ -27,18 +27,18 @@ export default class IssuesClose { * @returns {Promise} */ public async closed(): Promise { - const issueClosed = this.context.issue({ - body: `Issue closed by @${this.context.payload.sender.login}.` + const issueClosed = this._context.issue({ + body: `Issue closed by @${this._context.payload.sender.login}.` }); console.log("Issues closed"); - await this.context.octokit.issues.addLabels( - this.context.issue({ + await this._context.octokit.issues.addLabels( + this._context.issue({ labels: ["Closed"] }) ); - await this.context.octokit.issues.createComment(issueClosed); - await this.context.octokit.issues.removeLabel( - this.context.issue({ + await this._context.octokit.issues.createComment(issueClosed); + await this._context.octokit.issues.removeLabel( + this._context.issue({ name: "Pending" }) ); @@ -50,25 +50,25 @@ export default class IssuesClose { * @returns {Promise} */ public async invalid(): Promise { - const issueClosed = this.context.issue({ - body: `Issue closed as invalid by @${this.context.payload.sender.login}.` + const issueClosed = this._context.issue({ + body: `Issue closed as invalid by @${this._context.payload.sender.login}.` }); console.log("Issues closed"); - await this.context.octokit.issues.addLabels( - this.context.issue({ + await this._context.octokit.issues.addLabels( + this._context.issue({ labels: ["Closed", "Invalid"] }) ); - await this.context.octokit.issues.createComment(issueClosed); - await this.context.octokit.issues.removeLabel( - this.context.issue({ + await this._context.octokit.issues.createComment(issueClosed); + await this._context.octokit.issues.removeLabel( + this._context.issue({ name: "Pending" }) ); - await this.context.octokit.issues.lock({ - owner: this.context.payload.repository.owner.login, - repo: this.context.payload.repository.name, - issue_number: this.context.payload.issue.number, + await this._context.octokit.issues.lock({ + owner: this._context.payload.repository.owner.login, + repo: this._context.payload.repository.name, + issue_number: this._context.payload.issue.number, lock_reason: "off-topic" }); } diff --git a/src/class/issuesComment.ts b/src/class/issuesComment.ts index 7b30d1a..cf86ae9 100644 --- a/src/class/issuesComment.ts +++ b/src/class/issuesComment.ts @@ -1,4 +1,4 @@ -import Context from "../index"; +import { Context } from "../index.js"; /** * @class @@ -11,14 +11,14 @@ export default class IssuesComment { * @private * @type Context<"issue_comment.created"> */ - private context: Context<"issue_comment.created">; + private _context: Context<"issue_comment.created">; /** * @constructor * @param {Context<"issue_comment.created">} context */ constructor(context: Context<"issue_comment.created">) { - this.context = context; + this._context = context; } /** @@ -27,37 +27,37 @@ export default class IssuesComment { * @returns {Promise} */ public async userPRsComment(): Promise { - 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 + 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 (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") { + for (i = 0; i < this._context.payload.issue.labels.length; i++) { + if (this._context.payload.issue.labels[i].name === "Approved") { console.log("Merging"); - await this.context.octokit.pulls.merge({ - repo: this.context.payload.repository.name, - owner: this.context.payload.repository.owner.login, - pull_number: this.context.payload.issue.number, - commit_title: `Merge PR #${this.context.payload.issue.number} ${this.context.payload.issue.title}`, - commit_message: this.context.payload.issue.title + await this._context.octokit.pulls.merge({ + repo: this._context.payload.repository.name, + owner: this._context.payload.repository.owner.login, + pull_number: this._context.payload.issue.number, + commit_title: `Merge PR #${this._context.payload.issue.number} ${this._context.payload.issue.title}`, + commit_message: this._context.payload.issue.title }); console.log("Merged!"); - await this.context.octokit.issues.createComment( - this.context.issue({ - body: `Merged by ${this.context.payload.comment.user.login}!` + await this._context.octokit.issues.createComment( + this._context.issue({ + body: `Merged by ${this._context.payload.comment.user.login}!` }) ); 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({ - body: `Merging blocked because PRs has requested changes! @${this.context.payload.comment.user.login}` + await this._context.octokit.issues.createComment( + this._context.issue({ + body: `Merging blocked because PRs has requested changes! @${this._context.payload.comment.user.login}` }) ); break; @@ -69,14 +69,14 @@ export default class IssuesComment { return; } } 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}` + await this._context.octokit.issues.createComment( + this._context.issue({ + body: `Merging blocked because PRs has merge conflict! @${this._context.payload.comment.user.login}` }) ); } else { - await this.context.octokit.issues.createComment( - this.context.issue({ + await this._context.octokit.issues.createComment( + this._context.issue({ body: "We apologize for the inconvenience, but it seems that Automaton processes are currently unable to proceed with merging your commit. Please wait for a moment and try merging it again." }) ); @@ -84,48 +84,48 @@ export default class IssuesComment { }); } - 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, - pull_number: this.context.payload.issue.number, - commit_title: `Merge PR #${this.context.payload.issue.number} ${this.context.payload.issue.title}`, - commit_message: this.context.payload.issue.title + 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, + pull_number: this._context.payload.issue.number, + commit_title: `Merge PR #${this._context.payload.issue.number} ${this._context.payload.issue.title}`, + commit_message: this._context.payload.issue.title }); console.log("Merged!"); - await this.context.octokit.issues.removeLabel( - this.context.issue({ + await this._context.octokit.issues.removeLabel( + this._context.issue({ name: "Pending" }) ); - await this.context.octokit.issues.createComment( - this.context.issue({ - body: `Merged by \`[OWNER]\`${this.context.payload.comment.user.login}!` + await this._context.octokit.issues.createComment( + this._context.issue({ + body: `Merged by \`[OWNER]\`${this._context.payload.comment.user.login}!` }) ); - await this.context.octokit.issues.addLabels( - this.context.issue({ + await this._context.octokit.issues.addLabels( + this._context.issue({ labels: ["Owner Merge"] }) ); - } else if (this.context.payload.issue.author_association === "MEMBER" || this.context.payload.issue.author_association === "COLLABORATOR") { - await this.context.octokit.pulls.merge({ - repo: this.context.payload.repository.name, - owner: this.context.payload.repository.owner.login, - pull_number: this.context.payload.issue.number, - commit_title: `Merge PR #${this.context.payload.issue.number} ${this.context.payload.issue.title}`, - commit_message: this.context.payload.issue.title + } else if (this._context.payload.issue.author_association === "MEMBER" || this._context.payload.issue.author_association === "COLLABORATOR") { + await this._context.octokit.pulls.merge({ + repo: this._context.payload.repository.name, + owner: this._context.payload.repository.owner.login, + pull_number: this._context.payload.issue.number, + commit_title: `Merge PR #${this._context.payload.issue.number} ${this._context.payload.issue.title}`, + commit_message: this._context.payload.issue.title }); console.log("Merged!"); - await this.context.octokit.issues.removeLabel( - this.context.issue({ + await this._context.octokit.issues.removeLabel( + this._context.issue({ name: "Pending" }) ); - await this.context.octokit.issues.createComment( - this.context.issue({ - body: `Merged by \`[MAINTAINER]\`${this.context.payload.comment.user.login}!` + await this._context.octokit.issues.createComment( + this._context.issue({ + body: `Merged by \`[MAINTAINER]\`${this._context.payload.comment.user.login}!` }) ); } else { @@ -140,48 +140,48 @@ 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) { - await this.context.octokit.pulls.merge({ - repo: this.context.payload.repository.name, - owner: this.context.payload.repository.owner.login, - pull_number: this.context.payload.issue.number, - commit_title: `Merge PR #${this.context.payload.issue.number} ${this.context.payload.issue.title}`, - commit_message: this.context.payload.issue.title + 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, + pull_number: this._context.payload.issue.number, + commit_title: `Merge PR #${this._context.payload.issue.number} ${this._context.payload.issue.title}`, + commit_message: this._context.payload.issue.title }); console.log("Merged!"); - await this.context.octokit.issues.removeLabel( - this.context.issue({ + await this._context.octokit.issues.removeLabel( + this._context.issue({ name: "Pending" }) ); - await this.context.octokit.issues.createComment( - this.context.issue({ - body: `Merged by \`[OWNER]\`${this.context.payload.comment.user.login}!` + await this._context.octokit.issues.createComment( + this._context.issue({ + body: `Merged by \`[OWNER]\`${this._context.payload.comment.user.login}!` }) ); - await this.context.octokit.issues.addLabels( - this.context.issue({ + await this._context.octokit.issues.addLabels( + this._context.issue({ labels: ["Owner Merge"] }) ); - } else if (this.context.payload.issue.author_association === "MEMBER" || this.context.payload.issue.author_association === "COLLABORATOR") { - await this.context.octokit.pulls.merge({ - repo: this.context.payload.repository.name, - owner: this.context.payload.repository.owner.login, - pull_number: this.context.payload.issue.number, - commit_title: `Merge PR #${this.context.payload.issue.number} ${this.context.payload.issue.title}`, - commit_message: this.context.payload.issue.title + } else if (this._context.payload.issue.author_association === "MEMBER" || this._context.payload.issue.author_association === "COLLABORATOR") { + await this._context.octokit.pulls.merge({ + repo: this._context.payload.repository.name, + owner: this._context.payload.repository.owner.login, + pull_number: this._context.payload.issue.number, + commit_title: `Merge PR #${this._context.payload.issue.number} ${this._context.payload.issue.title}`, + commit_message: this._context.payload.issue.title }); console.log("Merged!"); - await this.context.octokit.issues.removeLabel( - this.context.issue({ + await this._context.octokit.issues.removeLabel( + this._context.issue({ name: "Pending" }) ); - await this.context.octokit.issues.createComment( - this.context.issue({ - body: `Merged by \`[MAINTAINER]\`${this.context.payload.comment.user.login}!` + await this._context.octokit.issues.createComment( + this._context.issue({ + body: `Merged by \`[MAINTAINER]\`${this._context.payload.comment.user.login}!` }) ); } else { diff --git a/src/class/issuesOpen.ts b/src/class/issuesOpen.ts index 2ea6046..1834c73 100644 --- a/src/class/issuesOpen.ts +++ b/src/class/issuesOpen.ts @@ -1,4 +1,4 @@ -import Context from "../index"; +import { Context } from "../index.js"; /** * @class @@ -11,14 +11,14 @@ export default class IssuesOpen { * @private * @type Context<"issues.opened"> */ - private context: Context<"issues.opened">; + private _context: Context<"issues.opened">; /** * @constructor * @param {Context<"issues.opened">} context */ constructor(context: Context<"issues.opened">) { - this.context = context; + this._context = context; } /** @@ -27,17 +27,17 @@ export default class IssuesOpen { * @returns {Promise} */ public async open(): Promise { - if (this.context.payload.sender.login !== "Muunatic") { - const issueComment = this.context.issue({ - body: `Hello @${this.context.payload.sender.login} Thank you for submitting Issue, please wait for next notification after we review your Issue.` + if (this._context.payload.sender.login !== "Muunatic") { + const issueComment = this._context.issue({ + body: `Hello @${this._context.payload.sender.login} Thank you for submitting Issue, please wait for next notification after we review your Issue.` }); console.log("Issues created"); - await this.context.octokit.issues.addLabels( - this.context.issue({ + await this._context.octokit.issues.addLabels( + this._context.issue({ labels: ["Pending"] }) ); - await this.context.octokit.issues.createComment(issueComment); + await this._context.octokit.issues.createComment(issueComment); } else { return; } diff --git a/src/class/prsOpen.ts b/src/class/prsOpen.ts index 466287d..a5cf8d9 100644 --- a/src/class/prsOpen.ts +++ b/src/class/prsOpen.ts @@ -1,4 +1,4 @@ -import Context, { octokit } from "../index"; +import { Context, octokit } from "../index.js"; /** * @class @@ -11,14 +11,14 @@ export default class PullRequestOpen { * @private * @type Context<"pull_request.opened"> */ - private context: Context<"pull_request.opened">; + private _context: Context<"pull_request.opened">; /** * @constructor * @param {Context<"pull_request.opened">} context */ constructor(context: Context<"pull_request.opened">) { - this.context = context; + this._context = context; } /** @@ -28,10 +28,10 @@ export default class PullRequestOpen { */ private async checkChanges(): Promise { let totalChanges: number = 0; - await this.context.octokit.pulls.listFiles({ - owner: this.context.payload.repository.owner.login, - repo: this.context.payload.repository.name, - pull_number: this.context.payload.number + await this._context.octokit.pulls.listFiles({ + owner: this._context.payload.repository.owner.login, + repo: this._context.payload.repository.name, + pull_number: this._context.payload.number }).then(async (res) => { const filterFiles = res.data.filter((a) => a.filename !== "package.json" && a.filename !== "package-lock.json"); filterFiles.forEach((file) => { @@ -39,8 +39,8 @@ export default class PullRequestOpen { }); if (totalChanges > 1000) { - await this.context.octokit.issues.addLabels( - this.context.issue({ + await this._context.octokit.issues.addLabels( + this._context.issue({ labels: ["Huge Changes"] }) ); @@ -56,10 +56,10 @@ export default class PullRequestOpen { private async giveLabels(): Promise { const fileLabels: string[] = []; const filteredlabels: string[] = []; - await this.context.octokit.pulls.listFiles({ + await this._context.octokit.pulls.listFiles({ owner: "Typeslint", repo: "github-AutoResponse", - pull_number: this.context.payload.number + pull_number: this._context.payload.number }).then(async (res) => { const listFiles = res.data.map((a) => a.filename); listFiles.forEach((file) => { @@ -78,8 +78,8 @@ export default class PullRequestOpen { if (fileLabels.length > 0) { new Set(fileLabels).forEach((a) => filteredlabels.push(a)); - await this.context.octokit.issues.addLabels( - this.context.issue({ + await this._context.octokit.issues.addLabels( + this._context.issue({ labels: filteredlabels }) ); @@ -96,26 +96,26 @@ export default class PullRequestOpen { */ public async open(): Promise { - 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` + 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` }); console.log("Pull request opened"); - await this.context.octokit.issues.createComment(propened); - await this.context.octokit.issues.addLabels( - this.context.issue({ + await this._context.octokit.issues.createComment(propened); + await this._context.octokit.issues.addLabels( + this._context.issue({ labels: ["Pending"] }) ); await this.checkChanges(); } else { - const propened = this.context.issue({ - body: `PRs by \`[OWNER]\`${this.context.payload.pull_request.user.login}!` + const propened = this._context.issue({ + body: `PRs by \`[OWNER]\`${this._context.payload.pull_request.user.login}!` }); console.log("Pull request opened"); - await this.context.octokit.issues.createComment(propened); - await this.context.octokit.issues.addLabels( - this.context.issue({ + await this._context.octokit.issues.createComment(propened); + await this._context.octokit.issues.addLabels( + this._context.issue({ labels: ["Pending"] }) ); @@ -129,13 +129,13 @@ export default class PullRequestOpen { * @returns {Promise} */ public async openCore(): Promise { - 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` + 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` }); console.log("Pull request opened"); - await this.context.octokit.issues.createComment(propened); - await this.context.octokit.issues.addLabels( - this.context.issue({ + await this._context.octokit.issues.createComment(propened); + await this._context.octokit.issues.addLabels( + this._context.issue({ labels: ["Pending"] }) ); @@ -145,7 +145,7 @@ export default class PullRequestOpen { await octokit.rest.pulls.get({ owner: "Typeslint", repo: "github-AutoResponse", - pull_number: this.context.payload.number + pull_number: this._context.payload.number }).then(async (res) => { shaRef = res.data.head.sha; await octokit.rest.repos.getContent({ @@ -170,15 +170,15 @@ export default class PullRequestOpen { if (decodeContent.includes("\"noImplicitAny\": true") && decodeContent.includes("\"noImplicitThis\": true") && decodeContent.includes("\"strictFunctionTypes\": true") && decodeContent.includes("\"strictNullChecks\": true")) { return; } else { - await this.context.octokit.issues.addLabels( - this.context.issue({ + await this._context.octokit.issues.addLabels( + this._context.issue({ labels: ["Config Invalid"] }) ); - const configInvalid = this.context.issue({ + const configInvalid = this._context.issue({ body: `[tsconfig](${res.data.html_url}) needs the following rules to be set to true: ${missingRules.join(", ")}` }); - await this.context.octokit.issues.createComment(configInvalid); + await this._context.octokit.issues.createComment(configInvalid); } } else { return; diff --git a/src/class/prsReview.ts b/src/class/prsReview.ts index 11d6593..73dffef 100644 --- a/src/class/prsReview.ts +++ b/src/class/prsReview.ts @@ -1,4 +1,4 @@ -import Context from "../index"; +import { Context } from "../index.js"; /** * @class @@ -10,35 +10,35 @@ export default class PullRequestReview { * @private * @type Context<"pull_request_review.submitted"> */ - private context: Context<"pull_request_review.submitted">; + private _context: Context<"pull_request_review.submitted">; /** * @constructor * @param {Context<"pull_request_review.submitted">} context */ constructor(context: Context<"pull_request_review.submitted">) { - this.context = context; + this._context = context; } /** * @private + * @async * @param {string} body * @param {string[]} labels * @param {string[]} [removeLabel] - * @async * @returns {Promise} */ private async createReview(body: string, labels: string[], removeLabel?: string[]): Promise { - await this.context.octokit.pulls.createReview({ - repo: this.context.payload.repository.name, - owner: this.context.payload.repository.owner.login, - pull_number: this.context.payload.pull_request.number, + await this._context.octokit.pulls.createReview({ + repo: this._context.payload.repository.name, + owner: this._context.payload.repository.owner.login, + pull_number: this._context.payload.pull_request.number, body: body, event: "COMMENT" }); - await this.context.octokit.issues.addLabels( - this.context.issue({ + await this._context.octokit.issues.addLabels( + this._context.issue({ labels: labels }) ); @@ -46,8 +46,8 @@ export default class PullRequestReview { if (removeLabel) { removeLabel.forEach((label) => { new Promise((resolve, reject) => { - this.context.octokit.issues.removeLabel( - this.context.issue({ + this._context.octokit.issues.removeLabel( + this._context.issue({ name: label }) ).then(() => { @@ -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") { - 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.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")) { await this.createReview(reviewMessage, ["Approved"], ["Requested Changes", "Pending"]); } else { await this.createReview(reviewMessage, ["Approved"], ["Pending"]); } - } 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")) { + } 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")) { await this.createReview(reviewMessage, ["Requested Changes"], ["Approved", "Pending"]); } else { await this.createReview(reviewMessage, ["Requested Changes"], ["Pending"]); } } - } else if (this.context.payload.review.author_association === "MEMBER" || this.context.payload.review.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")) { + } else if (this._context.payload.review.author_association === "MEMBER" || this._context.payload.review.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")) { await this.createReview(reviewMessage, ["Approved"], ["Requested Changes", "Pending"]); } else { await this.createReview(reviewMessage, ["Approved"], ["Pending"]); } - } 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")) { + } 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")) { 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") { - 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.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")) { 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") { - 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")) { + } 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")) { await this.createReview(reviewMessage, ["Requested Changes"], ["Others Approved", "Pending"]); } else { await this.createReview(reviewMessage, ["Requested Changes"], ["Pending"]); @@ -127,48 +127,49 @@ export default class PullRequestReview { * @returns {Promise} */ public async botPRs(): Promise { - const maintainers: ReadonlyArray = await this.context.octokit.pulls.listReviews({ - owner: this.context.payload.repository.owner.login, - repo: this.context.payload.repository.name, - pull_number: this.context.payload.pull_request.number + const maintainers: ReadonlyArray = await this._context.octokit.pulls.listReviews({ + owner: this._context.payload.repository.owner.login, + repo: this._context.payload.repository.name, + pull_number: this._context.payload.pull_request.number }).then((response) => { return response.data.filter((data) => data.user?.login && - this.context.payload.review.user.login !== data.user.login && + this._context.payload.review.user.login !== data.user.login && data.user.type.toLowerCase() !== "bot" && ["COLLABORATOR", "MEMBER", "OWNER"].includes(data.author_association) ).map((data) => { return `@${data.user?.login}`; }); }); - 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") { - 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.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")) { await this.createReview(reviewMessage, ["Approved"], ["Requested Changes", "Pending"]); } else { await this.createReview(reviewMessage, ["Approved"], ["Pending"]); } - } else if (this.context.payload.review.state === "changes_requested") { - const reviewMessage = `@${this.context.payload.pull_request.user.login} pull request has requested changes by \`[OWNER]\`@${this.context.payload.review.user.login}. ${maintainers.join(", ")} please address their comments before I'm merging this PR, thanks!`; - if (this.context.payload.pull_request.labels.find((a) => a.name === "Approved")) { + } else if (this._context.payload.review.state === "changes_requested") { + const reviewMessage = `@${this._context.payload.pull_request.user.login} pull request has requested changes by \`[OWNER]\`@${this._context.payload.review.user.login}. ${maintainers.join(", ")} please address their comments before I'm merging this PR, thanks!`; + 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.review.author_association === "MEMBER" || this.context.payload.review.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")) { + } else if (this._context.payload.review.author_association === "MEMBER" || this._context.payload.review.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")) { await this.createReview(reviewMessage, ["Approved"], ["Requested Changes", "Pending"]); } else { await this.createReview(reviewMessage, ["Approved"], ["Pending"]); } - } else if (this.context.payload.review.state === "changes_requested") { - const reviewMessage = `Pull request has requested changes by \`[MAINTAINER]\`@${this.context.payload.review.user.login}. ${maintainers.join(", ")} please address their comments before I'm merging this PR, thanks!`; - if (this.context.payload.pull_request.labels.find((a) => a.name === "Approved")) { + } else if (this._context.payload.review.state === "changes_requested") { + const reviewMessage = `Pull request has requested changes by \`[MAINTAINER]\`@${this._context.payload.review.user.login}. ${maintainers.join(", ")} please address their comments before I'm merging this PR, thanks!`; + 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"]); @@ -176,16 +177,16 @@ export default class PullRequestReview { } } else { // Others 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.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")) { 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") { - const reviewMessage = `Pull request has requested changes by @${this.context.payload.review.user.login}. ${maintainers.join(", ")} please address their comments before I'm merging this PR, thanks!`; - if (this.context.payload.pull_request.labels.find((a) => a.name === "Others Approved")) { + } else if (this._context.payload.review.state === "changes_requested") { + const reviewMessage = `Pull request has requested changes by @${this._context.payload.review.user.login}. ${maintainers.join(", ")} please address their comments before I'm merging this PR, thanks!`; + 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 e48a851..09fee19 100644 --- a/src/class/prsStale.ts +++ b/src/class/prsStale.ts @@ -1,4 +1,4 @@ -import { octokit } from "../index"; +import { octokit } from "../index.js"; /** * @class diff --git a/src/class/prsSynchronize.ts b/src/class/prsSynchronize.ts index d29f221..f1e1420 100644 --- a/src/class/prsSynchronize.ts +++ b/src/class/prsSynchronize.ts @@ -1,4 +1,4 @@ -import Context, { octokit } from "../index"; +import { Context, octokit } from "../index.js"; /** * @class @@ -11,14 +11,14 @@ export default class PullRequestSynchronize { * @private * @type Context<"pull_request.synchronize"> */ - private context: Context<"pull_request.synchronize">; + private _context: Context<"pull_request.synchronize">; /** * @constructor * @param {Context<"pull_request.synchronize">} context */ constructor(context: Context<"pull_request.synchronize">) { - this.context = context; + this._context = context; } /** @@ -27,18 +27,18 @@ export default class PullRequestSynchronize { * @returns {Promise} */ public async sync(): Promise { - await this.context.octokit.issues.listLabelsOnIssue({ - owner: this.context.payload.repository.owner.login, - repo: this.context.payload.repository.name, - issue_number: this.context.payload.pull_request.number + await this._context.octokit.issues.listLabelsOnIssue({ + owner: this._context.payload.repository.owner.login, + repo: this._context.payload.repository.name, + issue_number: this._context.payload.pull_request.number }).then(async (res) => { let i: number; const prsLabels = res.data.find((a) => a.name === "Requested Changes" || a.name === "Approved")?.name; if (prsLabels) { - await this.context.octokit.pulls.listReviews({ - owner: this.context.payload.repository.owner.login, - repo: this.context.payload.repository.name, - pull_number: this.context.payload.pull_request.number + await this._context.octokit.pulls.listReviews({ + owner: this._context.payload.repository.owner.login, + repo: this._context.payload.repository.name, + pull_number: this._context.payload.pull_request.number }).then(async (res) => { const reviewersArray: string[] = []; const tagReviewers: string[] = []; @@ -53,17 +53,17 @@ export default class PullRequestSynchronize { const username: string = res.data[i].user?.login || ""; reviewersArray.push(username); tagReviewers.push("@" + username); - await this.context.octokit.pulls.dismissReview({ - owner: this.context.payload.repository.owner.login, - repo: this.context.payload.repository.name, - pull_number: this.context.payload.pull_request.number, + await this._context.octokit.pulls.dismissReview({ + owner: this._context.payload.repository.owner.login, + repo: this._context.payload.repository.name, + pull_number: this._context.payload.pull_request.number, review_id: res.data[i].id, message: "This review is stale and has been dismissed." }); - await this.context.octokit.pulls.requestReviewers({ - owner: this.context.payload.repository.owner.login, - repo: this.context.payload.repository.name, - pull_number: this.context.payload.pull_request.number, + await this._context.octokit.pulls.requestReviewers({ + owner: this._context.payload.repository.owner.login, + repo: this._context.payload.repository.name, + pull_number: this._context.payload.pull_request.number, reviewers: [username] }); } else { @@ -76,23 +76,23 @@ export default class PullRequestSynchronize { continue; } } - if (this.context.payload.sender.login === this.context.payload.pull_request.user.login) { - await this.context.octokit.issues.createComment( - this.context.issue({ - owner: this.context.payload.repository.owner.login, - repo: this.context.payload.repository.name, - issue_number: this.context.payload.pull_request.number, - body: `PING! ${tagReviewers.join(", ")}. The author has pushed new commits since your last review. please review @${this.context.payload.sender.login} new commit before merge, thanks!` + if (this._context.payload.sender.login === this._context.payload.pull_request.user.login) { + await this._context.octokit.issues.createComment( + this._context.issue({ + owner: this._context.payload.repository.owner.login, + repo: this._context.payload.repository.name, + issue_number: this._context.payload.pull_request.number, + body: `PING! ${tagReviewers.join(", ")}. The author has pushed new commits since your last review. please review @${this._context.payload.sender.login} new commit before merge, thanks!` }) ); - await this.context.octokit.issues.removeLabel( - this.context.issue({ + await this._context.octokit.issues.removeLabel( + this._context.issue({ name: prsLabels }) ); } else { - await this.context.octokit.issues.removeLabel( - this.context.issue({ + await this._context.octokit.issues.removeLabel( + this._context.issue({ name: prsLabels }) ); @@ -115,7 +115,7 @@ export default class PullRequestSynchronize { await octokit.rest.pulls.get({ owner: "Typeslint", repo: "github-AutoResponse", - pull_number: this.context.payload.number + pull_number: this._context.payload.number }).then(async (res) => { shaRef = res.data.head.sha; await octokit.rest.repos.getContent({ @@ -128,14 +128,14 @@ export default class PullRequestSynchronize { const textContent:string = res.data.content; const decodeContent:string = Buffer.from(textContent, "base64").toString("utf-8"); if (decodeContent.includes("\"noImplicitAny\": true") && decodeContent.includes("\"noImplicitThis\": true") && decodeContent.includes("\"strictFunctionTypes\": true") && decodeContent.includes("\"strictNullChecks\": true")) { - await this.context.octokit.issues.listLabelsOnIssue({ - owner: this.context.payload.repository.owner.login, - repo: this.context.payload.repository.name, - issue_number: this.context.payload.pull_request.number + await this._context.octokit.issues.listLabelsOnIssue({ + owner: this._context.payload.repository.owner.login, + repo: this._context.payload.repository.name, + issue_number: this._context.payload.pull_request.number }).then(async (res) => { if (res.data.find((a) => a.name === "Config Invalid")) { - await this.context.octokit.issues.removeLabel( - this.context.issue({ + await this._context.octokit.issues.removeLabel( + this._context.issue({ name: "Config Invalid" }) ); @@ -144,10 +144,10 @@ export default class PullRequestSynchronize { } }); } else { - const configInvalid = this.context.issue({ + const configInvalid = this._context.issue({ body: `[tsconfig](${res.data.html_url}) need [*noImplicitAny*, *noImplicitThis*, *strictFunctionTypes*, *strictNullChecks*] to true value` }); - await this.context.octokit.issues.createComment(configInvalid); + await this._context.octokit.issues.createComment(configInvalid); } } else { return; diff --git a/src/class/push.ts b/src/class/push.ts index db79b47..73c3d9c 100644 --- a/src/class/push.ts +++ b/src/class/push.ts @@ -1,4 +1,4 @@ -import Context, { GetEvent, GetUserData, octokit, token } from "../index"; +import { Context, GetEvent, GetUserData, octokit, token } from "../index.js"; /** * @class @@ -11,14 +11,14 @@ export default class Push { * @private * @type Context<"push"> */ - private context: Context<"push">; + private _context: Context<"push">; /** * @constructor * @param {Context<"push">} context */ constructor(context: Context<"push">) { - this.context = context; + this._context = context; } /** @@ -82,10 +82,10 @@ 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({ + await this._context.octokit.repos.getContent({ owner: "Muunatic", repo: "Muunatic", path: "README.md", @@ -93,7 +93,7 @@ export default class Push { }).then(async (res) => { if ("sha" in res.data) { const textcontent = `# ɢɪᴛʜᴜʙ sᴛᴀᴛs

\nUpdated ${new Date().toUTCString()} \n\n1. ${event1}\n2. ${event2}\n3. ${event3}\n4. ${event4}\n5. ${event5}`; - await this.context.octokit.repos.createOrUpdateFileContents({ + await this._context.octokit.repos.createOrUpdateFileContents({ content: Buffer.from(textcontent, "utf-8").toString("base64"), path: "README.md", message: "Update Readme.md", @@ -106,13 +106,13 @@ 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", name: "typeslint/ci", - head_sha: this.context.payload.head_commit?.id as string, + head_sha: this._context.payload.head_commit?.id as string, status: "in_progress" }).then(async (resId) => { await octokit.rest.checks.update({ @@ -124,7 +124,7 @@ export default class Push { conclusion: "success", output: { title: "Update Activities ✔️", - summary: "@" + this.context.payload.sender.login + " README Update" + summary: "@" + this._context.payload.sender.login + " README Update" } }); }); diff --git a/src/class/workflowCheck.ts b/src/class/workflowCheck.ts index 2daf35d..7fcd10d 100644 --- a/src/class/workflowCheck.ts +++ b/src/class/workflowCheck.ts @@ -1,4 +1,4 @@ -import Context, { octokit } from "../index"; +import { Context, octokit } from "../index.js"; /** * @class @@ -11,14 +11,14 @@ export default class WorkflowCheck { * @private * @type Context<"workflow_run.completed"> */ - private context: Context<"workflow_run.completed">; + private _context: Context<"workflow_run.completed">; /** * @constructor * @param {Context<"workflow_run.completed">} context */ constructor(context: Context<"workflow_run.completed">) { - this.context = context; + this._context = context; } /** @@ -27,21 +27,21 @@ export default class WorkflowCheck { * @returns {Promise} */ public async checkCI(): Promise { - if (this.context.payload.workflow_run.conclusion === "failure") { - await this.context.octokit.issues.addLabels( - this.context.issue({ - owner: this.context.payload.repository.owner.login, - repo: this.context.payload.repository.name, - issue_number: this.context.payload.workflow_run.pull_requests[0].number, + if (this._context.payload.workflow_run.conclusion === "failure") { + await this._context.octokit.issues.addLabels( + this._context.issue({ + owner: this._context.payload.repository.owner.login, + repo: this._context.payload.repository.name, + issue_number: this._context.payload.workflow_run.pull_requests[0].number, labels: ["CI Failed"] }) ); - await this.context.octokit.issues.createComment( - this.context.issue({ - owner: this.context.payload.repository.owner.login, - repo: this.context.payload.repository.name, - issue_number: this.context.payload.workflow_run.pull_requests[0].number, - body: `CI build failed! for more information please review the [logs](${this.context.payload.workflow_run.html_url}).` + await this._context.octokit.issues.createComment( + this._context.issue({ + owner: this._context.payload.repository.owner.login, + repo: this._context.payload.repository.name, + issue_number: this._context.payload.workflow_run.pull_requests[0].number, + body: `CI build failed! for more information please review the [logs](${this._context.payload.workflow_run.html_url}).` }) ); } else { @@ -56,48 +56,47 @@ export default class WorkflowCheck { */ public async checkUserCI(): Promise { await octokit.rest.pulls.list({ - owner: this.context.payload.repository.owner.login, - repo: this.context.payload.repository.name, - head: `${this.context.payload.workflow_run.actor.login}:${this.context.payload.workflow_run.head_branch}`, + owner: this._context.payload.repository.owner.login, + repo: this._context.payload.repository.name, 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") { - await this.context.octokit.pulls.get({ - owner: this.context.payload.repository.owner.login, - repo: this.context.payload.repository.name, + 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") { + console.log(this._context.payload.repository.owner.login, this._context.payload.repository.name, prsNumber); + 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")) { - await this.context.octokit.issues.removeLabel( - this.context.issue({ - owner: this.context.payload.repository.owner.login, - repo: this.context.payload.repository.name, + await this._context.octokit.issues.removeLabel( + this._context.issue({ + owner: this._context.payload.repository.owner.login, + repo: this._context.payload.repository.name, issue_number: prsNumber, name: "CI Failed" }) ); - console.log("CI Passed!"); } else { 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({ - owner: this.context.payload.repository.owner.login, - repo: this.context.payload.repository.name, + await this._context.octokit.issues.addLabels( + this._context.issue({ + owner: this._context.payload.repository.owner.login, + repo: this._context.payload.repository.name, issue_number: prsNumber, labels: ["CI Failed"] }) ); - await this.context.octokit.issues.createComment( - this.context.issue({ - owner: this.context.payload.repository.owner.login, - repo: this.context.payload.repository.name, + await this._context.octokit.issues.createComment( + this._context.issue({ + owner: this._context.payload.repository.owner.login, + repo: this._context.payload.repository.name, issue_number: prsNumber, - body: `CI build failed! for more information please review the [logs](${this.context.payload.workflow_run.html_url}).` + body: `CI build failed! for more information please review the [logs](${this._context.payload.workflow_run.html_url}).` }) ); } else { diff --git a/src/index.ts b/src/index.ts index fe15c50..743d956 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,10 +1,10 @@ import { Context, Probot } from "probot"; import { Octokit } from "octokit"; import { createAppAuth } from "@octokit/auth-app"; -import { token } from "./data/config"; -import { IssuesClose, IssuesComment, IssuesOpen, PRsStale, PullRequestOpen, PullRequestReview, PullRequestSynchronize, Push, WorkflowCheck } from "./structures/constant"; -import { GetEvent, GetUserData } from "./structures/type"; -import "./structures/listener"; +import { token } from "./data/config.js"; +import { IssuesClose, IssuesComment, IssuesOpen, PRsStale, PullRequestOpen, PullRequestReview, PullRequestSynchronize, Push, WorkflowCheck } from "./structures/constant.js"; +import { GetEvent, GetUserData } from "./structures/type.js"; +import "./structures/listener.js"; import dotenv from "dotenv"; dotenv.config(); @@ -19,7 +19,7 @@ const octokit = new Octokit({ } }); -module.exports = (app: Probot) => { +export default (app: Probot): void => { app.on("push", async (context): Promise => { await new Push(context).push(); @@ -45,10 +45,13 @@ module.exports = (app: Probot) => { }); app.on("issues.closed", async (context): Promise => { - if (context.payload.issue.state_reason === "not_planned") { - await new IssuesClose(context).invalid(); - } else { - await new IssuesClose(context).closed(); + switch (context.payload.issue.state_reason?.toLowerCase()) { + case "not_planned": + await new IssuesClose(context).invalid(); + break; + default: + await new IssuesClose(context).closed(); + break; } }); @@ -59,8 +62,6 @@ module.exports = (app: Probot) => { } else { await new PullRequestOpen(context).open(); } - } else { - return; } }); @@ -112,6 +113,5 @@ setInterval(() => { }); }, 3600000); -export default Context; -export { octokit, token }; +export { Context, octokit, token }; export type { GetEvent, GetUserData }; diff --git a/src/structures/constant.ts b/src/structures/constant.ts index 54a2b8a..c9aa557 100644 --- a/src/structures/constant.ts +++ b/src/structures/constant.ts @@ -1,12 +1,12 @@ -import IssuesClose from "../class/issuesClose"; -import IssuesComment from "../class/issuesComment"; -import IssuesOpen from "../class/issuesOpen"; -import PullRequestOpen from "../class/prsOpen"; -import PullRequestReview from "../class/prsReview"; -import PullRequestSynchronize from "../class/prsSynchronize"; -import Push from "../class/push"; -import WorkflowCheck from "../class/workflowCheck"; -import PRsStale from "../class/prsStale"; +import IssuesClose from "../class/issuesClose.js"; +import IssuesComment from "../class/issuesComment.js"; +import IssuesOpen from "../class/issuesOpen.js"; +import PullRequestOpen from "../class/prsOpen.js"; +import PullRequestReview from "../class/prsReview.js"; +import PullRequestSynchronize from "../class/prsSynchronize.js"; +import Push from "../class/push.js"; +import WorkflowCheck from "../class/workflowCheck.js"; +import PRsStale from "../class/prsStale.js"; export { IssuesClose, diff --git a/tsconfig.json b/tsconfig.json index d41109a..349e9ba 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,10 +1,10 @@ { "compilerOptions": { "module": "Node16", - "target": "ES2023", + "target": "ES2024", "outDir": "dist", "lib": [ - "ES2023", + "ES2024", "dom" ], "alwaysStrict": true, @@ -31,7 +31,8 @@ "strictNullChecks": true }, "include": [ - "src/" + "src/", + "eslint.config.ts" ], "exclude": [ "node_modules"