This is an automated email from the ASF dual-hosted git repository. ovilia pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-echarts-bot.git
commit 4526a41d164814c17ed4a20e2498d0f24caf4cba Author: Ovilia <[email protected]> AuthorDate: Tue Nov 20 16:08:30 2018 +0800 feat: 🎸 listen to comments --- index.js | 55 ++++++++++++++++++++++++++++++++++++++------------- src/coreCommitters.js | 19 ++++++++++++++++++ src/issue.js | 2 +- 3 files changed, 61 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index 0d42caa..338360d 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,5 @@ const Issue = require('./src/issue'); +const coreCommitters = require('./src/coreCommitters'); module.exports = app => { app.on(['issues.opened', 'issues.edited'], async context => { @@ -23,25 +24,51 @@ module.exports = app => { })) : Promise.resolve(); - const removeLabels = issue.isMeetAllRequires() - ? context.github.issues.deleteLabel(context.issue({ - name: 'waiting-for-author' - })) - : context.github.issues.deleteLabel(context.issue({ - name: 'waiting-for-help' - })); - removeLabels.catch(err => { - // Ignore error caused by not existing. - if (err.message !== 'Not Found') { - throw(err); - } - }); + const removeLabel = getRemoveLabel( + context, + issue.isMeetAllRequires() + ? 'waiting-for-author' + : 'waiting-for-help' + ); const comment = context.github.issues.createComment(context.issue({ body: issue.response })); - return Promise.all([addLabels, removeLabels, comment]); + return Promise.all([addLabels, removeLabel, comment]); + } + }); + + app.on('issue_comment.created', async context => { + const commenter = context.payload.comment.user.login; + let removeLabel, addLabel; + if (coreCommitters.isCoreCommitter(commenter)) { + // New comment from core committers + removeLabel = getRemoveLabel(context, 'waiting-for-help'); + addLabel = context.github.issues.addLabels(context.issue({ + labels: ['waiting-for-author'] + })); + } + else if (commenter === context.payload.issue.user.login) { + // New comment from issue author + removeLabel = getRemoveLabel(context, 'waiting-for-author'); + addLabel = context.github.issues.addLabels(context.issue({ + labels: ['waiting-for-help'] + })); + } + return Promise.all([removeLabel, addLabel]); + }); +} + +function getRemoveLabel(context, name) { + return context.github.issues.deleteLabel( + context.issue({ + name: name + }) + ).catch(err => { + // Ignore error caused by not existing. + if (err.message !== 'Not Found') { + throw(err); } }); } diff --git a/src/coreCommitters.js b/src/coreCommitters.js new file mode 100644 index 0000000..6d9cf9f --- /dev/null +++ b/src/coreCommitters.js @@ -0,0 +1,19 @@ +const committers = [ + 'pissang', + '100pah', + 'Ovilia', + 'deqingli' +]; + +function getCoreCommitters() { + return committers; +} + +function isCoreCommitter(user) { + return committers.indexOf(user) > -1; +} + +module.exports = { + getCoreCommitters: getCoreCommitters, + isCoreCommitter: isCoreCommitter +}; diff --git a/src/issue.js b/src/issue.js index a8be8f8..73077ff 100644 --- a/src/issue.js +++ b/src/issue.js @@ -150,7 +150,7 @@ class Issue { } _matches(text) { - return this.body.indexOf('- [x] ' + text) > -1; + return this.body.indexOf('- [x] Required: ' + text) > -1; } } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
