Add `pr merge` with all six Gitea methods, the three common-method shorthands, `--auto`, `--delete-branch`, `--subject`, `--body`/`--body-file`, and `--merge-commit-id` (required with and only valid for `--method manually-merged`). Conflicting method flags and the manually-merged/commit-id pairing are rejected as VALIDATION_ERROR before any API call. An already-merged PR short-circuits to a `pull_request` entity block with `merged_by`/`merged_at`; merge-blocked 405/409 responses surface as VALIDATION_ERROR with update-branch/checkout remediation. Add `pr update-branch` merging the base into the head via the update endpoint with `--style <merge|rebase>` (default merge).
67 lines
2.3 KiB
TypeScript
67 lines
2.3 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 UPDATE_PATH = `${REPO_PATH}/pulls/9/update`;
|
|
|
|
let server: FixtureServer;
|
|
|
|
afterEach(async () => {
|
|
await server.close();
|
|
});
|
|
|
|
function updateRequest() {
|
|
return server.requests.find(
|
|
(request) => request.method === "POST" && request.path === UPDATE_PATH,
|
|
);
|
|
}
|
|
|
|
describe("pr update-branch", () => {
|
|
it("updates the head branch with the default merge style", async () => {
|
|
server = await startFixtureServer([{ method: "POST", path: UPDATE_PATH, body: {} }]);
|
|
const { stdout, exitCode } = await runCliTest(["pr", "update-branch", "9"], {
|
|
env: testModeEnv(server.url),
|
|
});
|
|
|
|
expect(exitCode).toBe(0);
|
|
expect(stdout).toContain("updated:");
|
|
expect(stdout).toContain("number: 9");
|
|
expect(stdout).toContain("status: ok");
|
|
expect(updateRequest()?.query.style).toBe("merge");
|
|
});
|
|
|
|
it("passes --style rebase to the update endpoint", async () => {
|
|
server = await startFixtureServer([{ method: "POST", path: UPDATE_PATH, body: {} }]);
|
|
const { stdout, exitCode } = await runCliTest(["pr", "update-branch", "9", "--style", "rebase"], {
|
|
env: testModeEnv(server.url),
|
|
});
|
|
|
|
expect(exitCode).toBe(0);
|
|
expect(stdout).toContain("updated:");
|
|
expect(updateRequest()?.query.style).toBe("rebase");
|
|
});
|
|
|
|
it("rejects an invalid --style value before any API call", async () => {
|
|
server = await startFixtureServer([]);
|
|
const { stdout, exitCode } = await runCliTest(["pr", "update-branch", "9", "--style", "cherry"], {
|
|
env: testModeEnv(server.url),
|
|
});
|
|
|
|
expect(exitCode).toBe(2);
|
|
expect(stdout).toContain("code: VALIDATION_ERROR");
|
|
expect(server.requests).toHaveLength(0);
|
|
});
|
|
|
|
it("prints help with --help without calling the API", async () => {
|
|
server = await startFixtureServer([]);
|
|
const { stdout, exitCode } = await runCliTest(["pr", "update-branch", "--help"], {
|
|
env: testModeEnv(server.url),
|
|
});
|
|
|
|
expect(exitCode).toBe(0);
|
|
expect(stdout).toContain("usage: gitea-axi pr update-branch");
|
|
expect(server.requests).toHaveLength(0);
|
|
});
|
|
});
|