Skip to content

Commit caab2fd

Browse files
authored
fix(web): render draft PRs in gray (pingdotgg#9537)
1 parent 5cc369b commit caab2fd

30 files changed

Lines changed: 152 additions & 36 deletions

‎apps/mobile/src/features/threads/thread-list-items.tsx‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { relativeTime } from "../../lib/time";
2323
import { themeColorWithAlpha } from "../../lib/mobileTheme";
2424
import { useUniwindTheme } from "../../lib/useUniwindTheme";
2525
import type { PendingNewTask } from "../../state/use-pending-new-tasks";
26-
import { useThreadPr, type ThreadPr } from "../../state/use-thread-pr";
26+
import { useThreadPr, type ThreadPrPresentation } from "../../state/use-thread-pr";
2727
import type { HomeGroupDisplayAction } from "../home/homeListItems";
2828
import { ThreadSwipeable } from "../home/thread-swipe-actions";
2929
import { buildThreadTitleRegenerationMenuItems } from "./thread-title-regeneration-menu";
@@ -42,9 +42,15 @@ export type ThreadListVariant = "compact" | "sidebar";
4242
export const THREAD_LIST_COMPACT_INSET = HOME_HORIZONTAL_INSET;
4343
const SIDEBAR_ROW_RADIUS = 12;
4444

45-
function pullRequestTintColor(state: ThreadPr["state"], colorScheme: "light" | "dark") {
45+
function pullRequestTintColor(
46+
pr: Pick<ThreadPrPresentation, "state" | "isDraft">,
47+
colorScheme: "light" | "dark",
48+
) {
4649
const dark = colorScheme === "dark";
47-
switch (state) {
50+
if (pr.state === "open" && pr.isDraft === true) {
51+
return dark ? "#a1a1aa" : "#71717a";
52+
}
53+
switch (pr.state) {
4854
case "open":
4955
return dark ? "#34d399" : "#059669";
5056
case "merged":
@@ -548,9 +554,7 @@ export const ThreadListRow = memo(function ThreadListRow(props: {
548554
<PullRequestIcon
549555
size={compact ? 13 : 11}
550556
color={
551-
selected
552-
? String(selectedForegroundColor)
553-
: pullRequestTintColor(pr.state, colorScheme)
557+
selected ? String(selectedForegroundColor) : pullRequestTintColor(pr, colorScheme)
554558
}
555559
/>
556560
<Text

‎apps/mobile/src/state/thread-pr-presentation.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export type ThreadPr = NonNullable<VcsStatusResult["pr"]>;
66
export interface ThreadPrPresentation {
77
readonly number: number;
88
readonly state: ThreadPr["state"];
9+
readonly isDraft: boolean;
910
/** Provider-side last activity, bounding when a terminal state landed. */
1011
readonly updatedAt: string | null;
1112
readonly url: string;
@@ -27,13 +28,15 @@ export function presentThreadPr(
2728
provider: VcsStatusResult["sourceControlProvider"] | null | undefined,
2829
): ThreadPrPresentation {
2930
const presentation = resolveChangeRequestPresentation(provider);
31+
const isDraft = pr.state === "open" && pr.isDraft === true;
3032
return {
3133
number: pr.number,
3234
state: pr.state,
35+
isDraft,
3336
updatedAt: pr.updatedAt ?? null,
3437
url: pr.url,
3538
label: String(pr.number),
36-
accessibilityLabel: `#${pr.number} ${presentation.longName} ${pr.state}`,
37-
textClassName: PR_STATE_TEXT_CLASS[pr.state],
39+
accessibilityLabel: `#${pr.number} ${presentation.longName} ${isDraft ? "draft" : pr.state}`,
40+
textClassName: isDraft ? "text-adaptive-zinc-500-400" : PR_STATE_TEXT_CLASS[pr.state],
3841
};
3942
}

‎apps/mobile/src/state/use-thread-pr.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,13 @@ describe("presentThreadPr", () => {
3333
accessibilityLabel: "#3774 merge request merged",
3434
});
3535
});
36+
37+
it("uses gray for draft pull requests", () => {
38+
expect(
39+
presentThreadPr({ ...pullRequest, state: "open", isDraft: true }, undefined),
40+
).toMatchObject({
41+
accessibilityLabel: "#3774 pull request draft",
42+
textClassName: "text-adaptive-zinc-500-400",
43+
});
44+
});
3645
});

‎apps/server/src/git/GitManager.test.ts‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ interface FakeGhScenario {
5454
baseRefName: string;
5555
headRefName: string;
5656
state?: "open" | "closed" | "merged";
57+
isDraft?: boolean;
5758
isCrossRepository?: boolean;
5859
headRepositoryNameWithOwner?: string | null;
5960
headRepositoryOwnerLogin?: string | null;
@@ -116,6 +117,7 @@ function normalizeFakePullRequestSummary(raw: unknown): GitHubCli.GitHubPullRequ
116117
? "closed"
117118
: "merged"
118119
: undefined;
120+
const isDraft = typeof record.isDraft === "boolean" ? record.isDraft : undefined;
119121
const isCrossRepository =
120122
typeof record.isCrossRepository === "boolean" ? record.isCrossRepository : undefined;
121123
const headRepositoryNameWithOwner =
@@ -138,6 +140,7 @@ function normalizeFakePullRequestSummary(raw: unknown): GitHubCli.GitHubPullRequ
138140
baseRefName,
139141
headRefName,
140142
...(state ? { state } : {}),
143+
...(isDraft === true ? { isDraft: true } : {}),
141144
...(isCrossRepository !== undefined ? { isCrossRepository } : {}),
142145
...(headRepositoryNameWithOwner ? { headRepositoryNameWithOwner } : {}),
143146
...(headRepositoryOwnerLogin ? { headRepositoryOwnerLogin } : {}),
@@ -508,7 +511,7 @@ function createGitHubCliWithFakeGh(scenario: FakeGhScenario = {}): {
508511
"--limit",
509512
String(input.limit ?? 1),
510513
"--json",
511-
"number,title,url,baseRefName,headRefName,state,mergedAt,isCrossRepository,headRepository,headRepositoryOwner",
514+
"number,title,url,baseRefName,headRefName,state,isDraft,mergedAt,isCrossRepository,headRepository,headRepositoryOwner",
512515
],
513516
}).pipe(
514517
Effect.map((result) => JSON.parse(result.stdout) as unknown[]),
@@ -552,7 +555,7 @@ function createGitHubCliWithFakeGh(scenario: FakeGhScenario = {}): {
552555
"view",
553556
input.reference,
554557
"--json",
555-
"number,title,url,baseRefName,headRefName,state,mergedAt,isCrossRepository,headRepository,headRepositoryOwner",
558+
"number,title,url,baseRefName,headRefName,state,isDraft,mergedAt,isCrossRepository,headRepository,headRepositoryOwner",
556559
],
557560
}).pipe(
558561
Effect.map((result) => JSON.parse(result.stdout) as GitHubCli.GitHubPullRequestSummary),
@@ -699,7 +702,7 @@ const GitManagerTestLayer = GitVcsDriver.layer.pipe(
699702
);
700703

701704
it.layer(GitManagerTestLayer)("GitManager", (it) => {
702-
it.effect("status includes PR metadata when branch already has an open PR", () =>
705+
it.effect("status includes draft PR metadata when branch already has a draft PR", () =>
703706
Effect.gen(function* () {
704707
const repoDir = yield* makeTempDir("t3code-git-manager-");
705708
yield* initRepo(repoDir);
@@ -719,6 +722,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
719722
url: "https://github.com/pingdotgg/codething-mvp/pull/13",
720723
baseRefName: "main",
721724
headRefName: "feature/status-open-pr",
725+
isDraft: true,
722726
},
723727
]),
724728
],
@@ -737,6 +741,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
737741
baseRef: "main",
738742
headRef: "feature/status-open-pr",
739743
state: "open",
744+
isDraft: true,
740745
updatedAt: null,
741746
});
742747
}),
@@ -1686,7 +1691,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
16861691
updatedAt: "2026-03-10T07:00:00.000Z",
16871692
});
16881693
expect(ghCalls).toContain(
1689-
"pr list --head jasonLaster:statemachine --state all --limit 20 --json number,title,url,baseRefName,headRefName,state,mergedAt,updatedAt,isCrossRepository,headRepository,headRepositoryOwner",
1694+
"pr list --head jasonLaster:statemachine --state all --limit 20 --json number,title,url,baseRefName,headRefName,state,isDraft,mergedAt,updatedAt,isCrossRepository,headRepository,headRepositoryOwner",
16901695
);
16911696
}),
16921697
20_000,
@@ -1752,7 +1757,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
17521757
updatedAt: "2026-03-10T07:00:00.000Z",
17531758
});
17541759
expect(ghCalls).toContain(
1755-
"pr list --head contributor:main --state all --limit 20 --json number,title,url,baseRefName,headRefName,state,mergedAt,updatedAt,isCrossRepository,headRepository,headRepositoryOwner",
1760+
"pr list --head contributor:main --state all --limit 20 --json number,title,url,baseRefName,headRefName,state,isDraft,mergedAt,updatedAt,isCrossRepository,headRepository,headRepositoryOwner",
17561761
);
17571762
}),
17581763
20_000,

