You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by wa...@apache.org on 2022/07/02 08:42:48 UTC

[echarts-bot] branch master updated: feat: support closing issue with specified reason

This is an automated email from the ASF dual-hosted git repository.

wangzx pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/echarts-bot.git


The following commit(s) were added to refs/heads/master by this push:
     new 6ca2198  feat: support closing issue with specified reason
6ca2198 is described below

commit 6ca2198a044772e432bb8a452ae14f4c82b9fda7
Author: plainheart <yh...@all-my-life.cn>
AuthorDate: Sat Jul 2 16:41:44 2022 +0800

    feat: support closing issue with specified reason
---
 index.js          | 47 ++++++++++++++++++++++++++---------
 package-lock.json | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 package.json      |  1 +
 3 files changed, 110 insertions(+), 12 deletions(-)

diff --git a/index.js b/index.js
index 07c1bf1..be841d0 100644
--- a/index.js
+++ b/index.js
@@ -14,6 +14,8 @@ const { GraphqlResponseError } = require('@octokit/graphql');
 /**
  * @typedef {import('probot').Probot} Probot
  * @typedef {import('probot').Context} Context
+ * @typedef {import('@octokit/graphql-schema').ReportedContentClassifiers} ReportedContentClassifiers
+ * @typedef {import('@octokit/graphql-schema').IssueClosedStateReason} IssueClosedStateReason
  */
 
 module.exports = (/** @type {Probot} */ app) => {
@@ -134,7 +136,7 @@ module.exports = (/** @type {Probot} */ app) => {
             case labelText.RESOLVED:
             case labelText.DUPLICATE:
                 return Promise.all([
-                    closeIssue(context),
+                    closeIssue(context, labelName === labelText.RESOLVED),
                     removeLabels(context, [labelText.WAITING_FOR_COMMUNITY])
                 ]);
 
@@ -335,14 +337,40 @@ function addLabels(context, labelNames) {
 
 /**
  * @param {Context} context
+ * @param {boolean?} completed
  */
-function closeIssue(context) {
+async function closeIssue(context, completed) {
     // close issue
-    return context.octokit.issues.update(
-        context.issue({
-            state: 'closed'
-        })
+    // return await context.octokit.issues.update(
+    //     context.issue({
+    //         state: 'closed'
+    //     })
+    // );
+    // use GraphQL to close the issue with specified reason
+    const res = await context.octokit.graphql(
+        `
+            mutation closeIssue($id: ID!, $reason: IssueClosedStateReason) {
+                closeIssue(input: { issueId: $id, stateReason: $reason }) {
+                    clientMutationId
+                    issue {
+                        number
+                        closed
+                        state
+                        stateReason
+                    }
+                }
+            }
+        `,
+        {
+            id: context.payload.issue.node_id,
+            /**
+             * @type {IssueClosedStateReason}
+             */
+            reason: completed ? 'COMPLETED' : 'NOT_PLANNED'
+        }
     );
+    logger.info('close issue result: \n' + JSON.stringify(res, null, 2));
+    return res;
 }
 
 /**
@@ -491,11 +519,6 @@ async function hasCommented(context, commentText) {
     return comments.findIndex(comment => comment.user.type === 'Bot' && comment.body === commentText) > -1;
 }
 
-/**
- * PENDING import from @octokit/graphql-schema?
- * @typedef {'SPAM'|'ABUSE'|'OFF_TOPIC'|'OUTDATED'|'DUPLICATE'|'RESOLVED'} ReportedContentClassifiers
- */
-
 /**
  * Minimize a comment with specified classifier
  *
@@ -533,7 +556,7 @@ async function minimizeComment(context, commentText, classifier) {
         logger.info('minimize comment result: \n' + JSON.stringify(res, null, 2));
     } catch (e) {
         if (e instanceof GraphqlResponseError) {
-            logger.error('Graphql Request Failed');
+            logger.error('GraphQL Request Failed');
             logger.error(JSON.stringify(e.request, null, 2));
         }
         logger.error(e);
diff --git a/package-lock.json b/package-lock.json
index ff59777..01ee552 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -15,6 +15,7 @@
         "probot": "^12.2.5"
       },
       "devDependencies": {
+        "@octokit/graphql-schema": "^10.74.1",
         "jest": "^25.0.0",
         "nock": "^12.0.0",
         "nodemon": "^2.0.16",
@@ -903,6 +904,16 @@
         "universal-user-agent": "^6.0.0"
       }
     },
+    "node_modules/@octokit/graphql-schema": {
+      "version": "10.74.1",
+      "resolved": "https://registry.npmjs.org/@octokit/graphql-schema/-/graphql-schema-10.74.1.tgz",
+      "integrity": "sha512-FeaXZH/xwZ8aTtBBMvVg7slRTgvRZGsf407coLjl4pLTirWkN/PQ6DxZUSEeXsYJcYiMim4C1rSaPNzjhBx98w==",
+      "dev": true,
+      "dependencies": {
+        "graphql": "^15.0.0",
+        "graphql-tag": "^2.10.3"
+      }
+    },
     "node_modules/@octokit/oauth-authorization-url": {
       "version": "4.3.1",
       "resolved": "https://registry.npmjs.org/@octokit/oauth-authorization-url/-/oauth-authorization-url-4.3.1.tgz",
@@ -5175,6 +5186,36 @@
       "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.9.tgz",
       "integrity": "sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ=="
     },
+    "node_modules/graphql": {
+      "version": "15.8.0",
+      "resolved": "https://registry.npmjs.org/graphql/-/graphql-15.8.0.tgz",
+      "integrity": "sha512-5gghUc24tP9HRznNpV2+FIoq3xKkj5dTQqf4v0CpdPbFVwFkWoxOM+o+2OC9ZSvjEMTjfmG9QT+gcvggTwW1zw==",
+      "dev": true,
+      "engines": {
+        "node": ">= 10.x"
+      }
+    },
+    "node_modules/graphql-tag": {
+      "version": "2.12.6",
+      "resolved": "https://registry.npmjs.org/graphql-tag/-/graphql-tag-2.12.6.tgz",
+      "integrity": "sha512-FdSNcu2QQcWnM2VNvSCCDCVS5PpPqpzgFT8+GXzqJuoDd0CBncxCY278u4mhRO7tMgo2JjgJA5aZ+nWSQ/Z+xg==",
+      "dev": true,
+      "dependencies": {
+        "tslib": "^2.1.0"
+      },
+      "engines": {
+        "node": ">=10"
+      },
+      "peerDependencies": {
+        "graphql": "^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
+      }
+    },
+    "node_modules/graphql-tag/node_modules/tslib": {
+      "version": "2.4.0",
+      "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz",
+      "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==",
+      "dev": true
+    },
     "node_modules/growly": {
       "version": "1.3.0",
       "resolved": "https://registry.npmjs.org/growly/-/growly-1.3.0.tgz",
@@ -12375,6 +12416,16 @@
         "universal-user-agent": "^6.0.0"
       }
     },
+    "@octokit/graphql-schema": {
+      "version": "10.74.1",
+      "resolved": "https://registry.npmjs.org/@octokit/graphql-schema/-/graphql-schema-10.74.1.tgz",
+      "integrity": "sha512-FeaXZH/xwZ8aTtBBMvVg7slRTgvRZGsf407coLjl4pLTirWkN/PQ6DxZUSEeXsYJcYiMim4C1rSaPNzjhBx98w==",
+      "dev": true,
+      "requires": {
+        "graphql": "^15.0.0",
+        "graphql-tag": "^2.10.3"
+      }
+    },
     "@octokit/oauth-authorization-url": {
       "version": "4.3.1",
       "resolved": "https://registry.npmjs.org/@octokit/oauth-authorization-url/-/oauth-authorization-url-4.3.1.tgz",
@@ -15802,6 +15853,29 @@
       "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.9.tgz",
       "integrity": "sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ=="
     },
+    "graphql": {
+      "version": "15.8.0",
+      "resolved": "https://registry.npmjs.org/graphql/-/graphql-15.8.0.tgz",
+      "integrity": "sha512-5gghUc24tP9HRznNpV2+FIoq3xKkj5dTQqf4v0CpdPbFVwFkWoxOM+o+2OC9ZSvjEMTjfmG9QT+gcvggTwW1zw==",
+      "dev": true
+    },
+    "graphql-tag": {
+      "version": "2.12.6",
+      "resolved": "https://registry.npmjs.org/graphql-tag/-/graphql-tag-2.12.6.tgz",
+      "integrity": "sha512-FdSNcu2QQcWnM2VNvSCCDCVS5PpPqpzgFT8+GXzqJuoDd0CBncxCY278u4mhRO7tMgo2JjgJA5aZ+nWSQ/Z+xg==",
+      "dev": true,
+      "requires": {
+        "tslib": "^2.1.0"
+      },
+      "dependencies": {
+        "tslib": {
+          "version": "2.4.0",
+          "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz",
+          "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==",
+          "dev": true
+        }
+      }
+    },
     "growly": {
       "version": "1.3.0",
       "resolved": "https://registry.npmjs.org/growly/-/growly-1.3.0.tgz",
diff --git a/package.json b/package.json
index 75318a3..9706085 100644
--- a/package.json
+++ b/package.json
@@ -27,6 +27,7 @@
     "probot": "^12.2.5"
   },
   "devDependencies": {
+    "@octokit/graphql-schema": "^10.74.1",
     "jest": "^25.0.0",
     "nock": "^12.0.0",
     "nodemon": "^2.0.16",


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org