| const text = 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.removeLabel = null; |
| |
| if (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.addLabels.push('en'); |
| } |
| } |
| |
| _contain(txt) { |
| return this.body.indexOf(txt) > -1; |
| } |
| } |
| |
| module.exports = Issue; |