blob: 6139a363a8fbf316b9808978c4d07ef43b486ff1 [file] [log] [blame]
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;
this.issue = context.payload.issue;
this.body = this.issue.body;
this.issueType = null;
this.addLabels = [];
this.removeLabel = null;
// if author is committer, do not check if using template
const isCore = isCommitter(this.issue.author_association, this.issue.user.login);
if (isCore || this.isUsingTemplate()) {
this.init();
}
else {
this.response = text.NOT_USING_TEMPLATE;
this.addLabels.push('invalid');
}
}
init() {
if (this._contain('Steps to reproduce')) {
this.issueType = 'bug';
}
else if (this._contain('What problem does this feature solve')) {
this.issueType = 'new-feature';
}
else {
this.response = text.NOT_USING_TEMPLATE;
return;
}
this._computeResponse();
}
isUsingTemplate() {
return this.body.indexOf('generated by echarts-issue-helper') > -1;
}
_computeResponse() {
switch(this.context.payload.action) {
case 'opened':
case 'reopened':
this.response = text.ISSUE_CREATED;
break;
case 'edited':
this.response = text.ISSUE_UPDATED;
this.removeLabel = 'waiting-for: help';
break;
}
this.addLabels.push('waiting-for: community');
this.addLabels.push('pending');
this.addLabels.push(this.issueType);
const isInEnglish = this._contain('This issue is in English');
if (isInEnglish && !this._isMainlyUsingChinese()) {
this.addLabels.push('en');
}
}
_contain(txt) {
return this.body.indexOf(txt) > -1;
}
_isMainlyUsingChinese() {
return this.body.match(REG_CHN_CHAR).length > MAX_CHN_CHAR_COUNT;
}
}
module.exports = Issue;