mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-22 16:11:34 +01:00
On Capy, /ship hands its pull request edits and comments to Capy's PR tool, always naming the right repository (GST-3183) (#4518)
On Capy, /ship's PR body edits, comments and new PRs no longer go out through `gh` under the machine owner's GitHub account. Each write runs its checks, saves the exact text to a private file and prints a `HOST_PUBLISH:` line that names the repository (and host, off github.com) it belongs to, so Capy's PR tool sends it to the same place `gh` would have. Nothing changes outside Capy (`GSTACK_CAPY` unset). Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/specialist-batched#1 reader=specialist-batched Review-Finding: p1/specialist-batched#3 reader=specialist-batched Review-Finding: p1/red-team#6 reader=red-team Review-Finding: p1/specialist-batched#1 reader=testing Review-Finding: p1/specialist-batched#2 reader=testing
This commit is contained in:
1 parent
ed267248d3
commit
e95cea8404
15 files changed
+479
-18
No files matched your search
+25
-1
@@ -54,8 +54,13 @@ export interface PostEnv {
|
||||
readFile(path: string): string;
|
||||
out(text: string): void;
|
||||
err(text: string): void;
|
||||
/** On Capy (GSTACK_CAPY=1): write the checked parts for the host's PR tool and return its HOST_PUBLISH: line; gh is never called to write (GST-3183). */
|
||||
hostPublish?(op: Op, target: string | undefined, parts: Array<[Part, string]>, dest: HostDest): string;
|
||||
}
|
||||
|
||||
/** Where the gh write would have gone, so the host's PR tool can send the hand-off to the same place. */
|
||||
export interface HostDest { repo: string; host: string; to?: string; base?: string; head?: string; draft: boolean }
|
||||
|
||||
export const EXIT = { posted: 0, refused: 1, confirm: 2, cliFailed: 3, plainTitle: 4, usage: 64 } as const;
|
||||
|
||||
export const USAGE = `usage: gstack-post <op> [<target>] [options]
|
||||
@@ -473,7 +478,7 @@ function visibility(env: PostEnv, req: Request, kind: HostKind, configBin: strin
|
||||
try { return norm(String(JSON.parse(gl.stdout).visibility ?? "")) ?? "unknown"; } catch { return "unknown"; }
|
||||
}
|
||||
|
||||
type Part = "title" | "body";
|
||||
export type Part = "title" | "body";
|
||||
interface Located { part: Part; finding: Finding }
|
||||
|
||||
/**
|
||||
@@ -835,6 +840,25 @@ export function runPost(argv: string[], env: PostEnv, configBin = "gstack-config
|
||||
return EXIT.confirm;
|
||||
}
|
||||
}
|
||||
if (env.hostPublish) {
|
||||
let head = req.head;
|
||||
if (req.op === "pr-create" && !head) {
|
||||
const b = env.run("git", ["branch", "--show-current"]);
|
||||
head = b.status === 0 ? b.stdout.trim() : "";
|
||||
if (!head) throw new UsageError("pr-create on Capy needs --head <branch> when HEAD is detached: the host's PR tool cannot infer it");
|
||||
}
|
||||
let dest = { repo: remote.segments.join("/"), host: remote.host };
|
||||
if (remote.kind === "github") {
|
||||
const view = env.run("gh", ["repo", "view", "--json", "nameWithOwner,url"]);
|
||||
try { const v = JSON.parse(view.stdout); dest = { repo: String(v.nameWithOwner ?? ""), host: new URL(String(v.url)).host }; } catch { dest = { repo: "", host: "" }; }
|
||||
if (view.status !== 0 || !dest.repo) { env.err(`gstack-post: cannot resolve the repository gh would have written to (gh repo view --json nameWithOwner,url: ${view.stderr.trim().split("\n")[0] || "no repository"}); nothing was handed off\n`); return EXIT.cliFailed; }
|
||||
}
|
||||
let line: string;
|
||||
try { line = env.hostPublish(req.op, n, parts, { ...dest, to: req.to, base: req.base, head, draft: req.draft }); }
|
||||
catch (e) { env.err(`gstack-post: could not write the hand-off for the host's PR tool: ${(e as Error).message}; nothing was handed off\n`); return EXIT.cliFailed; }
|
||||
env.out(line);
|
||||
return EXIT.posted;
|
||||
}
|
||||
return send(env, remote.kind, req, n, title, body);
|
||||
} catch (e) {
|
||||
if (!(e instanceof UsageError)) throw e;
|
||||
|
||||
Reference in new issue
Block a user