Skip to content

Commit

Permalink
feat: update comment steps state on review events
Browse files Browse the repository at this point in the history
  • Loading branch information
christophehurpeau committed Dec 19, 2022
1 parent b03bd10 commit c94c102
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 28 deletions.
@@ -0,0 +1,30 @@
import type { EventsWithRepository } from 'context/repoContext';
import type { ProbotEvent } from '../../probot-types';
import type { ReviewflowPrContext } from '../utils/createPullRequestContext';
import { updatePrCommentBodyIfNeeded } from './updatePrCommentBody';
import {
updateCommentBodyProgress,
defaultCommentBody,
} from './utils/body/updateBody';
import type { StepsState } from './utils/steps/calcStepsState';

export async function updateCommentBodyProgressFromStepsState<
Name extends EventsWithRepository,
>(
stepsState: StepsState,
context: ProbotEvent<Name>,
reviewflowPrContext: ReviewflowPrContext,
): Promise<void> {
if (reviewflowPrContext.commentBody === defaultCommentBody) return;

const newCommentBody = updateCommentBodyProgress(
reviewflowPrContext.commentBody,
stepsState,
);

await updatePrCommentBodyIfNeeded(
context,
reviewflowPrContext,
newCommentBody,
);
}
22 changes: 15 additions & 7 deletions src/events/pr-handlers/reviewDismissed.ts
Expand Up @@ -3,6 +3,7 @@ import type { AppContext } from '../../context/AppContext';
import * as slackUtils from '../../slack/utils';
import { checkIfIsThisBot } from '../../utils/github/isBotUser';
import { autoApproveAndAutoMerge } from './actions/autoApproveAndAutoMerge';
import { updateCommentBodyProgressFromStepsState } from './actions/updateCommentBodyProgressFromStepsState';
import { updateReviewStatus } from './actions/updateReviewStatus';
import { updateStatusCheckFromStepsState } from './actions/updateStatusCheckFromStepsState';
import { calcStepsState } from './actions/utils/steps/calcStepsState';
Expand Down Expand Up @@ -97,13 +98,20 @@ export default function reviewDismissed(
labels: newLabels,
});

await updateStatusCheckFromStepsState(
stepsState,
pullRequest,
context,
appContext,
reviewflowPrContext,
);
await Promise.all([
updateStatusCheckFromStepsState(
stepsState,
pullRequest,
context,
appContext,
reviewflowPrContext,
),
updateCommentBodyProgressFromStepsState(
stepsState,
context,
reviewflowPrContext,
),
]);
}

if (updatedPr.assignees) {
Expand Down
22 changes: 15 additions & 7 deletions src/events/pr-handlers/reviewRequestRemoved.ts
Expand Up @@ -2,6 +2,7 @@ import type { Probot } from 'probot';
import type { AppContext } from '../../context/AppContext';
import * as slackUtils from '../../slack/utils';
import { autoMergeIfPossible } from './actions/autoMergeIfPossible';
import { updateCommentBodyProgressFromStepsState } from './actions/updateCommentBodyProgressFromStepsState';
import { updateReviewStatus } from './actions/updateReviewStatus';
import { updateStatusCheckFromStepsState } from './actions/updateStatusCheckFromStepsState';
import { calcStepsState } from './actions/utils/steps/calcStepsState';
Expand Down Expand Up @@ -100,13 +101,20 @@ export default function reviewRequestRemoved(
labels: newLabels,
});

await updateStatusCheckFromStepsState(
stepsState,
pullRequest,
context,
appContext,
reviewflowPrContext,
);
await Promise.all([
updateStatusCheckFromStepsState(
stepsState,
pullRequest,
context,
appContext,
reviewflowPrContext,
),
updateCommentBodyProgressFromStepsState(
stepsState,
context,
reviewflowPrContext,
),
]);
}

if (approved && !hasChangesRequestedInReviews) {
Expand Down
22 changes: 15 additions & 7 deletions src/events/pr-handlers/reviewRequested.ts
@@ -1,6 +1,7 @@
import type { Probot } from 'probot';
import type { AppContext } from '../../context/AppContext';
import * as slackUtils from '../../slack/utils';
import { updateCommentBodyProgressFromStepsState } from './actions/updateCommentBodyProgressFromStepsState';
import { updateReviewStatus } from './actions/updateReviewStatus';
import { updateStatusCheckFromStepsState } from './actions/updateStatusCheckFromStepsState';
import { calcStepsState } from './actions/utils/steps/calcStepsState';
Expand Down Expand Up @@ -64,13 +65,20 @@ export default function reviewRequested(
labels: newLabels,
});

await updateStatusCheckFromStepsState(
stepsState,
pullRequest,
context,
appContext,
reviewflowPrContext,
);
await Promise.all([
updateStatusCheckFromStepsState(
stepsState,
pullRequest,
context,
appContext,
reviewflowPrContext,
),
updateCommentBodyProgressFromStepsState(
stepsState,
context,
reviewflowPrContext,
),
]);
}

/* update slack home */
Expand Down
22 changes: 15 additions & 7 deletions src/events/pr-handlers/reviewSubmitted.ts
Expand Up @@ -8,6 +8,7 @@ import * as slackUtils from '../../slack/utils';
import { ExcludesNullish } from '../../utils/Excludes';
import { createSlackMessageWithSecondaryBlock } from '../../utils/slack/createSlackMessageWithSecondaryBlock';
import { autoMergeIfPossible } from './actions/autoMergeIfPossible';
import { updateCommentBodyProgressFromStepsState } from './actions/updateCommentBodyProgressFromStepsState';
import { updateReviewStatus } from './actions/updateReviewStatus';
import { updateStatusCheckFromStepsState } from './actions/updateStatusCheckFromStepsState';
import { calcStepsState } from './actions/utils/steps/calcStepsState';
Expand Down Expand Up @@ -140,13 +141,20 @@ export default function reviewSubmitted(
labels: newLabels,
});

await updateStatusCheckFromStepsState(
stepsState,
pullRequest,
context,
appContext,
reviewflowPrContext,
);
await Promise.all([
updateStatusCheckFromStepsState(
stepsState,
pullRequest,
context,
appContext,
reviewflowPrContext,
),
updateCommentBodyProgressFromStepsState(
stepsState,
context,
reviewflowPrContext,
),
]);
}

if (approved && !hasChangesRequestedInReviews) {
Expand Down

0 comments on commit c94c102

Please sign in to comment.