Public: anyone can read this; the crew can change it.
A merged pull shows the change it landed with (#16421) #16422
Check · Review · Land · Live done — Landed and live in production.
fix/merged-pull-diff → main 0 commits
2 files
changed +114
−0
src/core/pulls.ts +6
| @@ -928,6 +928,12 @@ export async function pullStatus( | ||
| 928 | 928 | pull: Pull, |
| 929 | 929 | gate?: ReviewGate, |
| 930 | 930 | ): Promise<PullStatus> { |
| 931 | // A merged pull is history: its change is the one it landed with, read from the base and head | |
| 932 | // recorded at the merge. Against the live base, which now holds the head, it would be empty. | |
| 933 | if (typeof pull.mergedAt === "string" && pull.baseOid !== "" && pull.headOid !== "") { | |
| 934 | const reviews = gate === undefined ? null : reviewGate(gate, pull, pull.headOid, pull.baseOid); | |
| 935 | return { baseOid: pull.baseOid, headOid: pull.headOid, ahead: 0, mergeable: false, conflicts: [], reviews }; | |
| 936 | } | |
| 931 | 937 | const headRef = pull.crossRepo |
| 932 | 938 | ? `refs/pull/${pull.number}/head` |
| 933 | 939 | : `refs/heads/${pull.headBranch}`; |
test/pull-merged-files.test.ts added +108
| @@ -0,0 +1,108 @@ | ||
| 1 | /** | |
| 2 | * A merged pull keeps its change (#16421): its Files tab and the API's diff read the base and head | |
| 3 | * recorded when it landed, not the live base, which now holds the head and would show nothing. | |
| 4 | */ | |
| 5 | ||
| 6 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 7 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 8 | import { tmpdir } from "node:os"; | |
| 9 | import { join } from "node:path"; | |
| 10 | import { mergePull, openPull } from "../src/actions/pulls.ts"; | |
| 11 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; | |
| 12 | import { createApp, type App } from "../src/app.ts"; | |
| 13 | import { createSession } from "../src/core/sessions.ts"; | |
| 14 | import { createToken } from "../src/core/tokens.ts"; | |
| 15 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 16 | import { seedAdmin } from "./helpers/admin.ts"; | |
| 17 | import { quietLogs } from "./helpers/globals.ts"; | |
| 18 | ||
| 19 | quietLogs(); | |
| 20 | ||
| 21 | let dataDir: string; | |
| 22 | let app: App; | |
| 23 | let servers: Servers; | |
| 24 | let cookie = ""; | |
| 25 | let token = ""; | |
| 26 | ||
| 27 | beforeAll(async () => { | |
| 28 | dataDir = await mkdtemp(join(tmpdir(), "forge-pull-merged-files-")); | |
| 29 | app = createApp({ dataDir, port: 0 }); | |
| 30 | servers = await serve(app); | |
| 31 | const a = await seedAdmin(app, { | |
| 32 | username: "alice", | |
| 33 | email: "[email protected]", | |
| 34 | password: "a-long-merged-passphrase", | |
| 35 | }); | |
| 36 | if (!a.ok) throw new Error("admin"); | |
| 37 | cookie = `forge_session=${createSession(app.db, a.value.id).token}`; | |
| 38 | token = createToken(app.db, a.value.id, "t", "rw").token; | |
| 39 | const made = await createRepo(app, a.value, { | |
| 40 | name: "voxel", | |
| 41 | visibility: "public", | |
| 42 | }); | |
| 43 | if (!made.ok) throw new Error("repo"); | |
| 44 | await commitToBranch(app, a.value, made.value, { | |
| 45 | message: "first", | |
| 46 | files: [{ path: "README.md", content: "# voxel\n" }], | |
| 47 | }); | |
| 48 | await commitToBranch(app, a.value, made.value, { | |
| 49 | branch: "brighter", | |
| 50 | base: "main", | |
| 51 | message: "Brighter blocks", | |
| 52 | files: [{ path: "blocks.txt", content: "bright\n" }], | |
| 53 | }); | |
| 54 | for (const strategy of ["merge", "squash"] as const) { | |
| 55 | const branch = strategy === "merge" ? "brighter" : "darker"; | |
| 56 | if (strategy === "squash") | |
| 57 | await commitToBranch(app, a.value, made.value, { | |
| 58 | branch, | |
| 59 | base: "main", | |
| 60 | message: "Darker sky", | |
| 61 | files: [{ path: "sky.txt", content: "dark\n" }], | |
| 62 | }); | |
| 63 | const opened = await openPull(app, a.value, made.value, { | |
| 64 | title: branch, | |
| 65 | baseBranch: "main", | |
| 66 | headBranch: branch, | |
| 67 | }); | |
| 68 | if (!opened.ok) throw new Error(JSON.stringify(opened.error)); | |
| 69 | const merged = await mergePull( | |
| 70 | app, | |
| 71 | a.value, | |
| 72 | made.value, | |
| 73 | opened.value, | |
| 74 | strategy, | |
| 75 | ); | |
| 76 | if (!merged.ok) throw new Error(JSON.stringify(merged.error)); | |
| 77 | } | |
| 78 | }); | |
| 79 | ||
| 80 | afterAll(async () => { | |
| 81 | servers.stop(); | |
| 82 | app.close(); | |
| 83 | await rm(dataDir, { recursive: true, force: true }); | |
| 84 | }); | |
| 85 | ||
| 86 | test("a merged pull's Files tab shows the change it landed with, for a merge and a squash", async () => { | |
| 87 | for (const [n, file] of [ | |
| 88 | [1, "blocks.txt"], | |
| 89 | [2, "sky.txt"], | |
| 90 | ] as const) { | |
| 91 | const page = await ( | |
| 92 | await fetch(`${servers.url}/alice/voxel/pulls/${n}/files`, { | |
| 93 | headers: { cookie }, | |
| 94 | }) | |
| 95 | ).text(); | |
| 96 | expect(page).not.toContain("No changes."); | |
| 97 | expect(page).toContain(file); | |
| 98 | } | |
| 99 | }); | |
| 100 | ||
| 101 | test("the API's diff of a merged pull is that change too", async () => { | |
| 102 | const res = await fetch( | |
| 103 | `${servers.url}/api/v1/repos/alice/voxel/pulls/1/files`, | |
| 104 | { headers: { authorization: `Bearer ${token}` } }, | |
| 105 | ); | |
| 106 | expect(res.status).toBe(200); | |
| 107 | expect(JSON.stringify(await res.json())).toContain("blocks.txt"); | |
| 108 | }); |
new above
offline