Skip to content

Commit

Permalink
fix: review status check when approved and still has needsReview
Browse files Browse the repository at this point in the history
  • Loading branch information
christophehurpeau committed Oct 27, 2018
1 parent 988a2cc commit 50a0b5c
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions lib/context/repoContext.js
Expand Up @@ -14,6 +14,11 @@ const initRepoContext = async (context, config) => {
.filter(Boolean)
.map((name) => labels[name].id);

const approvedReviewLabelIds = Object.keys(config.labels.review)
.map((key) => config.labels.review[key].approved)
.filter(Boolean)
.map((name) => labels[name].id);

const addStatusCheck = (context, statusInfo) => {
const pr = context.payload.pull_request;

Expand Down Expand Up @@ -45,29 +50,26 @@ const initRepoContext = async (context, config) => {

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

const isAllReviewsDone = (labels) =>
!labels.some((label) => needsReviewLabelIds.includes(label.id));
const hasNeedsReview = labels.some((label) =>
needsReviewLabelIds.includes(label.id)
);
const hasApprovesReview = labels.some((label) =>
approvedReviewLabelIds.includes(label.id)
);

const updateStatusCheckFromLabels = (
context,
labels = context.payload.pull_request.labels || []
) => {
if (isAllReviewsDone(labels)) {
return createDoneStatusCheck(context);
}
};

const createStatusCheckFromLabels = (context) => {
const labels = context.payload.pull_request.labels || [];
if (isAllReviewsDone(labels)) {
return createDoneStatusCheck(context);
} else {
if (hasNeedsReview(labels)) {
return createInProgressStatusCheck(context);
} else if (hasApprovesReview(labels)) {
return createDoneStatusCheck(context);
}
};

return Object.assign(repoContext, {
updateStatusCheckFromLabels: createStatusCheckFromLabels,
updateStatusCheckFromLabels,

updateReviewStatus: async (
context,
Expand Down Expand Up @@ -133,7 +135,7 @@ const initRepoContext = async (context, config) => {
addStatusCheckToLatestCommit: (context) =>
// old and new sha
// const { before, after } = context.payload;
createStatusCheckFromLabels(context),
updateStatusCheckFromLabels(context),
});
};

Expand Down

0 comments on commit 50a0b5c

Please sign in to comment.