C1: the gate and the forge hold no branch name; the trunk is the asked branch, a default is the repository's
Builds: design 47 G §428, §507, A-93 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
This commit is contained in:
@@ -17,12 +17,19 @@ const rules = [
|
||||
{ branch_name: "release", enable_push: false },
|
||||
];
|
||||
const seen: string[] = [];
|
||||
const opened: { base?: string }[] = [];
|
||||
|
||||
const server = createServer((req, res) => {
|
||||
const path = (req.url ?? "").replace(/^\/api\/v1/, "");
|
||||
const as = req.headers.authorization === adminBasic ? "admin" : "tools";
|
||||
seen.push(`${req.method} ${path} as ${as}`);
|
||||
const send = (status: number, body: unknown) => { res.writeHead(status, { "Content-Type": "application/json" }); res.end(JSON.stringify(body)); };
|
||||
if (path === "/repos/novox/app") return send(200, { full_name: "novox/app", default_branch: "trunk" });
|
||||
if (req.method === "POST" && path === "/repos/novox/app/pulls") {
|
||||
let raw = "";
|
||||
req.on("data", (c) => (raw += c));
|
||||
return req.on("end", () => { opened.push(JSON.parse(raw)); send(201, { number: 7, title: "t", state: "open", html_url: "u" }); });
|
||||
}
|
||||
if (path.includes("/branch_protections")) {
|
||||
if (as !== "admin") return send(403, { message: "user should be an owner or a collaborator with admin write of a repository" });
|
||||
if (req.method === "GET") return send(200, rules);
|
||||
@@ -57,3 +64,10 @@ test("gitea_branch_protection_set still gets the forge's refusal, as the tools'
|
||||
);
|
||||
assert.ok(!seen.some((s) => /^(PATCH|POST|PUT|DELETE) .*branch_protections.* as admin$/.test(s)), seen.join("\n"));
|
||||
});
|
||||
|
||||
// Design 47 G §428: no part's code holds a branch's name; a pull request opened with no base goes to the repository's default branch.
|
||||
test("gitea_create_pull_request with no base opens against the repository's default branch, and a named base stays", async () => {
|
||||
await tool("gitea_create_pull_request").run({ owner: "novox", repo: "app", title: "t", head: "feat/x" });
|
||||
await tool("gitea_create_pull_request").run({ owner: "novox", repo: "app", title: "t", head: "feat/x", base: "release" });
|
||||
assert.deepEqual(opened.map((o) => o.base), ["trunk", "release"]);
|
||||
});
|
||||
|
||||
@@ -93,6 +93,12 @@ export function getGiteaTools(gitea: GiteaClient, admin?: () => GiteaAdmin): Too
|
||||
// A merge, a status, a comment, a delivery's view and its note are the seat git's acts (seat.ts), asked by the forge
|
||||
// bridge alone: no tool of the module's own does them (novox/hq design 47 *The seat git*).
|
||||
function allGiteaTools(gitea: GiteaClient, admin: (() => GiteaAdmin) | undefined): ToolDefinition[] {
|
||||
// A branch no caller named is the repository's default branch, as the forge says it; no part's code holds one (§428).
|
||||
const defaultBranchOf = async (owner: string, repo: string): Promise<string> => {
|
||||
const found = String((await gitea.getRepo(owner, repo)).default_branch ?? "");
|
||||
if (!found) throw new Error(`the forge names no default branch of ${owner}/${repo}: name the branch`);
|
||||
return found;
|
||||
};
|
||||
return [
|
||||
// ---- Repositories ----
|
||||
{
|
||||
@@ -269,14 +275,14 @@ function allGiteaTools(gitea: GiteaClient, admin: (() => GiteaAdmin) | undefined
|
||||
title: { type: "string", description: "the PR title" },
|
||||
body: { type: "string", description: "the PR body (markdown)" },
|
||||
head: { type: "string", description: "the source branch" },
|
||||
base: { type: "string", description: "the target branch (default main)" },
|
||||
base: { type: "string", description: "the target branch (default: the repository's default branch)" },
|
||||
},
|
||||
run: async (args) => ({
|
||||
pull: await gitea.createPullRequest(String(args.owner), String(args.repo), {
|
||||
title: String(args.title),
|
||||
body: args.body ? String(args.body) : undefined,
|
||||
head: String(args.head),
|
||||
base: args.base ? String(args.base) : "main",
|
||||
base: args.base ? String(args.base) : await defaultBranchOf(String(args.owner), String(args.repo)),
|
||||
}),
|
||||
}),
|
||||
},
|
||||
@@ -679,7 +685,7 @@ function allGiteaTools(gitea: GiteaClient, admin: (() => GiteaAdmin) | undefined
|
||||
repo: { type: "string", description: "the repository name" },
|
||||
number: { type: "number", description: "a pull request's number: its head is read, and its base's protection" },
|
||||
sha: { type: "string", description: "a commit, or the start of one, instead of a pull request" },
|
||||
base: { type: "string", description: "with sha: the branch whose protection is read (default main)" },
|
||||
base: { type: "string", description: "with sha: the branch whose protection is read (default: the repository's default branch)" },
|
||||
},
|
||||
run: async (args) => {
|
||||
const owner = String(args.owner ?? "").trim(), repo = String(args.repo ?? "").trim();
|
||||
@@ -702,7 +708,7 @@ function allGiteaTools(gitea: GiteaClient, admin: (() => GiteaAdmin) | undefined
|
||||
if (!ref) throw new Error("name a pull request's number or a commit");
|
||||
const combined = await gitea.combinedStatus(owner, repo, ref);
|
||||
const statuses = newestByContext(combined.statuses);
|
||||
base = base || "main";
|
||||
base = base || (await defaultBranchOf(owner, repo));
|
||||
let rule: BranchProtection | null = null, unreadable: string | undefined;
|
||||
try {
|
||||
rule = await gitea.appliedProtection(owner, repo, base);
|
||||
|
||||
Reference in New Issue
Block a user