Skip to content

Commit

Permalink
feat: use pending states for reviewflow check
Browse files Browse the repository at this point in the history
  • Loading branch information
christophehurpeau committed Oct 19, 2023
1 parent 7315c50 commit 6486198
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/accountConfigs/types.ts
Expand Up @@ -2,7 +2,7 @@ import type { MessageCategory } from '../dm/MessageCategory';
import type { Options } from '../events/pr-handlers/actions/utils/body/prOptions';

export interface StatusInfo {
type: 'failure' | 'success';
type: 'failure' | 'pending' | 'success';
inBody?: true;
url?: string;
title: string;
Expand Down
31 changes: 25 additions & 6 deletions src/events/pr-handlers/actions/updateStatusCheckFromStepsState.ts
Expand Up @@ -16,7 +16,7 @@ import createStatus, { isSameStatus } from './utils/createStatus';
import hasLabelInPR from './utils/labels/hasLabelInPR';
import type { StepsState } from './utils/steps/calcStepsState';

type ReviewflowStatusCheckState = 'failure' | 'success';
type ReviewflowStatusCheckState = 'failure' | 'pending' | 'success';

const addStatusCheck = async <EventName extends EventsWithRepository>(
pullRequest: PullRequestWithDecentData,
Expand Down Expand Up @@ -55,14 +55,18 @@ const addStatusCheck = async <EventName extends EventsWithRepository>(
};

if (prCheck) {
if (prCheck.conclusion !== state || prCheck.output.title !== description) {
const conclusion = state === 'pending' ? 'failure' : state;
if (
prCheck.conclusion !== conclusion ||
prCheck.output.title !== description
) {
await context.octokit.checks.create(
context.repo({
name: process.env.REVIEWFLOW_NAME!,
head_sha: pullRequest.head.sha,
started_at: pullRequest.created_at,
status: 'completed',
conclusion: state,
conclusion,
completed_at: new Date().toISOString(),
output: {
title: description,
Expand All @@ -82,7 +86,7 @@ const addStatusCheck = async <EventName extends EventsWithRepository>(
await Promise.all([
previousSha &&
(previousStatus
? previousStatus.type === 'failure'
? previousStatus.type !== 'success'
: state === 'failure') &&
createStatus(context, '', previousSha, {
type: 'success',
Expand Down Expand Up @@ -136,6 +140,21 @@ export const updateStatusCheckFromStepsState = <
previousSha,
).then(() => 'failure');

const createPendingStatusCheck = (
description: string,
): Promise<ReviewflowStatusCheckState> =>
addStatusCheck(
pullRequest,
context,
appContext,
reviewflowPrContext,
{
state: 'pending',
description,
},
previousSha,
).then(() => 'pending');

// PR Merged
if (pullRequest.merged_at) {
return addStatusCheck(
Expand Down Expand Up @@ -217,7 +236,7 @@ export const updateStatusCheckFromStepsState = <
}

if (stepsState.checks.isInProgress) {
return createFailedStatusCheck('Checks in progress');
return createPendingStatusCheck('Checks in progress');
}
}

Expand All @@ -227,7 +246,7 @@ export const updateStatusCheckFromStepsState = <
stepsState.codeReview.hasRequestedReviewers ||
stepsState.codeReview.hasRequestedTeams
) {
return createFailedStatusCheck(
return createPendingStatusCheck(
`Awaiting review from: ${[
...(pullRequest.requested_reviewers || []),
...(pullRequest.requested_teams || []),
Expand Down

0 comments on commit 6486198

Please sign in to comment.