Skip to content
Permalink
Browse files
feat: pull request handling
  • Loading branch information
Ovilia committed Jan 13, 2020
1 parent cb262c7 commit ab6abe3034644b4d5de5331351c3df4919f422d8
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 31 deletions.
@@ -1,4 +1,4 @@
.env
.env*
lib
node_modules
.DS_Store
@@ -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';
}
@@ -2,7 +2,10 @@ const committers = [
'pissang',
'100pah',
'Ovilia',
'deqingli'
'deqingli',
'susiwen8',
'cuijian-dexter',
'SnailSword'
];

function getCoreCommitters() {
@@ -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 secretary@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-subscribe@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,

0 comments on commit ab6abe3

Please sign in to comment.