TypeScript
fix(mobile): Bitbucket and GitCafe approvals show as approved on the PR timeline (#23138)
MarcoDotIO6d18edd9635d
diff --git a/apps/mobile/src/features/pull-requests/PullRequestTimeline.tsx b/apps/mobile/src/features/pull-requests/PullRequestTimeline.tsxindex 424f8cdff1b..8f4b1e45a86 100644--- a/apps/mobile/src/features/pull-requests/PullRequestTimeline.tsx+++ b/apps/mobile/src/features/pull-requests/PullRequestTimeline.tsx@@ -14,6 +14,7 @@ import { PullRequestAvatar } from "./PullRequestPresentation";import { PullRequestMarkdown } from "./PullRequestMarkdown";import { PullRequestCommentFooter } from "./PullRequestReactions";import { pullRequestDescriptionContent } from "./pullRequestDescriptionContent";+import { normalizedReviewState } from "./pullRequestStatus";import type { PullRequestParams } from "./usePullRequestDiff";function TimelineEvent(props: {@@ -80,8 +81,9 @@ function TimelineComment({[comment.body],);const preview = content.preview;- const approved = comment.reviewState === "APPROVED";- const changes = comment.reviewState === "CHANGES_REQUESTED";+ const state = normalizedReviewState(comment.reviewState);+ const approved = state === "APPROVED";+ const changes = state === "CHANGES_REQUESTED";return (<TimelineEventicon={approved ? "checkmark" : changes ? "doc.text" : "text.bubble"}diff --git a/apps/mobile/src/features/pull-requests/pullRequestStatus.test.ts b/apps/mobile/src/features/pull-requests/pullRequestStatus.test.tsindex 749686fd459..aef40179ded 100644--- a/apps/mobile/src/features/pull-requests/pullRequestStatus.test.ts+++ b/apps/mobile/src/features/pull-requests/pullRequestStatus.test.ts@@ -1,6 +1,10 @@import type { PullRequestActivity, PullRequestCheck, PullRequestComment } from "@t3tools/contracts";import { describe, expect, it } from "vite-plus/test";-import { pullRequestChecksSummary, pullRequestReviewSummary } from "./pullRequestStatus";+import {+ normalizedReviewState,+ pullRequestChecksSummary,+ pullRequestReviewSummary,+} from "./pullRequestStatus";const author = { login: "julius", name: null, avatarUrl: null };function review(state: string, at: string): PullRequestComment {@@ -76,6 +80,18 @@ describe("mobile overview review status", () => {});});+describe("mobile review state spelling", () => {+ it("reads GitHub's uppercase and Bitbucket's or GitCafe's lowercase verdicts alike", () => {+ expect(normalizedReviewState("APPROVED")).toBe("APPROVED");+ expect(normalizedReviewState("approved")).toBe("APPROVED");+ expect(normalizedReviewState("CHANGES_REQUESTED")).toBe("CHANGES_REQUESTED");+ expect(normalizedReviewState("changes_requested")).toBe("CHANGES_REQUESTED");+ expect(normalizedReviewState("changes-requested")).toBe("CHANGES_REQUESTED");+ expect(normalizedReviewState("commented")).toBe("COMMENTED");+ expect(normalizedReviewState(null)).toBeUndefined();+ });+});+describe("mobile overview check status", () => {it("prioritizes failed checks while others are running", () => {expect(diff --git a/apps/mobile/src/features/pull-requests/pullRequestStatus.ts b/apps/mobile/src/features/pull-requests/pullRequestStatus.tsindex fa802a43095..5426266dc68 100644--- a/apps/mobile/src/features/pull-requests/pullRequestStatus.ts+++ b/apps/mobile/src/features/pull-requests/pullRequestStatus.ts@@ -135,6 +135,11 @@ export function pullRequestChecksSummary(pr: Pick<PullRequestDetail, "checks">)} as const;}+// GitHub and Forgejo send uppercase review states; Bitbucket and GitCafe send lowercase.+export function normalizedReviewState(reviewState: string | null) {+ return reviewState?.toUpperCase().replaceAll("-", "_");+}+export function pullRequestReviewSummary(pr: Pick<PullRequestDetail, "reviewers">,activity: Pick<PullRequestActivity, "comments" | "commits"> | null,@@ -142,8 +147,8 @@ export function pullRequestReviewSummary(const latest = new Map<string, PullRequestActivity["comments"][number]>();const comments = new Map<string, PullRequestActivity["comments"][number]>();for (const review of activity?.comments ?? []) {- if (review.kind !== "review" || !review.reviewState) continue;- const state = review.reviewState.toUpperCase().replaceAll("-", "_");+ const state = normalizedReviewState(review.reviewState);+ if (review.kind !== "review" || !state) continue;const key = review.author?.login ?? review.id;if (state === "COMMENTED") {const previous = comments.get(key);