Skip to content

Commit e0afb81

Browse files
committed
feat(mobile): open pull requests with conflicts show a warning like web
1 parent 861b362 commit e0afb81

12 files changed

Lines changed: 106 additions & 10 deletions

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,22 @@ import {
1111
THREAD_LIST_V2_SIDEBAR_ROW_STYLE,
1212
THREAD_LIST_V2_SIDEBAR_ROW_CONTAINER_STYLE,
1313
} from "../threads/thread-list-v2-row-appearance";
14-
import { PullRequestAvatar, PullRequestDiffStats } from "./PullRequestPresentation";
14+
import {
15+
PullRequestAvatar,
16+
PullRequestConflictBadge,
17+
PullRequestDiffStats,
18+
} from "./PullRequestPresentation";
1519
import {
1620
pullRequestLabelColor,
1721
pullRequestListReviewStatus,
1822
pullRequestListRowsAreEqual,
1923
type EnvironmentPullRequestListEntry,
2024
} from "./pullRequestList";
21-
import { pullRequestChecksStatus, pullRequestStatus } from "./pullRequestStatus";
25+
import {
26+
pullRequestChecksStatus,
27+
pullRequestConflict,
28+
pullRequestStatus,
29+
} from "./pullRequestStatus";
2230
import { PullRequestGlyph } from "./pullRequestGlyphs";
2331