‎apps/server/src/git/GitManager.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ interface OpenPrInfo {
170170

171171
interface PullRequestInfo extends OpenPrInfo, PullRequestHeadRemoteInfo {
172172
state: "open" | "closed" | "merged";
173+
isDraft?: boolean;
173174
updatedAt: Option.Option<DateTime.Utc>;
174175
}
175176

@@ -404,6 +405,7 @@ function toPullRequestInfo(summary: ChangeRequest): PullRequestInfo {
404405
baseRefName: summary.baseRefName,
405406
headRefName: summary.headRefName,
406407
state: summary.state ?? "open",
408+
...(summary.isDraft === true ? { isDraft: true } : {}),
407409
updatedAt: summary.updatedAt,
408410
...(summary.isCrossRepository !== undefined
409411
? { isCrossRepository: summary.isCrossRepository }
@@ -558,6 +560,7 @@ function toStatusPr(pr: PullRequestInfo): {
558560
baseRef: string;
559561
headRef: string;
560562
state: "open" | "closed" | "merged";
563+
isDraft?: boolean;
561564
updatedAt: string | null;
562565
} {
563566
return {
@@ -567,6 +570,7 @@ function toStatusPr(pr: PullRequestInfo): {
567570
baseRef: pr.baseRefName,
568571
headRef: pr.headRefName,
569572
state: pr.state,
573+
...(pr.isDraft === true ? { isDraft: true } : {}),
570574
updatedAt: Option.match(pr.updatedAt, {
571575
onNone: () => null,
572576
onSome: (updatedAt) => DateTime.formatIso(updatedAt),
@@ -1518,11 +1522,7 @@ export const make = Effect.gen(function* () {
15181522
);
15191523
if (firstPullRequest) {
15201524
return {
1521-
number: firstPullRequest.number,
1522-
title: firstPullRequest.title,
1523-
url: firstPullRequest.url,
1524-
baseRefName: firstPullRequest.baseRefName,
1525-
headRefName: firstPullRequest.headRefName,
1525+
...firstPullRequest,
15261526
state: "open",
15271527
updatedAt: Option.none(),
15281528
} satisfies PullRequestInfo;

‎apps/server/src/pullRequest/GitHubPullRequestCli.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ export class GitHubPullRequestCli extends Context.Service<
468468
readonly headBranch: string;
469469
readonly baseBranch: string;
470470
readonly state: "open" | "closed" | "merged";
471+
readonly isDraft?: boolean;
471472
readonly updatedAt: string;
472473
},
473474
GitHubPullRequestCliError
@@ -1650,6 +1651,7 @@ export const make = Effect.gen(function* () {
16501651
headBranch: summary.headRefName,
16511652
baseBranch: summary.baseRefName,
16521653
state: summary.state ?? "open",
1654+
...(summary.isDraft === true ? { isDraft: true } : {}),
16531655
updatedAt: summary.updatedAt,
16541656
}),
16551657
),

‎apps/server/src/pullRequest/PullRequestProvider.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ export interface ProviderChangeRequestSummary {
9696
readonly headBranch: string;
9797
readonly baseBranch: string;
9898
readonly state: PullRequestState;
99+
/** Present when the host says an open pull request is still a draft. */
100+
readonly isDraft?: boolean;
99101
readonly updatedAt: string;
100102
}
101103

‎apps/server/src/pullRequest/PullRequestService.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,6 +1254,7 @@ export const make = Effect.gen(function* () {
12541254
title: changeRequest.title,
12551255
url: changeRequest.url,
12561256
state: changeRequest.state,
1257+
...(changeRequest.isDraft === true ? { isDraft: true } : {}),
12571258
headBranch: changeRequest.headBranch,
12581259
baseBranch: changeRequest.baseBranch,
12591260
updatedAt: changeRequest.updatedAt,
@@ -2278,6 +2279,7 @@ export const make = Effect.gen(function* () {
22782279
title: detail.title,
22792280
url: detail.url,
22802281
state: detail.state,
2282+
...(detail.isDraft === true ? { isDraft: true } : {}),
22812283
headBranch: detail.headBranch,
22822284
baseBranch: detail.baseBranch,
22832285
updatedAt: detail.updatedAt,

‎apps/server/src/sourceControl/AzureDevOpsSourceControlProvider.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ function toChangeRequest(summary: {
6161
readonly baseRefName: string;
6262
readonly headRefName: string;
6363
readonly state: "open" | "closed" | "merged";
64+
readonly isDraft?: boolean;
6465
readonly updatedAt: ChangeRequest["updatedAt"];
6566
}): ChangeRequest {
6667
return {
@@ -71,6 +72,7 @@ function toChangeRequest(summary: {
7172
baseRefName: summary.baseRefName,
7273
headRefName: summary.headRefName,
7374
state: summary.state,
75+
...(summary.isDraft === true ? { isDraft: true } : {}),
7476
updatedAt: summary.updatedAt,
7577
isCrossRepository: false,
7678
};

‎apps/server/src/sourceControl/BitbucketSourceControlProvider.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ function toChangeRequest(summary: NormalizedBitbucketPullRequestRecord): ChangeR
1717
baseRefName: summary.baseRefName,
1818
headRefName: summary.headRefName,
1919
state: summary.state,
20+
...(summary.isDraft === true ? { isDraft: true } : {}),
2021
updatedAt: summary.updatedAt ?? Option.none(),
2122
...(summary.isCrossRepository !== undefined
2223
? { isCrossRepository: summary.isCrossRepository }

0 commit comments

Comments
 (0)