Skip local-branch PR checks and dedupe sidebar git status

- server: only query open PRs when the current branch has an upstream; still fall back to merged PR lookup
- tests: cover status behavior for branches without upstream tracking
- web: fetch git status once per cwd, validate query data with schema parsing, and map merged PR badges by thread branch match
This commit is contained in:
Julius Marminge committed 2026-02-15 14:28:03 -08:00
1 parent 46347e2bd2
commit dcdb9ac923
3 files changed
+58 -13

No files matched your search

+22
View File
@@ -242,6 +242,28 @@ describe("GitManager", () => {
expect(ghCalls.some((call) => call.includes("--state merged"))).toBe(true);
});
it("status skips open PR lookup for branches without upstream", async () => {
const repoDir = makeTempDir("t3code-git-manager-");
await initRepo(repoDir);
await runGit(repoDir, ["checkout", "-b", "feature/local-only"]);
const { runner, ghCalls } = createRunnerWithFakeGh({
prListSequence: ["[]"],
});
const manager = new GitManager({
runProcess: runner,
textGenerator: createTextGenerator(),
});
const status = await manager.status({ cwd: repoDir });
expect(status.branch).toBe("feature/local-only");
expect(status.openPr).toBeNull();
expect(status.mergedPr).toBeNull();
expect(ghCalls.some((call) => call.includes("--state open"))).toBe(false);
expect(ghCalls.some((call) => call.includes("--state merged"))).toBe(true);
});
it("status is resilient to gh lookup failures and returns openPr/mergedPr null", async () => {
const repoDir = makeTempDir("t3code-git-manager-");
await initRepo(repoDir);
+7 -4
View File
@@ -195,10 +195,13 @@ export class GitManager {
let mergedPr: ReturnType<typeof toStatusOpenPr> | null = null;
if (details.branch) {
try {
const existing = await this.findOpenPr(input.cwd, details.branch);
if (existing) {
openPr = toStatusOpenPr(existing);
} else {
if (details.hasUpstream) {
const existing = await this.findOpenPr(input.cwd, details.branch);
if (existing) {
openPr = toStatusOpenPr(existing);
}
}
if (!openPr) {
const merged = await this.findMergedPr(input.cwd, details.branch);
if (merged) {
mergedPr = toStatusOpenPr(merged);
+29 -9
View File
@@ -1,7 +1,7 @@
import { MonitorIcon, MoonIcon, SunIcon, TerminalIcon } from "lucide-react";
import { useCallback, useEffect, useMemo, useState } from "react";
import { useMutation, useQueries, useQueryClient } from "@tanstack/react-query";
import type { GitStatusResult } from "@t3tools/contracts";
import { gitStatusResultSchema, type GitStatusResult } from "@t3tools/contracts";
import { isElectron } from "../env";
import { useTheme } from "../hooks/useTheme";
import { DEFAULT_MODEL } from "../model-logic";
@@ -153,29 +153,49 @@ export default function Sidebar() {
})),
[projectCwdById, state.threads],
);
const threadGitStatusCwds = useMemo(
() =>
[
...new Set(
threadGitTargets
.filter((target) => target.branch !== null)
.map((target) => target.cwd)
.filter((cwd): cwd is string => cwd !== null),
),
],
[threadGitTargets],
);
const threadGitStatusQueries = useQueries({
queries: threadGitTargets.map((target) => {
const base = gitStatusQueryOptions(api, target.cwd);
queries: threadGitStatusCwds.map((cwd) => {
const base = gitStatusQueryOptions(api, cwd);
return {
...base,
enabled: Boolean(base.enabled && target.branch !== null),
enabled: Boolean(base.enabled),
staleTime: 30_000,
refetchInterval: 60_000,
};
}),
});
const mergedPrByThreadId = useMemo(() => {
const statusByCwd = new Map<string, GitStatusResult>();
for (let index = 0; index < threadGitStatusCwds.length; index += 1) {
const cwd = threadGitStatusCwds[index];
if (!cwd) continue;
const parsed = gitStatusResultSchema.safeParse(threadGitStatusQueries[index]?.data);
if (parsed.success) {
statusByCwd.set(cwd, parsed.data);
}
}
const map = new Map<string, boolean>();
for (let index = 0; index < threadGitTargets.length; index += 1) {
const target = threadGitTargets[index];
if (!target) continue;
const status = threadGitStatusQueries[index]?.data as GitStatusResult | undefined;
for (const target of threadGitTargets) {
const status = target.cwd ? statusByCwd.get(target.cwd) : undefined;
const branchMatches =
target.branch !== null && status?.branch !== null && status?.branch === target.branch;
map.set(target.threadId, branchMatches && status?.openPr === null && status?.mergedPr !== null);
}
return map;
}, [threadGitStatusQueries, threadGitTargets]);
}, [threadGitStatusCwds, threadGitStatusQueries, threadGitTargets]);
const handleNewThread = useCallback(
(projectId: string) => {