2432
export const PullRequestListRow = memo(
@@ -48,6 +56,7 @@ export const PullRequestListRow = memo(
4856
? "text-drawer-foreground-muted"
4957
: "text-foreground-tertiary";
5058
const status = pullRequestStatus(item);
59+
const conflict = pullRequestConflict(item);
5160
const review = pullRequestListReviewStatus(item);
5261
const checks = item.checksState ? pullRequestChecksStatus(item.checksState) : null;
5362
return (
@@ -61,7 +70,7 @@ export const PullRequestListRow = memo(
6170
<Pressable
6271
accessibilityRole="button"
6372
accessibilityState={{ selected: props.selected, busy: props.busy }}
64-
accessibilityLabel={`Pull request ${item.number}, ${item.title}, ${status.label}, by ${item.author?.login ?? "unknown author"}${review ? `, ${review.accessibleLabel}` : ""}${item.checksState ? `, checks ${item.checksState}` : ""}${item.stack ? `, stack ${item.stack.position} of ${item.stack.size}` : ""}${item.labels.length ? `, ${item.labels.map((label) => label.name).join(", ")}` : ""}, ${item.additions} additions, ${item.deletions} deletions`}
73+
accessibilityLabel={`Pull request ${item.number}, ${item.title}, ${status.label}${conflict ? `, ${conflict.label.toLowerCase()}` : ""}, by ${item.author?.login ?? "unknown author"}${review ? `, ${review.accessibleLabel}` : ""}${item.checksState ? `, checks ${item.checksState}` : ""}${item.stack ? `, stack ${item.stack.position} of ${item.stack.size}` : ""}${item.labels.length ? `, ${item.labels.map((label) => label.name).join(", ")}` : ""}, ${item.additions} additions, ${item.deletions} deletions`}
6574
accessibilityHint="Double tap to open. Touch and hold for quick actions."
6675
onPress={() => props.onSelect(item)}
6776
disabled={props.busy}
@@ -75,8 +84,19 @@ export const PullRequestListRow = memo(
7584
props.busy && "opacity-50",
7685
)}
7786
>
78-
<View className={props.sidebar ? "pt-0.5" : "pt-2.5"}>
87+
<View className={cn("self-start", props.sidebar ? "pt-0.5" : "pt-2.5")}>
7988
<SymbolView name={status.icon} size={20} tintColorClassName={status.tint} />
89+
{conflict ? (
90+
<PullRequestConflictBadge
91+
surfaceClassName={
92+
props.selected
93+
? "text-thread-selected"
94+
: props.sidebar
95+
? "text-drawer"
96+
: "text-screen"
97+
}
98+
/>
99+
) : null}
80100
</View>
81101
<View
82102
className={cn(

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { PullRequestStackCard } from "./PullRequestStackCard";
77
import type { PullRequestParams } from "./usePullRequestDiff";
88
import type { PullRequestStackState } from "./usePullRequestStack";
99
import { pullRequestListReviewStatus } from "./pullRequestList";
10+
import { PullRequestGlyph } from "./pullRequestGlyphs";
1011

1112
export function PullRequestOverviewLoading({
1213
summary,
@@ -74,7 +75,7 @@ export function PullRequestOverviewLoading({
7475
: "Branch"
7576
}
7677
icon={
77-
conflicting ? "exclamationmark.triangle" : clean ? "checkmark.circle" : "arrow.branch"
78+
conflicting ? PullRequestGlyph.conflicting : clean ? "checkmark.circle" : "arrow.branch"
7879
}
7980
tint={
8081
conflicting

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator";
22
import type { PullRequestActor } from "@t3tools/contracts";
3+
import IconAlertTriangle from "@tabler/icons-react-native/IconAlertTriangle";
34
import { Image } from "expo-image";
45
import { View } from "react-native";
6+
import { useResolveClassNames } from "uniwind";
57

68
import { AppText as Text } from "../../components/ui/AppText";
79
import { cn } from "../../lib/cn";
@@ -18,6 +20,16 @@ export function PullRequestReadStatus(props: {
1820
) : null;
1921
}
2022

23+
export function PullRequestConflictBadge(props: { readonly surfaceClassName: string }) {
24+
const { color } = useResolveClassNames("text-danger-foreground");
25+
const { color: surface } = useResolveClassNames(props.surfaceClassName);
26+
return (
27+
<View pointerEvents="none" className="absolute -right-1 -bottom-1">
28+
<IconAlertTriangle size={15} strokeWidth={2.5} color={color} fill={surface} />
29+
</View>
30+
);
31+
}
32+
2133
export function PullRequestAvatar(props: {
2234
readonly actor: PullRequestActor | null;
2335
readonly size?: number;

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { Menu } from "../../components/ui/Menu";
1212
import { PullRequestAvatar } from "./PullRequestPresentation";
1313
import { PullRequestCardRow } from "./PullRequestControls";
1414
import { PullRequestAgentRow } from "./PullRequestAgentRow";
15+
import { PullRequestGlyph } from "./pullRequestGlyphs";
1516
import { composerPullRequests } from "../../state/pull-requests";
1617
import { useEnvironmentQuery } from "../../state/query";
1718
import { allowedUpdateMethods, PR_ACTION_ICONS, PR_ACTION_LABELS } from "./pullRequestActions";
@@ -189,7 +190,9 @@ export function PullRequestBranchRow(props: RowProps) {
189190
? `No conflicts with ${props.pr.baseBranch}`
190191
: "Branch"
191192
}
192-
icon={conflicting ? "exclamationmark.triangle" : clean ? "checkmark.circle" : "arrow.branch"}
193+
icon={
194+
conflicting ? PullRequestGlyph.conflicting : clean ? "checkmark.circle" : "arrow.branch"
195+
}
193196
tint={
194197
conflicting
195198
? "accent-danger-foreground"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ export const PullRequestGlyph = {
66
closed: "git.pull-request.closed",
77
merged: "arrow.triangle.merge",
88
stack: "square.3.layers.3d",
9+
conflicting: "exclamationmark.triangle",
910
} as const satisfies Record<string, AppSymbolName>;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ describe("recycled PR list rows", () => {
8686
{ viewerReviewRequested: true },
8787
{ isDraft: true },
8888
{ state: "closed" as const },
89+
{ mergeability: "conflicting" as const },
90+
{ baseBranch: "release" },
8991
{ author: { login: "another", name: null, avatarUrl: null } },
9092
{ author: { login: "octocat", name: null, avatarUrl: "https://example.com/avatar.png" } },
9193
{ labels: [{ name: "bug", color: "ff0000" }] },

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ export function pullRequestListRowsAreEqual(
5757
previous.url === next.url &&
5858
previous.state === next.state &&
5959
previous.isDraft === next.isDraft &&
60+
previous.mergeability === next.mergeability &&
61+
previous.baseBranch === next.baseBranch &&
6062
previous.updatedAt === next.updatedAt &&
6163
previous.additions === next.additions &&
6264
previous.deletions === next.deletions &&

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

Lines changed: 32 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+
pullRequestChecksSummary,
5+
pullRequestConflict,
6+
pullRequestReviewSummary,
7+
} from "./pullRequestStatus";
48

59
const author = { login: "julius", name: null, avatarUrl: null };
610
function review(state: string, at: string): PullRequestComment {
@@ -107,3 +111,30 @@ describe("mobile overview check status", () => {
107111
).toMatchObject({ title: "1 check failing", count: "1 of 3" });
108112
});
109113
});
114+
115+
describe("mobile pull request conflict", () => {
116+
it("names the base branch of an open pull request with conflicts", () => {
117+
expect(
118+
pullRequestConflict({
119+
state: "open",
120+
isDraft: false,
121+
mergeability: "conflicting",
122+
baseBranch: "main",
123+
})?.label,
124+
).toBe("Conflicts with main");
125+
expect(
126+
pullRequestConflict({ state: "open", isDraft: false, mergeability: "conflicting" })?.label,
127+
).toBe("Has conflicts");
128+
});
129+
130+
it.each([
131+
{ state: "open" as const, isDraft: true, mergeability: "conflicting" as const },
132+
{ state: "merged" as const, isDraft: false, mergeability: "conflicting" as const },
133+
{ state: "closed" as const, isDraft: false, mergeability: "conflicting" as const },
134+
{ state: "open" as const, isDraft: false, mergeability: "mergeable" as const },
135+
{ state: "open" as const, isDraft: false, mergeability: "unknown" as const },
136+
{ state: "open" as const, isDraft: false },
137+
])("stays quiet when it cannot conflict or has not been reported: %j", (pr) => {
138+
expect(pullRequestConflict(pr)).toBeNull();
139+
});
140+
});

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {
44
PullRequestChecksState,
55
PullRequestDetail,
66
PullRequestListEntry,
7+
PullRequestMergeability,
78
} from "@t3tools/contracts";
89
import type { AppSymbolName } from "../../components/ui/AppSymbol";
910
import { PullRequestGlyph } from "./pullRequestGlyphs";
@@ -46,6 +47,16 @@ export function pullRequestStatus(pr: Pick<PullRequestListEntry, "state" | "isDr
4647
return STATES[pr.isDraft && pr.state === "open" ? "draft" : pr.state];
4748
}
4849

50+
export function pullRequestConflict(pr: {
51+
readonly state: PullRequestListEntry["state"];
52+
readonly isDraft: boolean;
53+
readonly mergeability?: PullRequestMergeability | undefined;
54+
readonly baseBranch?: string | undefined;
55+
}) {
56+
if (pr.state !== "open" || pr.isDraft || pr.mergeability !== "conflicting") return null;
57+
return { label: pr.baseBranch ? `Conflicts with ${pr.baseBranch}` : "Has conflicts" };
58+
}
59+
4960
export function checkStatus(check: PullRequestCheck) {
5061
switch (check.status) {
5162
case "success":

‎apps/mobile/src/features/threads/LinkedPullRequestList.tsx‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,16 @@ import { relativeTime } from "../../lib/time";
1515
import type { EnvironmentRuntimeState } from "../../state/remote-runtime-types";
1616
import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs";
1717
import { pullRequestListReviewStatus } from "../pull-requests/pullRequestList";
18-
import { PullRequestAvatar, PullRequestDiffStats } from "../pull-requests/PullRequestPresentation";
19-
import { pullRequestChecksStatus, pullRequestStatus } from "../pull-requests/pullRequestStatus";
18+
import {
19+
PullRequestAvatar,
20+
PullRequestConflictBadge,
21+
PullRequestDiffStats,
22+
} from "../pull-requests/PullRequestPresentation";
23+
import {
24+
pullRequestChecksStatus,
25+
pullRequestConflict,
26+
pullRequestStatus,
27+
} from "../pull-requests/pullRequestStatus";
2028

2129
export function useLinkedPullRequestLines(
2230
thread: EnvironmentThreadShell | null,
@@ -43,11 +51,13 @@ export function linkedPullRequestKey(line: PullRequestListLine) {
4351
export const LinkedPullRequestRow = memo(function LinkedPullRequestRow(props: {
4452
readonly line: PullRequestListLine;
4553
readonly separator: boolean;
54+
readonly surfaceClassName: string;
4655
readonly openPullRequest: (url: string) => Promise<boolean>;
4756
}) {
4857
const { link, depth, stack } = props.line;
4958
const snapshot = link.snapshot;
5059
const status = snapshot === null ? null : pullRequestStatus(snapshot);
60+
const conflict = snapshot === null ? null : pullRequestConflict(snapshot);
5161
const open = snapshot === null || snapshot.state === "open";
5262
const checks =
5363
open && snapshot?.checksState ? pullRequestChecksStatus(snapshot.checksState) : null;
@@ -64,7 +74,7 @@ export const LinkedPullRequestRow = memo(function LinkedPullRequestRow(props: {
6474
return (
6575
<Pressable
6676
accessibilityRole="button"
67-
accessibilityLabel={`Pull request ${link.number}, ${snapshot?.title ?? "waiting for host state"}${status ? `, ${status.label}` : ""}, ${link.repository}${stack ? `, stack of ${stack.size}` : ""}${watching ? ", watching" : ""}`}
77+
accessibilityLabel={`Pull request ${link.number}, ${snapshot?.title ?? "waiting for host state"}${status ? `, ${status.label}` : ""}${conflict ? `, ${conflict.label.toLowerCase()}` : ""}, ${link.repository}${stack ? `, stack of ${stack.size}` : ""}${watching ? ", watching" : ""}`}
6878
onPress={() => {
6979
void props.openPullRequest(link.url).then((opened) => {
7080
if (!opened) Dialog.alert("Unable to open PR", "The pull request could not be opened.");
@@ -81,6 +91,7 @@ export const LinkedPullRequestRow = memo(function LinkedPullRequestRow(props: {
8191
size={20}
8292
tintColorClassName={status?.tint ?? "accent-icon-muted"}
8393
/>
94+
{conflict ? <PullRequestConflictBadge surfaceClassName={props.surfaceClassName} /> : null}
8495
</View>
8596
<View
8697
className={cn(

0 commit comments

Comments
 (0)