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/06/20 02:18:29 UTC
[echarts-bot] branch master updated: fix: avoid potential duplicate comments from bot
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 583e9a1 fix: avoid potential duplicate comments from bot
583e9a1 is described below
commit 583e9a14a80246e50b01bd24ce9f4f73c153afd0
Author: plainheart <yh...@all-my-life.cn>
AuthorDate: Mon Jun 20 10:17:11 2022 +0800
fix: avoid potential duplicate comments from bot
---
index.js | 35 +++++++++++++++++++++++++----------
1 file changed, 25 insertions(+), 10 deletions(-)
diff --git a/index.js b/index.js
index 4786f53..5367741 100644
--- a/index.js
+++ b/index.js
@@ -57,7 +57,7 @@ module.exports = (/** @type import('probot').Probot */ app) => {
});
app.on(['issues.reopened'], context => {
- // unlabel invalid & missing-title when reopened by bot or commiters
+ // unlabel invalid & missing-title when reopened by bot or committers
if (context.payload.issue.user.login !== context.payload.sender.login) {
return removeLabels(context, [
labelText.INVALID,
@@ -281,7 +281,7 @@ module.exports = (/** @type import('probot').Probot */ app) => {
});
app.onError(e => {
- logger.error('bot occured an error');
+ logger.error('bot occurred an error');
logger.error(e);
});
}
@@ -347,19 +347,24 @@ function openIssue(context) {
* @param {import('probot').Context} context
* @param {string} commentText
*/
-function commentIssue(context, commentText) {
- // create comment
- return new Promise(resolve => {
- if (!commentText) {
- resolve();
+async function commentIssue(context, commentText) {
+ if (!commentText) {
+ return;
+ }
+ try {
+ if (await hasCommented(context, commentText)) {
+ logger.info('skip current comment as it has been submitted');
return;
}
- return context.octokit.issues.createComment(
+ return await context.octokit.issues.createComment(
context.issue({
body: commentText
})
);
- });
+ } catch (e) {
+ logger.error('failed to comment')
+ logger.error(e);
+ }
}
/**
@@ -417,7 +422,7 @@ async function translateIssue(context, createdIssue) {
* @param {string} body
*/
function fixMarkdown(body) {
- return body.replace(/\! \[/g, '![').replace(/\] \(/g, '](')
+ return body.replace(/\! \[/g, '![').replace(/\] \(/g, '](');
}
/**
@@ -461,3 +466,13 @@ function checkDoc(content, commentText, addLabelList, removeLabelList) {
}
return commentText;
}
+
+/**
+ * Check if a comment has submitted
+ * @param {import('probot').Context} context
+ * @param {string} commentText
+ */
+async function hasCommented(context, commentText) {
+ const comments = (await context.octokit.issues.listComments(context.issue())).data;
+ return comments.findIndex(comment => comment.user.type === 'Bot' && comment.body === commentText) > -1;
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org