Skip to content

Commit

Permalink
fix: update progress on closed and reopened events
Browse files Browse the repository at this point in the history
  • Loading branch information
christophehurpeau committed Jan 21, 2023
1 parent 8ba1d2c commit acdf3d7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/events/pr-handlers/actions/utils/steps/mergeStep.ts
Expand Up @@ -2,6 +2,7 @@ import type { BaseStepState, CalcStepOptions } from './BaseStepState';

export interface MergeStepState extends BaseStepState {
isMerged: boolean;
isClosed: boolean;
}

export function calcMergeStep<GroupNames extends string>({
Expand All @@ -10,13 +11,16 @@ export function calcMergeStep<GroupNames extends string>({
labels,
}: CalcStepOptions<GroupNames>): MergeStepState {
const isMerged = !!pullRequest.merged_at;
const isClosed = !!pullRequest.closed_at;

return {
state: (() => {
if (isMerged) return 'passed';
if (isClosed) return 'failed';
if (pullRequest.auto_merge) return 'in-progress';
return 'not-started';
})(),
isMerged,
isClosed,
};
}
20 changes: 16 additions & 4 deletions src/events/pr-handlers/closed.ts
Expand Up @@ -2,6 +2,7 @@ import type { Probot } from 'probot';
import type { AccountInfo } from 'context/getOrCreateAccount';
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 { parseOptions } from './actions/utils/body/parseBody';
Expand All @@ -22,6 +23,11 @@ export default function closed(app: Probot, appContext: AppContext): void {
/* update status, update automerge queue, delete branch */
const repo = context.payload.repository;

const stepsState = calcStepsState({
repoContext,
pullRequest,
});

if ((pullRequest as any).merged) {
const isNotFork = pullRequest.head.repo.id === repo.id;
const options = parseOptions(
Expand All @@ -42,12 +48,13 @@ export default function closed(app: Probot, appContext: AppContext): void {
)
.catch(() => {})
: undefined,
updateCommentBodyProgressFromStepsState(
stepsState,
context,
reviewflowPrContext,
),
]);
} else {
const stepsState = calcStepsState({
repoContext,
pullRequest,
});
await Promise.all([
repoContext.removePrFromAutomergeQueue(
context,
Expand All @@ -67,6 +74,11 @@ export default function closed(app: Probot, appContext: AppContext): void {
appContext,
reviewflowPrContext,
),
updateCommentBodyProgressFromStepsState(
stepsState,
context,
reviewflowPrContext,
),
]);
}
}
Expand Down

0 comments on commit acdf3d7

Please sign in to comment.