Skip to content

Commit

Permalink
fix: fix merged pr still marked as prs to merge
Browse files Browse the repository at this point in the history
  • Loading branch information
christophehurpeau committed Mar 9, 2023
1 parent 7f4b235 commit 087a0e7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/events/pr-handlers/actions/editOpenedPR.ts
Expand Up @@ -255,6 +255,7 @@ export const editOpenedPR = async <
headSha: pullRequest.head.sha,
title,
isDraft: pullRequest.draft === true,
isClosed: !!pullRequest.closed_at,
checksConclusion: checksAndStatuses.checksConclusionRecord,
statusesConclusion: checksAndStatuses.statusesConclusionRecord,
...(reviews ? { reviews } : {}),
Expand Down
11 changes: 11 additions & 0 deletions src/events/pr-handlers/closed.ts
Expand Up @@ -29,6 +29,15 @@ export default function closed(app: Probot, appContext: AppContext): void {
reviewflowPrContext,
});

const updateClosedPromise = appContext.mongoStores.prs.partialUpdateOne(
reviewflowPrContext.reviewflowPr,
{
$set: {
isClosed: true,
},
},
);

if ((pullRequest as any).merged) {
const isNotFork = pullRequest.head.repo.id === repo.id;
const options = parseOptions(
Expand All @@ -37,6 +46,7 @@ export default function closed(app: Probot, appContext: AppContext): void {
);

await Promise.all([
updateClosedPromise,
repoContext.removePrFromAutomergeQueue(
context,
pullRequest,
Expand All @@ -57,6 +67,7 @@ export default function closed(app: Probot, appContext: AppContext): void {
]);
} else {
await Promise.all([
updateClosedPromise,
repoContext.removePrFromAutomergeQueue(
context,
pullRequest,
Expand Down
2 changes: 2 additions & 0 deletions src/events/pr-handlers/utils/createPullRequestContext.ts
Expand Up @@ -46,6 +46,7 @@ export const getReviewflowPrContext = async <T extends EventsWithRepository>(
pr: prEmbed,
commentId: comment.id,
title: 'title' in pullRequest ? pullRequest.title : 'Unknown Title',
isClosed: 'closed_at' in pullRequest ? !!pullRequest.closed_at : false,
isDraft: 'draft' in pullRequest && pullRequest.draft === true,
reviews: createEmptyReviews(),
assignees:
Expand Down Expand Up @@ -87,6 +88,7 @@ export const getReviewflowPrContext = async <T extends EventsWithRepository>(
repo: repoContext.repoEmbed,
pr: prEmbed,
title: 'title' in pullRequest ? pullRequest.title : 'Unknown Title',
isClosed: 'closed_at' in pullRequest ? !!pullRequest.closed_at : false,
isDraft: 'draft' in pullRequest && pullRequest.draft === true,
commentId,
reviews: groupReviewsWithState(reviewersWithState!),
Expand Down
1 change: 1 addition & 0 deletions src/mongo.ts
Expand Up @@ -164,6 +164,7 @@ export interface ReviewflowPr extends MongoBaseModel {
headSha?: string;
title: string;
isDraft: boolean;
isClosed: boolean;
lastLintStatusesCommit?: string;
lintStatuses?: ReviewflowStatus[];
lastFlowStatusCommit?: string;
Expand Down
1 change: 1 addition & 0 deletions src/slack/home.ts
Expand Up @@ -37,6 +37,7 @@ export const createSlackHomeWorker = (mongoStores: MongoStores) => {
{
'account.id': member.org.id,
'assignees.id': member.user.id,
isClosed: false,
'reviews.reviewRequested': { $exists: true, $eq: [] },
'reviews.changesRequested': { $exists: true, $eq: [] },
'reviews.approved': { $exists: true, $ne: [] },
Expand Down

0 comments on commit 087a0e7

Please sign in to comment.