Skip to content

Commit

Permalink
fix(api): wip digest approved prs
Browse files Browse the repository at this point in the history
  • Loading branch information
waltergalvao committed Jan 9, 2025
1 parent 2baedc8 commit cad2394
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
16 changes: 15 additions & 1 deletion apps/api/src/app/code-reviews/services/code-review.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getPrisma } from "../../../prisma";
import { Prisma } from "@prisma/client";
import { CodeReview, CodeReviewState, Prisma } from "@prisma/client";
import { PaginateCodeReviewsArgs } from "./code-review.types";

export const paginateCodeReviews = async (
Expand Down Expand Up @@ -44,3 +44,17 @@ export const paginateCodeReviews = async (

return getPrisma(workspaceId).codeReview.findMany(query);
};

export const isPullRequestApproved = (
codeReviews: Pick<CodeReview, "state">[]
) => {
const approvals = codeReviews.filter(
(review) => review.state === CodeReviewState.APPROVED
).length;

const changesRequested = codeReviews.filter(
(review) => review.state === CodeReviewState.CHANGES_REQUESTED
).length;

return approvals > 0 && changesRequested === 0;
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CodeReviewState, PullRequestState } from "@prisma/client";
import { PullRequestState } from "@prisma/client";
import { getPrisma, take } from "../../../prisma";
import { ResourceNotFoundException } from "../../errors/exceptions/resource-not-found.exception";
import {
Expand All @@ -13,6 +13,7 @@ import { env } from "../../../env";
import { encodeId } from "../../../lib/hash-id";
import { capitalize } from "radash";
import { subMonths } from "date-fns";
import { isPullRequestApproved } from "../../code-reviews/services/code-review.service";

export const sendTeamWipDigest = async (digest: DigestWithRelations) => {
const { slackClient } = await getWorkspaceSlackClient(digest.workspaceId);
Expand Down Expand Up @@ -198,11 +199,7 @@ const getPullRequestsGroupedByState = async (
continue;
}

if (
pullRequest.codeReviews.some(
(review) => review.state === CodeReviewState.APPROVED
)
) {
if (isPullRequestApproved(pullRequest.codeReviews)) {
approved.push(pullRequest);
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/app/digests/workers/digest-send.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createWorker } from "../../../bull-mq/workers";
import { logger } from "../../../lib/logger";
import { DigestWithRelations } from "../services/digest.types";
import { DigestType } from "@prisma/client";
import { sendTeamWipDigest } from "../services/digest-team-wip-digest.service";
import { sendTeamWipDigest } from "../services/digest-team-wip.service";
import { sendTeamMetricsDigest } from "../services/digest-team-metrics.service";
import { InputValidationException } from "../../errors/exceptions/input-validation.exception";

Expand Down

0 comments on commit cad2394

Please sign in to comment.