fix(server): preserve merged PR badges after branch deletion (#6216)
This commit is contained in:
1 parent
be3da50e96
commit
ba30177b5a
2 files changed
+95
-13
No files matched your search
@@ -974,6 +974,75 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("status finds a merged PR after its remote branch was deleted", () =>
|
||||
Effect.gen(function* () {
|
||||
const repoDir = yield* makeTempDir("t3code-git-manager-");
|
||||
yield* initRepo(repoDir);
|
||||
const remoteDir = yield* createBareRemote();
|
||||
yield* runGit(repoDir, ["remote", "add", "origin", remoteDir]);
|
||||
yield* runGit(repoDir, ["push", "-u", "origin", "main"]);
|
||||
yield* runGit(repoDir, ["checkout", "-b", "feature/merged-branch-deleted"]);
|
||||
yield* runGit(repoDir, ["push", "-u", "origin", "feature/merged-branch-deleted"]);
|
||||
|
||||
// GitHub commonly deletes a pull request's head branch after merge. Git
|
||||
// removes the remote-tracking ref, but preserves the local branch's
|
||||
// remote and merge configuration as evidence that it was published.
|
||||
yield* runGit(repoDir, ["push", "origin", "--delete", "feature/merged-branch-deleted"]);
|
||||
const configuredRemote = yield* runGit(repoDir, [
|
||||
"config",
|
||||
"--get",
|
||||
"branch.feature/merged-branch-deleted.remote",
|
||||
]);
|
||||
const configuredMerge = yield* runGit(repoDir, [
|
||||
"config",
|
||||
"--get",
|
||||
"branch.feature/merged-branch-deleted.merge",
|
||||
]);
|
||||
const trackingRef = yield* runGit(repoDir, [
|
||||
"for-each-ref",
|
||||
"--format=%(refname)",
|
||||
"refs/remotes/origin/feature/merged-branch-deleted",
|
||||
]);
|
||||
expect(configuredRemote.stdout.trim()).toBe("origin");
|
||||
expect(configuredMerge.stdout.trim()).toBe("refs/heads/feature/merged-branch-deleted");
|
||||
expect(trackingRef.stdout.trim()).toBe("");
|
||||
|
||||
const { manager, ghCalls } = yield* makeManager({
|
||||
ghScenario: {
|
||||
prListSequence: [
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
JSON.stringify([
|
||||
{
|
||||
number: 215,
|
||||
title: "Merged branch was deleted",
|
||||
url: "https://github.com/pingdotgg/t3code/pull/215",
|
||||
baseRefName: "main",
|
||||
headRefName: "feature/merged-branch-deleted",
|
||||
state: "MERGED",
|
||||
mergedAt: "2026-04-02T15:00:00Z",
|
||||
updatedAt: "2026-04-02T15:00:00Z",
|
||||
},
|
||||
]),
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
const status = yield* manager.status({ cwd: repoDir });
|
||||
|
||||
expect(status.hasUpstream).toBe(false);
|
||||
expect(status.pr).toEqual({
|
||||
number: 215,
|
||||
title: "Merged branch was deleted",
|
||||
url: "https://github.com/pingdotgg/t3code/pull/215",
|
||||
baseRef: "main",
|
||||
headRef: "feature/merged-branch-deleted",
|
||||
state: "merged",
|
||||
updatedAt: "2026-04-02T15:00:00.000Z",
|
||||
});
|
||||
expect(ghCalls.filter((call) => call.startsWith("pr list ")).length).toBeGreaterThan(0);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("status still looks up PRs for a branch pushed without --set-upstream", () =>
|
||||
Effect.gen(function* () {
|
||||
const repoDir = yield* makeTempDir("t3code-git-manager-");
|
||||
|
||||
@@ -1268,15 +1268,17 @@ export const make = Effect.gen(function* () {
|
||||
* cannot exist for it and asking the provider is a guaranteed-empty API call.
|
||||
*
|
||||
* `git push` writes the remote-tracking ref even without `-u` (how most
|
||||
* terminal and agent pushes land), which makes this a safer "did it ever
|
||||
* reach the host" test than looking for upstream config, and the glob spans
|
||||
* every remote so a fork branch still counts. A repository that tracks no
|
||||
* remotes at all cannot answer the question, because then every branch looks
|
||||
* unpublished; it, and any failed probe, keeps the lookup.
|
||||
* terminal and agent pushes land), and configured upstream metadata survives
|
||||
* when a merged change request's remote branch is deleted. Together they
|
||||
* distinguish branches known to have reached a host from genuinely local
|
||||
* branches. The ref glob spans every remote so a fork branch still counts. A
|
||||
* repository that tracks no remotes at all cannot answer the question,
|
||||
* because then every branch looks unpublished; it, and any failed probe,
|
||||
* keeps the lookup.
|
||||
*/
|
||||
const isUnpublishedBranch = Effect.fn("isUnpublishedBranch")(function* (
|
||||
cwd: string,
|
||||
headContext: Pick<BranchHeadContext, "headBranch">,
|
||||
headContext: Pick<BranchHeadContext, "headBranch" | "localBranch">,
|
||||
) {
|
||||
if (headContext.headBranch.length === 0) {
|
||||
return false;
|
||||
@@ -1291,13 +1293,24 @@ export const make = Effect.gen(function* () {
|
||||
})
|
||||
.pipe(Effect.map((result) => result.stdout.trim().length > 0));
|
||||
|
||||
return yield* Effect.all(
|
||||
[matchesRef("refs/remotes"), matchesRef(`refs/remotes/*/${headContext.headBranch}`)],
|
||||
{ concurrency: "unbounded" },
|
||||
).pipe(
|
||||
Effect.map(([tracksAnyRemote, tracksThisBranch]) => tracksAnyRemote && !tracksThisBranch),
|
||||
Effect.orElseSucceed(() => false),
|
||||
);
|
||||
return yield* Effect.gen(function* () {
|
||||
const [configuredRemote, configuredMerge] = yield* Effect.all(
|
||||
[
|
||||
gitCore.readConfigValue(cwd, `branch.${headContext.localBranch}.remote`),
|
||||
gitCore.readConfigValue(cwd, `branch.${headContext.localBranch}.merge`),
|
||||
],
|
||||
{ concurrency: "unbounded" },
|
||||
);
|
||||
if (configuredRemote !== null && configuredMerge !== null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const [tracksAnyRemote, tracksThisBranch] = yield* Effect.all(
|
||||
[matchesRef("refs/remotes"), matchesRef(`refs/remotes/*/${headContext.headBranch}`)],
|
||||
{ concurrency: "unbounded" },
|
||||
);
|
||||
return tracksAnyRemote && !tracksThisBranch;
|
||||
}).pipe(Effect.orElseSucceed(() => false));
|
||||
});
|
||||
|
||||
const findOpenPr = Effect.fn("findOpenPr")(function* (
|
||||
|
||||
Reference in new issue
Block a user