Skip to content
TypeScript

fix(mobile): single-comment PR discussions say "1 comment", not "1 comments" (#22926)

MarcoDotIO5e191059bb24
diff --git a/apps/mobile/src/features/pull-requests/PullRequestTimeline.tsx b/apps/mobile/src/features/pull-requests/PullRequestTimeline.tsx
index 8f4b1e45a86..e9f288ea9c6 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 { discussionCommentCountLabel } from "./pullRequestDiffComments";
import { normalizedReviewState } from "./pullRequestStatus";
import type { PullRequestParams } from "./usePullRequestDiff";
@@ -250,7 +251,7 @@ export function pullRequestTimelineRows(
<Text className="text-xs text-foreground-muted">
{thread.isResolved ? "Resolved" : "Unresolved"}
{thread.isOutdated ? " · Outdated" : ""} ·{" "}
- {thread.commentCount ?? thread.comments.length} comments
+ {discussionCommentCountLabel(thread.commentCount ?? thread.comments.length)}
</Text>
</Pressable>
</TimelineEvent>
diff --git a/apps/mobile/src/features/pull-requests/pullRequestDiffComments.test.ts b/apps/mobile/src/features/pull-requests/pullRequestDiffComments.test.ts
index 2573436f3ac..d468e352c04 100644
--- a/apps/mobile/src/features/pull-requests/pullRequestDiffComments.test.ts
+++ b/apps/mobile/src/features/pull-requests/pullRequestDiffComments.test.ts
@@ -96,6 +96,22 @@ describe("PR comments in continuous native diffs", () => {
]);
expect(annotated.commentTargetsByRowId).toBe(data.commentTargetsByRowId);
});
+ it("counts a single-comment discussion in the singular", () => {
+ const annotated = annotatePullRequestDiff(
+ data,
+ [
+ { ...thread, commentCount: 1 },
+ { ...thread, id: "right", side: "right", commentCount: 2 },
+ ],
+ [],
+ "abc",
+ );
+ expect(
+ annotated.rows
+ .filter((row) => row.kind === "comment")
+ .map((row) => row.commentText?.split("\n").at(-1)),
+ ).toEqual(["1 comment · Tap to open", "2 comments · Tap to open"]);
+ });
it("uses the old line number for left-side context when the line numbers differ", () => {
const position = { kind: "context" as const, side: "left" as const, oldLine: 7, newLine: 8 };
const annotated = annotatePullRequestDiff(
diff --git a/apps/mobile/src/features/pull-requests/pullRequestDiffComments.ts b/apps/mobile/src/features/pull-requests/pullRequestDiffComments.ts
index 097ede3867e..6da3f8e0272 100644
--- a/apps/mobile/src/features/pull-requests/pullRequestDiffComments.ts
+++ b/apps/mobile/src/features/pull-requests/pullRequestDiffComments.ts
@@ -18,6 +18,9 @@ export function reviewPosition(row: NativeReviewDiffRow): PullRequestReviewPosit
};
return null;
}
+export function discussionCommentCountLabel(count: number) {
+ return `${count} ${count === 1 ? "comment" : "comments"}`;
+}
export function reviewPositionLabel(position: PullRequestReviewPosition) {
const oldSide =
position.kind === "deleted" || (position.kind === "context" && position.side === "left");
@@ -79,7 +82,7 @@ export function annotatePullRequestDiff(
attach(
anchor,
`discussion:${thread.id}`,
- `${first?.author?.login ?? "Discussion"}${thread.isResolved ? " · Resolved" : ""}\n${first?.body ?? ""}\n${thread.commentCount ?? thread.comments.length} comments · Tap to open`,
+ `${first?.author?.login ?? "Discussion"}${thread.isResolved ? " · Resolved" : ""}\n${first?.body ?? ""}\n${discussionCommentCountLabel(thread.commentCount ?? thread.comments.length)} · Tap to open`,
thread.line === null ? "file" : String(thread.line),
);
}