Show merged PR status in thread sidebar when no open PR exists #53
- @@ -192,4 +192,5 @@192192 const details = await this.gitCore.statusDetails(input.cwd);193193194194 let openPr: ReturnType<typeof toStatusOpenPr> | null = null;195- if (details.branch && details.hasUpstream) {195+ let mergedPr: ReturnType<typeof toStatusOpenPr> | null = null;196+ if (details.branch) {@@ -128,0 +146,21 @@146+ );147+ const threadGitTargets = useMemo(148+ () =>149+ state.threads.map((thread) => ({150+ threadId: thread.id,151+ branch: thread.branch,152+ cwd: thread.worktreePath ?? projectCwdById.get(thread.projectId) ?? null,153+ })),154+ [projectCwdById, state.threads],155+ );156+ const threadGitStatusQueries = useQueries({157+ queries: threadGitTargets.map((target) => {158+ const base = gitStatusQueryOptions(api, target.cwd);159+ return {160+ ...base,161+ enabled: Boolean(base.enabled && target.branch !== null),162+ staleTime: 30_000,163+ refetchInterval: 60_000,164+ };165+ }),166+ });@@ -128,0 +152,21 @@152+ cwd: thread.worktreePath ?? projectCwdById.get(thread.projectId) ?? null,153+ })),154+ [projectCwdById, state.threads],155+ );156+ const threadGitStatusQueries = useQueries({157+ queries: threadGitTargets.map((target) => {158+ const base = gitStatusQueryOptions(api, target.cwd);159+ return {160+ ...base,161+ enabled: Boolean(base.enabled && target.branch !== null),162+ staleTime: 30_000,163+ refetchInterval: 60_000,164+ };165+ }),166+ });167+ const mergedPrByThreadId = useMemo(() => {168+ const map = new Map<string, boolean>();169+ for (let index = 0; index < threadGitTargets.length; index += 1) {170+ const target = threadGitTargets[index];171+ if (!target) continue;172+ const status = threadGitStatusQueries[index]?.data as GitStatusResult | undefined;
- apps/server/src/gitManager.ts line 464OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -404,4 +457,8 @@404457 throw new Error("GitHub CLI returned invalid PR list JSON.");405458 }406459407- const parsed = parseOpenPrList(parsedJson);460+ const parsed = parsePullRequestList(parsedJson).toSorted((a, b) => {461+ const left = a.updatedAt ? Date.parse(a.updatedAt) : 0;462+ const right = b.updatedAt ? Date.parse(b.updatedAt) : 0;463+ return right - left;464+ });apps/web/src/components/Sidebar.tsx line 5OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1 +1,5 @@1-import { TerminalIcon } from "lucide-react";1+import {2+ GitPullRequestIcon,3+ MonitorIcon,4+ MoonIcon,5+ SunIcon,
- @@ -129,0 +206,21 @@206+ ],207+ })208+ .pipe(Effect.map((result) => result.stdout));209+210+ const raw = stdout.trim();211+ if (raw.length === 0) {212+ return null;213+ }214+215+ const parsedJson = yield* Effect.try({216+ try: () => JSON.parse(raw) as unknown,217+ catch: (cause) =>218+ gitManagerError("findLatestPr", "GitHub CLI returned invalid PR list JSON.", cause),219+ });220+221+ const parsed = parsePullRequestList(parsedJson).toSorted((a, b) => {222+ const left = a.updatedAt ? Date.parse(a.updatedAt) : 0;223+ const right = b.updatedAt ? Date.parse(b.updatedAt) : 0;224+ return right - left;225+ });226+ return parsed[0] ?? null;
juliusmarminge closed this
Sign in to join this conversation.



Note
Reviews paused#
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
reviews.auto_review.auto_pause_after_reviewed_commitssetting.Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.Use the checkboxes below for quick actions:
📝 Walkthrough
Walkthrough#
Replaces
openPrwith a nullableprobject that includes a normalized PRstate("open" | "closed" | "merged") andupdatedAt. Server PR lookup now queries broader PR states and selects the most recently updated PR; UI, tests, and contracts updated to consume the newprshape.Changes#
packages/contracts/src/git.ts,packages/contracts/src/git.test.tsopenPrwith `pr: GitStatusPrapps/server/src/git.tsGitStatusDetails/ service payload to usepr(nullable) instead ofopenPr; aligned exported types with contract.apps/server/src/gitManager.tsPullRequestInfowithstateandupdatedAt; addedfindLatestPr(...); parse/normalizestate/updatedAt; status() now returnspr(latest PR) instead ofopenPr.apps/server/src/gitManager.test.ts,apps/server/src/wsServer.test.tsprandpr.state; added merged/closed scenarios and ensured gh invoked with wider state lookups.apps/web/src/components/GitActionsControl.logic.ts,apps/web/src/components/GitActionsControl.logic.test.ts,apps/web/src/components/GitActionsControl.tsx,apps/web/src/components/Sidebar.tsxopenPrwithpr?.state === "open"; derive PR URLs frompr.url; wired per-thread PR state in Sidebar and added PR status pill rendering; updated tests and effect dependencies.apps/server/src/gitManager.*,apps/server/src/git.*(others grouped)state,mergedAt,updatedAt; error handling for PR JSON parsing tightened; minor signature/name updates (OpenPrInfo → PullRequestInfo).Sequence Diagram#
Estimated code review effort#
🎯 4 (Complex) | ⏱️ ~45 minutes
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (2 passed)
✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands and usage tips.