Skip to content

Commit

Permalink
fix: createStatusCheckFromLabels
Browse files Browse the repository at this point in the history
  • Loading branch information
christophehurpeau committed Oct 21, 2018
1 parent 03bec47 commit 9e7fee9
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions lib/context/repoContext.js
Expand Up @@ -26,28 +26,46 @@ const initRepoContext = async (context, config) => {
);
};

const createInProgressStatusCheck = (context) =>
addStatusCheck(context, {
status: 'in_progress',
});

const createDoneStatusCheck = (context) =>
addStatusCheck(context, {
status: 'completed',
conclusion: 'success',
completed_at: new Date(),
output: {
title: '✓ All reviews done !',
summary: 'Pull request was successfully reviewed',
},
});

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

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

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

addStatusCheck(context, {
status: 'completed',
conclusion: 'success',
output: {
title: 'All reviews done !',
summary: 'Pull request was successfully reviewed ',
},
});
const createStatusCheckFromLabels = (context) => {
if (isAllReviewsDone(labels)) {
return createDoneStatusCheck(context);
} else {
return createInProgressStatusCheck(context);
}
};

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

updateReviewStatus: async (
context,
Expand Down Expand Up @@ -104,9 +122,7 @@ const initRepoContext = async (context, config) => {
}

if (toAdd.has('needsReview')) {
addStatusCheck(context, {
status: 'in_progress',
});
createInProgressStatusCheck(context);
} else if (toDelete.has('needsReview')) {
updateStatusCheckFromLabels(context, [...newLabels]);
}
Expand All @@ -115,7 +131,7 @@ const initRepoContext = async (context, config) => {
addStatusCheckToLatestCommit: (context) =>
// old and new sha
// const { before, after } = context.payload;
updateStatusCheckFromLabels(context),
createStatusCheckFromLabels(context),
});
};

Expand Down

0 comments on commit 9e7fee9

Please sign in to comment.