blob: 0b3472ec91976b4b6d32f7b0d3c4c4a1e3f343f2 [file] [log] [blame]
const {NOT_USING_TEMPLATE, ISSUE_CREATED, ISSUE_UPDATED} = require('./text');
class Issue {
constructor(context) {
this.context = context;
this.issue = context.payload.issue;
this.body = this.issue.body;
this.issueType = null;
this.addLabels = [];
this.removeLabels = [];
if (this.isUsingTemplate()) {
this.init();
}
else {
this.response = 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 = 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 = ISSUE_CREATED;
break;
case 'edited':
this.response = ISSUE_UPDATED;
this.removeLabels.push('waiting-for: help');
break;
}
this.addLabels.push('waiting-for: help');
this.addLabels.push('pending');
this.addLabels.push(this.issueType);
const isInEnglish = this._contain('This issue is in English');
if (isInEnglish) {
this.addLabels.push('en');
}
}
_contain(txt) {
return this.body.indexOf(txt) > -1;
}
}
module.exports = Issue;