fix: remove comments in issue body before translating.
diff --git a/index.js b/index.js
index 0540f08..fb01555 100644
--- a/index.js
+++ b/index.js
@@ -2,7 +2,7 @@
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 @@
} = 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 @@
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 @@
.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
}