diff --git a/.env.example b/.env.example index 398c7da..24b97f6 100644 --- a/.env.example +++ b/.env.example @@ -5,4 +5,5 @@ APP_ID="" PRIVATE_KEY="" WEBHOOK_SECRET="" CLIENT_ID="" -CLIENT_SECRET="" \ No newline at end of file +CLIENT_SECRET="" +INSTALLATION_ID="" \ No newline at end of file diff --git a/eslint.config.mjs b/eslint.config.mjs deleted file mode 100644 index 3e8249b..0000000 --- a/eslint.config.mjs +++ /dev/null @@ -1,139 +0,0 @@ -import eslint from '@eslint/js'; -import tseslint from 'typescript-eslint'; -import tsPlugin from '@typescript-eslint/eslint-plugin'; -import tsParser from '@typescript-eslint/parser'; -import stylisticTs from '@stylistic/eslint-plugin-ts'; - -export default tseslint.config( - eslint.configs.recommended, - tseslint.configs.recommended, - tseslint.configs.recommendedTypeChecked, - - { - files: ["**/*.ts"], - languageOptions: { - ecmaVersion: 14, - parser: tsParser, - parserOptions: { - ecmaVersion: 14, - sourceType: "module", - project: true - } - }, - plugins: { - "@typescript-eslint": tsPlugin, - "@stylistic/ts": stylisticTs - }, - extends: [ - eslint.configs.recommended, - tseslint.configs.recommended, - tseslint.configs.recommendedTypeChecked - ], - rules: { - "arrow-parens": ["warn", "always"], - "brace-style": ["warn", "1tbs"], - "camelcase": ["warn", { - "properties": "never", - "ignoreImports": true - }], - "comma-dangle": ["error", "never"], - "comma-spacing": ["warn", { - "after": true, - "before": false - }], - "comma-style": ["warn", "last"], - "curly": ["error", "all"], - "default-case": 1, - "eol-last": ["warn", "always"], - "eqeqeq": ["error", "smart"], - "indent": ["warn", 4, { - "SwitchCase": 1 - }], - "key-spacing": ["warn", { - "mode": "strict" - }], - "keyword-spacing": ["warn", { - "after": true, - "before": true - }], - "lines-between-class-members": ["warn", "always"], - "no-multi-spaces": 1, - "no-multiple-empty-lines": ["warn", { - "max": 1 - }], - "no-trailing-spaces": 1, - "no-unused-vars": 1, - "no-useless-escape": 0, - "object-curly-spacing": ["error", "always", { - "objectsInObjects": true, - "arraysInObjects": true - }], - "object-shorthand": ["warn", "consistent"], - "quotes": ["warn", "double", { - "avoidEscape": false - }], - "semi": "error", - "semi-style": ["warn", "last"], - "sort-imports": ["warn", { - "ignoreCase": false, - "ignoreDeclarationSort": true - }], - "@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 - }], - "@stylistic/ts/member-delimiter-style": ["warn", { - "multiline": { - "delimiter": "semi", - "requireLast": true - }, - "singleline": { - "delimiter": "semi", - "requireLast": false - }, - "multilineDetection": "brackets" - }], - "@typescript-eslint/no-unnecessary-condition": 2, - "@typescript-eslint/no-unused-expressions": 0, - "@typescript-eslint/no-require-imports": 2, - "@typescript-eslint/no-var-requires": 1 - }, - }, - { - ignores: [ - "node_modules", - "dist" - ] - } -); diff --git a/package.json b/package.json index ee120c8..6db93e1 100644 --- a/package.json +++ b/package.json @@ -1,39 +1,39 @@ { "name": "typeslint-cli", - "version": "3.0.1", + "version": "4.0.0", + "type": "module", "private": true, "description": "GitHub Workflow Apps", "homepage": "https://typeslint.com/github-autoresponse", "author": "Typeslint", "license": "ISC", "scripts": { - "build": "tsc --build --verbose", - "build:start": "tsc --build --verbose && probot run ./dist/index.js", - "start": "probot run ./dist/index.js", + "build": "tsc --build --clean && tsc --build --force --verbose", + "build:start": "tsc --build --clean && tsc --build --force --verbose && probot run ./dist/src/index.js", + "start": "probot run ./dist/src/index.js", "test": "eslint .", "lint": "npx eslint src/**/*.ts", "lint:fix": "npx eslint src/**/*.ts --fix" }, "dependencies": { - "dotenv": "^16.4.5", - "octokit": "^3.2.1", - "probot": "^12.4.0", - "smee-client": "^2.0.1" + "@octokit/auth-app": "^8.1.2", + "@octokit/rest": "^22.0.1", + "dotenv": "^16.6.1", + "octokit": "^5.0.5", + "probot": "^14.2.4", + "smee-client": "^5.0.0" }, "devDependencies": { - "@octokit/auth-app": "^6.1.1", - "@octokit/rest": "^20.1.1", - "@types/node": "^18.19.39", - "@stylistic/eslint-plugin-ts": "^4.2.0", - "@typescript-eslint/eslint-plugin": "^8.29.1", - "@typescript-eslint/parser": "^8.29.1", - "eslint": "^9.24.0", - "typescript": "~5.8.3", - "typescript-eslint": "^8.29.1" + "@stylistic/eslint-plugin": "^5.6.1", + "@types/node": "^22.19.2", + "eslint": "^9.39.1", + "jiti": "^2.6.1", + "typescript": "~5.9.3", + "typescript-eslint": "^8.49.0" }, "engines": { - "node": ">=18.19.0", - "npm": ">=10.2.3" + "node": ">=22.21.1", + "npm": ">=10.9.4" }, "repository": { "type": "git", diff --git a/src/class/issuesClose.ts b/src/class/issuesClose.ts index 973ca9b..1457b01 100644 --- a/src/class/issuesClose.ts +++ b/src/class/issuesClose.ts @@ -31,13 +31,13 @@ export default class IssuesClose { body: `Issue closed by @${this._context.payload.sender.login}.` }); console.log("Issues closed"); - await this._context.octokit.issues.addLabels( + await this._context.octokit.rest.issues.addLabels( this._context.issue({ labels: ["Closed"] }) ); - await this._context.octokit.issues.createComment(issueClosed); - await this._context.octokit.issues.removeLabel( + await this._context.octokit.rest.issues.createComment(issueClosed); + await this._context.octokit.rest.issues.removeLabel( this._context.issue({ name: "Pending" }) @@ -54,18 +54,18 @@ export default class IssuesClose { body: `Issue closed as invalid by @${this._context.payload.sender.login}.` }); console.log("Issues closed"); - await this._context.octokit.issues.addLabels( + await this._context.octokit.rest.issues.addLabels( this._context.issue({ labels: ["Closed", "Invalid"] }) ); - await this._context.octokit.issues.createComment(issueClosed); - await this._context.octokit.issues.removeLabel( + await this._context.octokit.rest.issues.createComment(issueClosed); + await this._context.octokit.rest.issues.removeLabel( this._context.issue({ name: "Pending" }) ); - await this._context.octokit.issues.lock({ + await this._context.octokit.rest.issues.lock({ owner: this._context.payload.repository.owner.login, repo: this._context.payload.repository.name, issue_number: this._context.payload.issue.number, diff --git a/src/class/issuesComment.ts b/src/class/issuesComment.ts index cf86ae9..9a6b26b 100644 --- a/src/class/issuesComment.ts +++ b/src/class/issuesComment.ts @@ -28,18 +28,18 @@ export default class IssuesComment { */ public async userPRsComment(): Promise { if (this._context.payload.comment.body.toLowerCase() === "ready to merge") { - await this._context.octokit.pulls.get({ + await this._context.octokit.rest.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") { console.log("Merging"); - await this._context.octokit.pulls.merge({ + await this._context.octokit.rest.pulls.merge({ repo: this._context.payload.repository.name, owner: this._context.payload.repository.owner.login, pull_number: this._context.payload.issue.number, @@ -47,7 +47,7 @@ export default class IssuesComment { commit_message: this._context.payload.issue.title }); console.log("Merged!"); - await this._context.octokit.issues.createComment( + await this._context.octokit.rest.issues.createComment( this._context.issue({ body: `Merged by ${this._context.payload.comment.user.login}!` }) @@ -55,7 +55,7 @@ export default class IssuesComment { break; } else if (this._context.payload.issue.labels[i].name === "Requested Changes") { console.log("PRs Blocked"); - await this._context.octokit.issues.createComment( + await this._context.octokit.rest.issues.createComment( this._context.issue({ body: `Merging blocked because PRs has requested changes! @${this._context.payload.comment.user.login}` }) @@ -69,13 +69,13 @@ export default class IssuesComment { return; } } else if (res.data.mergeable_state.toLowerCase() === "dirty" || res.data.mergeable === false) { - await this._context.octokit.issues.createComment( + await this._context.octokit.rest.issues.createComment( this._context.issue({ - body: `Merging blocked because PRs has merge conflict! @${this._context.payload.comment.user.login}` + body: `Merging blocked because PRs has merge conflict! @${this._context.payload.comment.user?.login}` }) ); } else { - await this._context.octokit.issues.createComment( + await this._context.octokit.rest.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." }) @@ -86,7 +86,7 @@ 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({ + await this._context.octokit.rest.pulls.merge({ repo: this._context.payload.repository.name, owner: this._context.payload.repository.owner.login, pull_number: this._context.payload.issue.number, @@ -94,23 +94,23 @@ export default class IssuesComment { commit_message: this._context.payload.issue.title }); console.log("Merged!"); - await this._context.octokit.issues.removeLabel( + await this._context.octokit.rest.issues.removeLabel( this._context.issue({ name: "Pending" }) ); - await this._context.octokit.issues.createComment( + await this._context.octokit.rest.issues.createComment( this._context.issue({ - body: `Merged by \`[OWNER]\`${this._context.payload.comment.user.login}!` + body: `Merged by \`[OWNER]\`${this._context.payload.comment.user?.login}!` }) ); - await this._context.octokit.issues.addLabels( + await this._context.octokit.rest.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({ + await this._context.octokit.rest.pulls.merge({ repo: this._context.payload.repository.name, owner: this._context.payload.repository.owner.login, pull_number: this._context.payload.issue.number, @@ -118,14 +118,14 @@ export default class IssuesComment { commit_message: this._context.payload.issue.title }); console.log("Merged!"); - await this._context.octokit.issues.removeLabel( + await this._context.octokit.rest.issues.removeLabel( this._context.issue({ name: "Pending" }) ); - await this._context.octokit.issues.createComment( + await this._context.octokit.rest.issues.createComment( this._context.issue({ - body: `Merged by \`[MAINTAINER]\`${this._context.payload.comment.user.login}!` + body: `Merged by \`[MAINTAINER]\`${this._context.payload.comment.user?.login}!` }) ); } else { @@ -142,7 +142,7 @@ export default class IssuesComment { 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({ + await this._context.octokit.rest.pulls.merge({ repo: this._context.payload.repository.name, owner: this._context.payload.repository.owner.login, pull_number: this._context.payload.issue.number, @@ -150,23 +150,23 @@ export default class IssuesComment { commit_message: this._context.payload.issue.title }); console.log("Merged!"); - await this._context.octokit.issues.removeLabel( + await this._context.octokit.rest.issues.removeLabel( this._context.issue({ name: "Pending" }) ); - await this._context.octokit.issues.createComment( + await this._context.octokit.rest.issues.createComment( this._context.issue({ - body: `Merged by \`[OWNER]\`${this._context.payload.comment.user.login}!` + body: `Merged by \`[OWNER]\`${this._context.payload.comment.user?.login}!` }) ); - await this._context.octokit.issues.addLabels( + await this._context.octokit.rest.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({ + await this._context.octokit.rest.pulls.merge({ repo: this._context.payload.repository.name, owner: this._context.payload.repository.owner.login, pull_number: this._context.payload.issue.number, @@ -174,14 +174,14 @@ export default class IssuesComment { commit_message: this._context.payload.issue.title }); console.log("Merged!"); - await this._context.octokit.issues.removeLabel( + await this._context.octokit.rest.issues.removeLabel( this._context.issue({ name: "Pending" }) ); - await this._context.octokit.issues.createComment( + await this._context.octokit.rest.issues.createComment( this._context.issue({ - body: `Merged by \`[MAINTAINER]\`${this._context.payload.comment.user.login}!` + body: `Merged by \`[MAINTAINER]\`${this._context.payload.comment.user?.login}!` }) ); } else { diff --git a/src/class/issuesOpen.ts b/src/class/issuesOpen.ts index 1834c73..f8338d3 100644 --- a/src/class/issuesOpen.ts +++ b/src/class/issuesOpen.ts @@ -32,12 +32,12 @@ export default class IssuesOpen { 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( + await this._context.octokit.rest.issues.addLabels( this._context.issue({ labels: ["Pending"] }) ); - await this._context.octokit.issues.createComment(issueComment); + await this._context.octokit.rest.issues.createComment(issueComment); } else { return; } diff --git a/src/class/prsOpen.ts b/src/class/prsOpen.ts index a5cf8d9..e8eb716 100644 --- a/src/class/prsOpen.ts +++ b/src/class/prsOpen.ts @@ -28,7 +28,7 @@ export default class PullRequestOpen { */ private async checkChanges(): Promise { let totalChanges: number = 0; - await this._context.octokit.pulls.listFiles({ + await this._context.octokit.rest.pulls.listFiles({ owner: this._context.payload.repository.owner.login, repo: this._context.payload.repository.name, pull_number: this._context.payload.number @@ -39,7 +39,7 @@ export default class PullRequestOpen { }); if (totalChanges > 1000) { - await this._context.octokit.issues.addLabels( + await this._context.octokit.rest.issues.addLabels( this._context.issue({ labels: ["Huge Changes"] }) @@ -56,7 +56,7 @@ export default class PullRequestOpen { private async giveLabels(): Promise { const fileLabels: string[] = []; const filteredlabels: string[] = []; - await this._context.octokit.pulls.listFiles({ + await this._context.octokit.rest.pulls.listFiles({ owner: "Typeslint", repo: "github-AutoResponse", pull_number: this._context.payload.number @@ -78,7 +78,7 @@ export default class PullRequestOpen { if (fileLabels.length > 0) { new Set(fileLabels).forEach((a) => filteredlabels.push(a)); - await this._context.octokit.issues.addLabels( + await this._context.octokit.rest.issues.addLabels( this._context.issue({ labels: filteredlabels }) @@ -101,8 +101,8 @@ export default class PullRequestOpen { 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( + await this._context.octokit.rest.issues.createComment(propened); + await this._context.octokit.rest.issues.addLabels( this._context.issue({ labels: ["Pending"] }) @@ -113,8 +113,8 @@ export default class PullRequestOpen { 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( + await this._context.octokit.rest.issues.createComment(propened); + await this._context.octokit.rest.issues.addLabels( this._context.issue({ labels: ["Pending"] }) @@ -133,8 +133,8 @@ export default class PullRequestOpen { 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( + await this._context.octokit.rest.issues.createComment(propened); + await this._context.octokit.rest.issues.addLabels( this._context.issue({ labels: ["Pending"] }) @@ -170,7 +170,7 @@ 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( + await this._context.octokit.rest.issues.addLabels( this._context.issue({ labels: ["Config Invalid"] }) @@ -178,7 +178,7 @@ export default class PullRequestOpen { 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.rest.issues.createComment(configInvalid); } } else { return; diff --git a/src/class/prsReview.ts b/src/class/prsReview.ts index 73dffef..0fd3d1f 100644 --- a/src/class/prsReview.ts +++ b/src/class/prsReview.ts @@ -29,7 +29,7 @@ export default class PullRequestReview { * @returns {Promise} */ private async createReview(body: string, labels: string[], removeLabel?: string[]): Promise { - await this._context.octokit.pulls.createReview({ + await this._context.octokit.rest.pulls.createReview({ repo: this._context.payload.repository.name, owner: this._context.payload.repository.owner.login, pull_number: this._context.payload.pull_request.number, @@ -37,7 +37,7 @@ export default class PullRequestReview { event: "COMMENT" }); - await this._context.octokit.issues.addLabels( + await this._context.octokit.rest.issues.addLabels( this._context.issue({ labels: labels }) @@ -46,7 +46,7 @@ export default class PullRequestReview { if (removeLabel) { removeLabel.forEach((label) => { new Promise((resolve, reject) => { - this._context.octokit.issues.removeLabel( + this._context.octokit.rest.issues.removeLabel( this._context.issue({ name: label }) @@ -71,14 +71,14 @@ export default class PullRequestReview { 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`; + 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!`; + 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 { @@ -87,14 +87,14 @@ export default class PullRequestReview { } } 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`; + 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!`; + 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 { @@ -104,14 +104,14 @@ 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`; + 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!`; + 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 { @@ -127,14 +127,14 @@ export default class PullRequestReview { * @returns {Promise} */ public async botPRs(): Promise { - const maintainers: ReadonlyArray = await this._context.octokit.pulls.listReviews({ + const maintainers: ReadonlyArray = await this._context.octokit.rest.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) => { @@ -145,14 +145,14 @@ export default class PullRequestReview { 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}`; + 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!`; + 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 { @@ -161,14 +161,14 @@ export default class PullRequestReview { } } 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}`; + 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!`; + 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 { @@ -178,14 +178,14 @@ 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`; + 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!`; + 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 { diff --git a/src/class/prsSynchronize.ts b/src/class/prsSynchronize.ts index f1e1420..f300ca3 100644 --- a/src/class/prsSynchronize.ts +++ b/src/class/prsSynchronize.ts @@ -27,7 +27,7 @@ export default class PullRequestSynchronize { * @returns {Promise} */ public async sync(): Promise { - await this._context.octokit.issues.listLabelsOnIssue({ + await this._context.octokit.rest.issues.listLabelsOnIssue({ owner: this._context.payload.repository.owner.login, repo: this._context.payload.repository.name, issue_number: this._context.payload.pull_request.number @@ -35,7 +35,7 @@ export default class PullRequestSynchronize { 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({ + await this._context.octokit.rest.pulls.listReviews({ owner: this._context.payload.repository.owner.login, repo: this._context.payload.repository.name, pull_number: this._context.payload.pull_request.number @@ -53,14 +53,14 @@ export default class PullRequestSynchronize { const username: string = res.data[i].user?.login || ""; reviewersArray.push(username); tagReviewers.push("@" + username); - await this._context.octokit.pulls.dismissReview({ + await this._context.octokit.rest.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({ + await this._context.octokit.rest.pulls.requestReviewers({ owner: this._context.payload.repository.owner.login, repo: this._context.payload.repository.name, pull_number: this._context.payload.pull_request.number, @@ -76,8 +76,8 @@ export default class PullRequestSynchronize { continue; } } - if (this._context.payload.sender.login === this._context.payload.pull_request.user.login) { - await this._context.octokit.issues.createComment( + if (this._context.payload.sender.login === this._context.payload.pull_request.user?.login) { + await this._context.octokit.rest.issues.createComment( this._context.issue({ owner: this._context.payload.repository.owner.login, repo: this._context.payload.repository.name, @@ -85,13 +85,13 @@ export default class PullRequestSynchronize { 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( + await this._context.octokit.rest.issues.removeLabel( this._context.issue({ name: prsLabels }) ); } else { - await this._context.octokit.issues.removeLabel( + await this._context.octokit.rest.issues.removeLabel( this._context.issue({ name: prsLabels }) @@ -128,13 +128,13 @@ 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({ + await this._context.octokit.rest.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( + await this._context.octokit.rest.issues.removeLabel( this._context.issue({ name: "Config Invalid" }) @@ -147,7 +147,7 @@ export default class PullRequestSynchronize { 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.rest.issues.createComment(configInvalid); } } else { return; diff --git a/src/class/push.ts b/src/class/push.ts index 73c3d9c..4471b2e 100644 --- a/src/class/push.ts +++ b/src/class/push.ts @@ -82,18 +82,18 @@ 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.rest.repos.getContent({ owner: "Muunatic", repo: "Muunatic", path: "README.md", ref: "main" }).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({ + const textcontent = `# ɢɪᴛʜᴜʙ sᴛᴀᴛs

\nUpdated ${new Date().toUTCString()} \n\n1. ${event1}\n2. ${event2}\n3. ${event3}\n4. ${event4}\n5. ${event5}`; + await this._context.octokit.rest.repos.createOrUpdateFileContents({ content: Buffer.from(textcontent, "utf-8").toString("base64"), path: "README.md", message: "Update Readme.md", @@ -106,7 +106,7 @@ export default class Push { return; } }); - } else if (this._context.payload.sender.login === "typeslint-cli[bot]") { + } else if (this._context.payload.sender?.login === "typeslint-cli[bot]") { if (this._context.payload.repository.name === "Muunatic") { await octokit.rest.checks.create({ owner: "Muunatic", @@ -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 7fcd10d..7fe30d2 100644 --- a/src/class/workflowCheck.ts +++ b/src/class/workflowCheck.ts @@ -28,19 +28,19 @@ export default class WorkflowCheck { */ public async checkCI(): Promise { if (this._context.payload.workflow_run.conclusion === "failure") { - await this._context.octokit.issues.addLabels( + await this._context.octokit.rest.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, + issue_number: this._context.payload.workflow_run.pull_requests[0]?.number, labels: ["CI Failed"] }) ); - await this._context.octokit.issues.createComment( + await this._context.octokit.rest.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, + 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}).` }) ); @@ -63,13 +63,13 @@ export default class WorkflowCheck { 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({ + await this._context.octokit.rest.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( + await this._context.octokit.rest.issues.removeLabel( this._context.issue({ owner: this._context.payload.repository.owner.login, repo: this._context.payload.repository.name, @@ -83,7 +83,7 @@ export default class WorkflowCheck { }); } else if (this._context.payload.workflow_run.conclusion === "failure") { console.log("CI Failure!"); - await this._context.octokit.issues.addLabels( + await this._context.octokit.rest.issues.addLabels( this._context.issue({ owner: this._context.payload.repository.owner.login, repo: this._context.payload.repository.name, @@ -91,7 +91,7 @@ export default class WorkflowCheck { labels: ["CI Failed"] }) ); - await this._context.octokit.issues.createComment( + await this._context.octokit.rest.issues.createComment( this._context.issue({ owner: this._context.payload.repository.owner.login, repo: this._context.payload.repository.name, diff --git a/src/index.ts b/src/index.ts index 743d956..a675a72 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,7 +15,7 @@ const octokit = new Octokit({ privateKey: process.env.PRIVATE_KEY, clientId: process.env.CLIENT_ID, clientSecret: process.env.CLIENT_SECRET, - installationId: 12345678 // env not working + installationId: process.env.INSTALLATION_ID } }); @@ -30,7 +30,7 @@ export default (app: Probot): void => { }); 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(); @@ -67,7 +67,7 @@ export default (app: Probot): void => { app.on("pull_request_review.submitted", async (context): Promise => { if (context.payload.sender.type === "User") { - switch (context.payload.pull_request.user.type) { + switch (context.payload.pull_request.user?.type) { case "User": await new PullRequestReview(context).userPRs(); break; @@ -81,7 +81,7 @@ export default (app: Probot): void => { }); app.on("pull_request.synchronize", async (context): Promise => { - if (context.payload.pull_request.user.type === "User") { + if (context.payload.pull_request.user?.type === "User") { if (context.payload.repository.homepage === "https://github.com/Typeslint/github-AutoResponse") { await new PullRequestSynchronize(context).synchronizeCore(); } diff --git a/src/structures/type.ts b/src/structures/type.ts index 2d466df..447b114 100644 --- a/src/structures/type.ts +++ b/src/structures/type.ts @@ -1,10 +1,10 @@ export type GetUserData = { userData: UserDataInterface[]; -} +}; type UserDataInterface = { event: string; -} +}; export type GetEvent = { id: string; @@ -56,4 +56,4 @@ export type GetEvent = { public: boolean; created_at: string; }; -} +};