From 5510b947678e0ded614ff7e798c2a6144911869d Mon Sep 17 00:00:00 2001 From: plainheart Date: Mon, 23 Nov 2020 12:52:59 +0800 Subject: [PATCH] tweak: do not add en label when issue contains over 5 Chinese characters. --- src/issue.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/issue.js b/src/issue.js index efcbe60..6139a36 100644 --- a/src/issue.js +++ b/src/issue.js @@ -1,6 +1,9 @@ const text = require('./text'); const { isCommitter } = require('./coreCommitters'); +const REG_CHN_CHAR = /[\u4e00-\u9fa5]/g; +const MAX_CHN_CHAR_COUNT = 5; + class Issue { constructor(context) { this.context = context; @@ -57,7 +60,7 @@ class Issue { this.addLabels.push(this.issueType); const isInEnglish = this._contain('This issue is in English'); - if (isInEnglish) { + if (isInEnglish && !this._isMainlyUsingChinese()) { this.addLabels.push('en'); } } @@ -65,6 +68,10 @@ class Issue { _contain(txt) { return this.body.indexOf(txt) > -1; } + + _isMainlyUsingChinese() { + return this.body.match(REG_CHN_CHAR).length > MAX_CHN_CHAR_COUNT; + } } module.exports = Issue;