Skip to content

Commit 6d18edd

Browse files
MarcoDotIOclaudemaria-rcks
authored
fix(mobile): Bitbucket and GitCafe approvals show as approved on the PR timeline (#23138)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent 651e390 commit 6d18edd

3 files changed

Lines changed: 28 additions & 5 deletions

File tree

‎apps/mobile/src/features/pull-requests/PullRequestTimeline.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { PullRequestAvatar } from "./PullRequestPresentation";
1414
import { PullRequestMarkdown } from "./PullRequestMarkdown";
1515
import { PullRequestCommentFooter } from "./PullRequestReactions";
1616
import { pullRequestDescriptionContent } from "./pullRequestDescriptionContent";
17+
import { normalizedReviewState } from "./pullRequestStatus";
1718
import type { PullRequestParams } from "./usePullRequestDiff";
1819

1920
function TimelineEvent(props: {
@@ -80,8 +81,9 @@ function TimelineComment({
8081
[comment.body],
8182
);
8283
const preview = content.preview;
83-
const approved = comment.reviewState === "APPROVED";
84-
const changes = comment.reviewState === "CHANGES_REQUESTED";
84+
const state = normalizedReviewState(comment.reviewState);
85+
const approved = state === "APPROVED";
86+
const changes = state === "CHANGES_REQUESTED";
8587
return (
8688
<TimelineEvent
8789
icon={approved ? "checkmark" : changes ? "doc.text" : "text.bubble"}

‎apps/mobile/src/features/pull-requests/pullRequestStatus.test.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import type { PullRequestActivity, PullRequestCheck, PullRequestComment } from "@t3tools/contracts";
22
import { describe, expect, it } from "vite-plus/test";
3-
import { pullRequestChecksSummary, pullRequestReviewSummary } from "./pullRequestStatus";
3+
import {
4+
normalizedReviewState,
5+
pullRequestChecksSummary,
6+
pullRequestReviewSummary,
7+
} from "./pullRequestStatus";
48

59
const author = { login: "julius", name: null, avatarUrl: null };
610
function review(state: string, at: string): PullRequestComment {
@@ -76,6 +80,18 @@ describe("mobile overview review status", () => {
7680
});
7781
});
7882

83+
describe("mobile review state spelling", () => {
84+
it("reads GitHub's uppercase and Bitbucket's or GitCafe's lowercase verdicts alike", () => {
85+
expect(normalizedReviewState("APPROVED")).toBe("APPROVED");
86+
expect(normalizedReviewState("approved")).toBe("APPROVED");
87+
expect(normalizedReviewState("CHANGES_REQUESTED")).toBe("CHANGES_REQUESTED");
88+
expect(normalizedReviewState("changes_requested")).toBe("CHANGES_REQUESTED");
89+
expect(normalizedReviewState("changes-requested")).toBe("CHANGES_REQUESTED");
90+
expect(normalizedReviewState("commented")).toBe("COMMENTED");
91+
expect(normalizedReviewState(null)).toBeUndefined();
92+
});
93+
});
94+
7995
describe("mobile overview check status", () => {
8096
it("prioritizes failed checks while others are running", () => {
8197
expect(

‎apps/mobile/src/features/pull-requests/pullRequestStatus.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,20 @@ export function pullRequestChecksSummary(pr: Pick<PullRequestDetail, "checks">)
135135
} as const;
136136
}
137137

138+
// GitHub and Forgejo send uppercase review states; Bitbucket and GitCafe send lowercase.
139+
export function normalizedReviewState(reviewState: string | null) {
140+
return reviewState?.toUpperCase().replaceAll("-", "_");
141+
}
142+
138143
export function pullRequestReviewSummary(
139144
pr: Pick<PullRequestDetail, "reviewers">,
140145
activity: Pick<PullRequestActivity, "comments" | "commits"> | null,
141146
) {
142147
const latest = new Map<string, PullRequestActivity["comments"][number]>();
143148
const comments = new Map<string, PullRequestActivity["comments"][number]>();
144149
for (const review of activity?.comments ?? []) {
145-
if (review.kind !== "review" || !review.reviewState) continue;
146-
const state = review.reviewState.toUpperCase().replaceAll("-", "_");
150+
const state = normalizedReviewState(review.reviewState);
151+
if (review.kind !== "review" || !state) continue;
147152
const key = review.author?.login ?? review.id;
148153
if (state === "COMMENTED") {
149154
const previous = comments.get(key);

0 commit comments

Comments
 (0)