Files
gitea-axi/test/pr-reopen.test.ts
alexion 965ece306f
All checks were successful
CI / test (pull_request) Successful in 38s
CI / test (push) Successful in 39s
feat: add pr edit, close, and reopen (task 0011)
Add the PR-side state mutations mirroring the issue-side slice:

- `pr edit` applies title/body/base/milestone and the recomputed assignee
  list in one PATCH, with additive label endpoints and (per the ADR 0007
  amendment) the dedicated requested-reviewers POST/DELETE endpoints for
  `--add-reviewer`/`--remove-reviewer`.
- `pr close --comment` posts the comment after the PATCH and surfaces a
  comment-post failure; an already-closed or merged PR is an `already: true`
  no-op reporting the actual state.
- `pr reopen` is an `already: true` no-op when already open.

Extract the fetch-then-patch assignee merge into a shared `src/assignees.ts`
(`mergeAssignees` + `assigneeLogins`), now used by both `issue edit` and
`pr edit`.
2026-07-13 19:55:00 -04:00

58 lines
2.0 KiB
TypeScript

import { afterEach, describe, expect, it } from "vitest";
import { startFixtureServer, type FixtureServer } from "./fixture-server.js";
import { runCliTest, testModeEnv } from "./harness.js";
const REPO_PATH = "/api/v1/repos/testowner/testrepo";
const PR_PATH = `${REPO_PATH}/pulls/9`;
let server: FixtureServer;
afterEach(async () => {
await server.close();
});
describe("pr reopen", () => {
it("reopens a closed pull request and reports the action", async () => {
server = await startFixtureServer([
{ method: "GET", path: PR_PATH, body: { number: 9, state: "closed" } },
{ method: "PATCH", path: PR_PATH, body: { number: 9, state: "open" } },
]);
const { stdout, exitCode } = await runCliTest(["pr", "reopen", "9"], {
env: testModeEnv(server.url),
});
expect(exitCode).toBe(0);
expect(stdout).toContain("reopened:");
expect(stdout).toContain("number: 9");
expect(stdout).toContain("status: ok");
const patch = server.requests.find((request) => request.method === "PATCH");
expect(patch?.body).toEqual({ state: "open" });
});
it("returns early with already: true on an already-open pull request", async () => {
server = await startFixtureServer([
{ method: "GET", path: PR_PATH, body: { number: 9, state: "open" } },
]);
const { stdout, exitCode } = await runCliTest(["pr", "reopen", "9"], {
env: testModeEnv(server.url),
});
expect(exitCode).toBe(0);
expect(stdout).toContain("pull_request:");
expect(stdout).toContain("state: open");
expect(stdout).toContain("already: true");
expect(server.requests.some((request) => request.method === "PATCH")).toBe(false);
});
it("prints help with --help without calling the API", async () => {
server = await startFixtureServer([]);
const { stdout, exitCode } = await runCliTest(["pr", "reopen", "--help"], {
env: testModeEnv(server.url),
});
expect(exitCode).toBe(0);
expect(stdout).toContain("usage: gitea-axi pr reopen");
expect(server.requests).toHaveLength(0);
});
});