AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(dx): batch bot — push rollup objects instead of refs-API update, fix add-then-list race (#13536)
Nicholas Tindle5ad8981e3b2f
diff --git a/.github/batch-bot/batch.mjs b/.github/batch-bot/batch.mjsindex 2be00db8ff..c57cfce888 100644--- a/.github/batch-bot/batch.mjs+++ b/.github/batch-bot/batch.mjs@@ -137,17 +137,13 @@ function buildRollup(list) {);}- // Force-update the ephemeral, bot-owned rollup branch via the refs API. This is- // a non-ff update of a throwaway branch nobody builds on — protect it in branch- // settings so only the bot can push to it (see README).- const sha = git(["rev-parse", "HEAD"]);- const ref = `refs/heads/${ROLLUP}`;- const exists = tryGh(["api", `repos/${REPO}/git/${ref}`]).ok;- if (exists) {- gh(["api", "-X", "PATCH", `repos/${REPO}/git/${ref}`, "-f", `sha=${sha}`, "-F", "force=true"]);- } else {- gh(["api", "-X", "POST", `repos/${REPO}/git/refs`, "-f", `ref=${ref}`, "-f", `sha=${sha}`]);- }+ // Force-push the ephemeral, bot-owned rollup branch. The refs API cannot be+ // used here: the merge commits exist only in this runner's clone, and the+ // API refuses to point a ref at objects the server has never received+ // (422 "Object does not exist"). The push uploads the objects and creates+ // or force-moves the branch in one step, authenticated as the bot via the+ // checkout token — keep batch/rollup protected to bot-only pushes (README).+ git(["push", "--force", "origin", `HEAD:refs/heads/${ROLLUP}`]);return { merged, ejected };}@@ -229,8 +225,19 @@ function assertBatchable(pr) {return p;}-function rebuildAndReport(actionNote) {- const { merged, ejected } = buildRollup(members());+function rebuildAndReport(actionNote, ensureNumber = null) {+ // GitHub's label index lags behind `pr edit --add-label`, so the very first+ // /batch on a PR can list an empty batch and build nothing. When the caller+ // just labeled a PR, fetch it directly and union it into the member list.+ let list = members();+ if (ensureNumber && !list.some((p) => p.number === ensureNumber)) {+ const row = ghJSON([+ "pr", "view", String(ensureNumber), "--repo", REPO,+ "--json", "number,title,headRefName,headRefOid,url,labels,reviewDecision,mergeable,isDraft",+ ]);+ if (!row.labels.some((l) => l.name === NEVER)) list.push(row);+ }+ const { merged, ejected } = buildRollup(list);const pr = upsertRollupPR(merged, ejected);if (pr) deployRollup(pr); // (re)deploy the combined preview to reflect the new batchif (prNumber) {@@ -250,7 +257,7 @@ function cmdBatch() {if (!prNumber) throw new Error("no PR number");assertBatchable(prNumber);gh(["pr", "edit", String(prNumber), "--repo", REPO, "--add-label", LABEL]);- rebuildAndReport(`Added #${prNumber} to the batch.`);+ rebuildAndReport(`Added #${prNumber} to the batch.`, prNumber);}function cmdBatchRemove() {