Skip to content

Commit

Permalink
fix: handle synchronize, labelled and unlabelled events
Browse files Browse the repository at this point in the history
  • Loading branch information
christophehurpeau committed Oct 21, 2018
1 parent bf598c5 commit 03bec47
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 18 deletions.
40 changes: 26 additions & 14 deletions lib/context/repoContext.js
Expand Up @@ -28,7 +28,27 @@ const initRepoContext = async (context, config) => {

// const updateStatusCheck = (context, reviewGroup, statusInfo) => {};

const updateStatusCheckFromLabels = (
context,
labels = context.payload.pull_request.labels || []
) => {
if (labels.some((label) => needsReviewLabelIds.includes(label.id))) {
return;
}

addStatusCheck(context, {
status: 'completed',
conclusion: 'success',
output: {
title: 'All reviews done !',
summary: 'Pull request was successfully reviewed ',
},
});
};

return Object.assign(repoContext, {
updateStatusCheckFromLabels,

updateReviewStatus: async (
context,
reviewGroup,
Expand Down Expand Up @@ -88,22 +108,14 @@ const initRepoContext = async (context, config) => {
status: 'in_progress',
});
} else if (toDelete.has('needsReview')) {
if (
[...newLabels].some((label) => needsReviewLabelIds.includes(label.id))
) {
return;
}

addStatusCheck(context, {
status: 'completed',
conclusion: 'success',
output: {
title: 'All reviews done !',
summary: 'Pull request was successfully reviewed ',
},
});
updateStatusCheckFromLabels(context, [...newLabels]);
}
},

addStatusCheckToLatestCommit: (context) =>
// old and new sha
// const { before, after } = context.payload;
updateStatusCheckFromLabels(context),
});
};

Expand Down
23 changes: 19 additions & 4 deletions lib/index.js
Expand Up @@ -293,10 +293,25 @@ module.exports = (app) => {
)} dismissed your review on ${pr.html_url}, he requests a new one !`
);
}
});

app.on(
['pull_request.labeled', 'pull_request.unlabeled'],
async (context) => {
const sender = context.payload.sender;
if (sender.type === 'Bot') return;

const repoContext = await obtainRepoContext(context);
if (!repoContext) return;

repoContext.updateStatusCheckFromLabels(context);
}
);

app.on('pull_request.synchronize', async (context) => {
const repoContext = await obtainRepoContext(context);
if (!repoContext) return;

// repoContext.slack.postMessage(
// reviewer.login,
// `Your review was dismissed on ${pr.html_url}`
// );
repoContext.addStatusCheckToLatestCommit(context);
});
};

0 comments on commit 03bec47

Please sign in to comment.