feat: add issue edit, close, and reopen (task 0005)
Implement the issue state-transition mutations:
- issue edit: --title, --body/--body-file, --add-label/--remove-label,
--add-assignee/--remove-assignee, --milestone. Label mutations use
Gitea's dedicated additive/removal endpoints (names added directly,
removals resolved to IDs, unapplied-label 404 as silent success);
assignees use fetch-then-patch (ADR 0007); title/body/milestone and the
recomputed assignee list travel in one PATCH. Outputs edited: {number,
status: ok}.
- issue close: PATCHes state closed, optional --comment posted after with
its failure surfaced; already-closed short-circuits with Already closed.
- issue reopen: PATCHes state open; already-open short-circuits with
Already open.
Extract a shared getIssue helper used by view/edit/close/reopen.
This commit was merged in pull request #6.
This commit is contained in:
54
test/issue-reopen.test.ts
Normal file
54
test/issue-reopen.test.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { startFixtureServer, type FixtureServer } from "./fixture-server.js";
|
||||
import { runCliTest, testModeEnv } from "./harness.js";
|
||||
|
||||
const ISSUE_PATH = "/api/v1/repos/testowner/testrepo/issues/7";
|
||||
|
||||
let server: FixtureServer;
|
||||
|
||||
afterEach(async () => {
|
||||
await server.close();
|
||||
});
|
||||
|
||||
describe("issue reopen", () => {
|
||||
it("reopens a closed issue and reports the action", async () => {
|
||||
server = await startFixtureServer([
|
||||
{ method: "GET", path: ISSUE_PATH, body: { number: 7, state: "closed" } },
|
||||
{ method: "PATCH", path: ISSUE_PATH, body: { number: 7, state: "open" } },
|
||||
]);
|
||||
const { stdout, exitCode } = await runCliTest(["issue", "reopen", "7"], {
|
||||
env: testModeEnv(server.url),
|
||||
});
|
||||
|
||||
expect(exitCode).toBe(0);
|
||||
expect(stdout).toContain("reopened:");
|
||||
expect(stdout).toContain("number: 7");
|
||||
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 open on an already-open issue", async () => {
|
||||
server = await startFixtureServer([
|
||||
{ method: "GET", path: ISSUE_PATH, body: { number: 7, state: "open" } },
|
||||
]);
|
||||
const { stdout, exitCode } = await runCliTest(["issue", "reopen", "7"], {
|
||||
env: testModeEnv(server.url),
|
||||
});
|
||||
|
||||
expect(exitCode).toBe(0);
|
||||
expect(stdout).toContain("message: Already open");
|
||||
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(["issue", "reopen", "--help"], {
|
||||
env: testModeEnv(server.url),
|
||||
});
|
||||
|
||||
expect(exitCode).toBe(0);
|
||||
expect(stdout).toContain("usage: gitea-axi issue reopen");
|
||||
expect(server.requests).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user