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:
92
test/issue-close.test.ts
Normal file
92
test/issue-close.test.ts
Normal file
@@ -0,0 +1,92 @@
|
||||
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";
|
||||
const COMMENTS_PATH = "/api/v1/repos/testowner/testrepo/issues/7/comments";
|
||||
|
||||
let server: FixtureServer;
|
||||
|
||||
afterEach(async () => {
|
||||
await server.close();
|
||||
});
|
||||
|
||||
describe("issue close", () => {
|
||||
it("closes an open issue and reports the action", async () => {
|
||||
server = await startFixtureServer([
|
||||
{ method: "GET", path: ISSUE_PATH, body: { number: 7, state: "open" } },
|
||||
{ method: "PATCH", path: ISSUE_PATH, body: { number: 7, state: "closed" } },
|
||||
]);
|
||||
const { stdout, exitCode } = await runCliTest(["issue", "close", "7"], {
|
||||
env: testModeEnv(server.url),
|
||||
});
|
||||
|
||||
expect(exitCode).toBe(0);
|
||||
expect(stdout).toContain("closed:");
|
||||
expect(stdout).toContain("number: 7");
|
||||
expect(stdout).toContain("status: ok");
|
||||
const patch = server.requests.find((request) => request.method === "PATCH");
|
||||
expect(patch?.body).toEqual({ state: "closed" });
|
||||
});
|
||||
|
||||
it("posts a --comment after the close and reports success", async () => {
|
||||
server = await startFixtureServer([
|
||||
{ method: "GET", path: ISSUE_PATH, body: { number: 7, state: "open" } },
|
||||
{ method: "PATCH", path: ISSUE_PATH, body: { number: 7, state: "closed" } },
|
||||
{ method: "POST", path: COMMENTS_PATH, status: 201, body: { id: 1 } },
|
||||
]);
|
||||
const { exitCode } = await runCliTest(
|
||||
["issue", "close", "7", "--comment", "Fixed in main."],
|
||||
{ env: testModeEnv(server.url) },
|
||||
);
|
||||
|
||||
expect(exitCode).toBe(0);
|
||||
const post = server.requests.find((request) => request.method === "POST");
|
||||
expect(post?.body).toEqual({ body: "Fixed in main." });
|
||||
// The close lands before the comment.
|
||||
const patchIndex = server.requests.findIndex((request) => request.method === "PATCH");
|
||||
const postIndex = server.requests.findIndex((request) => request.method === "POST");
|
||||
expect(patchIndex).toBeLessThan(postIndex);
|
||||
});
|
||||
|
||||
it("surfaces a comment-post failure even though the issue was closed", async () => {
|
||||
server = await startFixtureServer([
|
||||
{ method: "GET", path: ISSUE_PATH, body: { number: 7, state: "open" } },
|
||||
{ method: "PATCH", path: ISSUE_PATH, body: { number: 7, state: "closed" } },
|
||||
{ method: "POST", path: COMMENTS_PATH, status: 403, body: { message: "forbidden" } },
|
||||
]);
|
||||
const { stdout, exitCode } = await runCliTest(
|
||||
["issue", "close", "7", "--comment", "note"],
|
||||
{ env: testModeEnv(server.url) },
|
||||
);
|
||||
|
||||
expect(exitCode).toBe(1);
|
||||
expect(stdout).toContain("code: FORBIDDEN");
|
||||
// The close still happened.
|
||||
expect(server.requests.some((request) => request.method === "PATCH")).toBe(true);
|
||||
});
|
||||
|
||||
it("returns early with Already closed on an already-closed issue", async () => {
|
||||
server = await startFixtureServer([
|
||||
{ method: "GET", path: ISSUE_PATH, body: { number: 7, state: "closed" } },
|
||||
]);
|
||||
const { stdout, exitCode } = await runCliTest(["issue", "close", "7"], {
|
||||
env: testModeEnv(server.url),
|
||||
});
|
||||
|
||||
expect(exitCode).toBe(0);
|
||||
expect(stdout).toContain("message: Already closed");
|
||||
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", "close", "--help"], {
|
||||
env: testModeEnv(server.url),
|
||||
});
|
||||
|
||||
expect(exitCode).toBe(0);
|
||||
expect(stdout).toContain("usage: gitea-axi issue close");
|
||||
expect(server.requests).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user