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
The following commit(s) were added to refs/heads/master by this push: new ab6abe3 feat: pull request handling ab6abe3 is described below commit ab6abe3034644b4d5de5331351c3df4919f422d8 Author: Ovilia <zwl.s...@gmail.com> AuthorDate: Mon Jan 13 19:17:44 2020 +0800 feat: pull request handling --- .gitignore | 2 +- index.js | 73 ++++++++++++++++++++++++++++++++++++--------------- src/coreCommitters.js | 5 +++- src/text.js | 14 +++++----- 4 files changed, 63 insertions(+), 31 deletions(-) diff --git a/.gitignore b/.gitignore index b8e0d49..990cb14 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -.env +.env* lib node_modules .DS_Store diff --git a/index.js b/index.js index 48374ca..fe0422a 100644 --- a/index.js +++ b/index.js @@ -44,8 +44,8 @@ module.exports = app => { case 'inactive': return Promise.all([commentIssue(context, text.INACTIVE_ISSUE), closeIssue(context)]); - case 'waiting-for: author': - return commentIssue(context, replaceAt(text.ISSUE_TAGGED_WAITING_AUTHOR)); + // case 'waiting-for: author': + // return commentIssue(context, replaceAt(text.ISSUE_TAGGED_WAITING_AUTHOR)); case 'difficulty: easy': return commentIssue(context, replaceAt(text.ISSUE_TAGGED_EASY)); @@ -56,6 +56,12 @@ module.exports = app => { }); app.on('issue_comment.created', async context => { + const isPr = context.payload.issue.html_url.indexOf('/pull/') > -1; + if (isPr) { + // Do nothing when pr is commented + return; + } + const commenter = context.payload.comment.user.login; const isCommenterAuthor = commenter === context.payload.issue.user.login; let removeLabel; @@ -75,25 +81,46 @@ module.exports = app => { }); // Pull Requests Not Tested Yet - // app.on(['pull_request.opened', 'pull_request.reopened'], async context => { - // console.log('pull request open'); - // const comment = context.github.issues.createComment(context.issue({ - // body: text.PR_OPENED - // })); - - // return Promise.all([comment]); - // }); - - // app.on(['pull_request.closed'], async context => { - // console.log('pull request close'); - // console.log(context.payload); - // const isMerged = context.payload['pull_request'].merged; - // const comment = context.github.issues.createComment(context.issue({ - // body: isMerged ? text.PR_MERGED : text.PR_NOT_MERGED - // })); - - // return Promise.all([comment]); - // }); + app.on(['pull_request.opened', 'pull_request.reopened'], async context => { + const auth = context.payload.pull_request.author_association; + const comment = context.github.issues.createComment(context.issue({ + body: isCommitter(auth) ? text.PR_OPENED_BY_COMMITTER : text.PR_OPENED + })); + + const labelList = ['PR: awaiting review']; + if (isCommitter(auth)) { + labelList.push('PR: author is committer'); + } + const addLabel = context.github.issues.addLabels(context.issue({ + labels: labelList + })); + + const removeLabel = getRemoveLabel(context, 'PR: revision needed'); + return Promise.all([comment, addLabel, removeLabel]); + }); + + app.on(['pull_request.closed'], async context => { + const isMerged = context.payload['pull_request'].merged; + if (isMerged) { + const comment = context.github.issues.createComment(context.issue({ + body: text.PR_MERGED + })); + return Promise.all([comment]); + } + }); + + app.on(['pull_request_review.submitted'], async context => { + if (context.payload.review.state === 'changes_requested' + && isCommitter(context.payload.review.author_association) + ) { + const addLabel = context.github.issues.addLabels(context.issue({ + labels: ['PR: revision needed'] + })); + + const removeLabel = getRemoveLabel(context, 'PR: awaiting review'); + return Promise.all([addLabel, removeLabel]); + } + }); } function getRemoveLabel(context, name) { @@ -126,3 +153,7 @@ function commentIssue(context, commentText) { function replaceAll(str, search, replacement) { return str.replace(new RegExp(search, 'g'), replacement); } + +function isCommitter(auth) { + return auth === 'COLLABORATOR' || auth === 'MEMBER' || auth === 'OWNER' || auth === 'CONTRIBUTOR'; +} diff --git a/src/coreCommitters.js b/src/coreCommitters.js index c13147e..10bf89f 100644 --- a/src/coreCommitters.js +++ b/src/coreCommitters.js @@ -2,7 +2,10 @@ const committers = [ 'pissang', '100pah', 'Ovilia', - 'deqingli' + 'deqingli', + 'susiwen8', + 'cuijian-dexter', + 'SnailSword' ]; function getCoreCommitters() { diff --git a/src/text.js b/src/text.js index 80cd25b..ab01a9a 100644 --- a/src/text.js +++ b/src/text.js @@ -45,17 +45,14 @@ const ISSUE_TAGGED_PRIORITY_HIGH = const PR_OPENED = `Thanks for your contribution! -@Ovilia Please check out this PR.`; +The community will review it ASAP. In the meanwhile, please checkout [the coding standard](https://echarts.apache.org/en/coding-standard.html) and Wiki about [How to make a pull request](https://github.com/apache/incubator-echarts/wiki/How-to-make-a-pull-request).`; -const PR_MERGED = - `Congratulations! Your PR has been merged. Thanks for your contribution! 👍 +const PR_OPENED_BY_COMMITTER = PR_OPENED + ` -Now you are one of the ECharts contributors. Since we joined the Apache group, you need to assign [ICLA](https://www.apache.org/licenses/icla.pdf) file if this is your first PR. -Please fill in the PDF and print it, then sign on it and send the scanned file to secret...@apache.org and oviliazhang at gmail.com with the title \`ICLA for incubator-echarts project\`. -This may be a little tricky, and sorry for the trouble. This is required for the first time your commit is merged in. If you refused, your commit will be backed off. +The pull request is marked to be \`PR: author is committer\` because you are a committer of this project.`; -You may send an email to dev-subscr...@echarts.apache.org to subscribe our developing discussion on mail list. -`; +const PR_MERGED = + `Congratulations! Your PR has been merged. Thanks for your contribution! 👍`; const PR_NOT_MERGED = `I'm sorry your PR didn't get merged. Don't get frustrated. Maybe next time. 😛` @@ -83,6 +80,7 @@ module.exports = { PR_OPENED, LABEL_HOWTO, PR_MERGED, + PR_OPENED_BY_COMMITTER, PR_NOT_MERGED, ISSUE_TAGGED_WAITING_AUTHOR, ISSUE_TAGGED_EASY, --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@echarts.apache.org For additional commands, e-mail: commits-h...@echarts.apache.org