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 2021/02/23 07:31:11 UTC

[echarts-bot] branch master updated: fix: remove comments in issue body before translating.

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 0ae6f36  fix: remove comments in issue body before translating.
0ae6f36 is described below

commit 0ae6f36ac246e178c16f7373a2f8eadc82e8d512
Author: plainheart <yh...@all-my-life.cn>
AuthorDate: Tue Feb 23 15:30:24 2021 +0800

    fix: remove comments in issue body before translating.
---
 index.js     | 4 ++--
 src/issue.js | 3 ++-
 src/util.js  | 5 +++++
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/index.js b/index.js
index 0540f08..fb01555 100644
--- a/index.js
+++ b/index.js
@@ -2,7 +2,7 @@ const Issue = require('./src/issue');
 const text = require('./src/text');
 const { isCommitter } = require('./src/coreCommitters');
 const logger = require('./src/logger');
-const { replaceAll } = require('./src/util');
+const { replaceAll, removeHTMLComment } = require('./src/util');
 
 module.exports = (app) => {
     app.on(['issues.opened'], async context => {
@@ -238,7 +238,7 @@ async function translateIssue (context, createdIssue) {
     } = createdIssue;
 
     const titleNeedsTranslation = translatedTitle && translatedTitle[0] !== title;
-    const bodyNeedsTranslation = translatedBody && translatedBody[0] !== body;
+    const bodyNeedsTranslation = translatedBody && translatedBody[0] !== removeHTMLComment(body);
     const needsTranslation = titleNeedsTranslation || bodyNeedsTranslation;
 
     logger.info('issue needs translation: ' + needsTranslation);
diff --git a/src/issue.js b/src/issue.js
index 136ab75..c359ae2 100644
--- a/src/issue.js
+++ b/src/issue.js
@@ -1,6 +1,7 @@
 const text = require('./text');
 const { isCommitter } = require('./coreCommitters');
 const { translate } = require('./translator');
+const { removeHTMLComment } = require('./util');
 
 class Issue {
     constructor(context) {
@@ -61,7 +62,7 @@ class Issue {
         if (res) {
             this.translatedTitle = res.lang !== 'en' && [res.translated, res.lang];
         }
-        res = await translate(this.body);
+        res = await translate(removeHTMLComment(this.body));
         if (res) {
             this.translatedBody = res.lang !== 'en' && [res.translated, res.lang];
         }
diff --git a/src/util.js b/src/util.js
index e10fdfe..09ee443 100644
--- a/src/util.js
+++ b/src/util.js
@@ -6,11 +6,16 @@ function removeCodeAndComment(body) {
         .replace(/-{3}\s?/g, '');
 }
 
+function removeHTMLComment (body) {
+    return body.replace(/<!--[\w\W\s]*?-->/gmi, '');
+}
+
 function replaceAll(str, search, replacement) {
 	return str.replace(new RegExp(search, 'g'), replacement);
 }
 
 module.exports = {
 	removeCodeAndComment,
+    removeHTMLComment,
 	replaceAll
 }


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