chore: support updating gitea pr bodies

This commit is contained in:
Nico 2026-05-31 02:24:12 -07:00
parent 9a0a0a2715
commit 68265c898e
3 changed files with 38 additions and 0 deletions

View File

@ -46,6 +46,11 @@ npm run pr:create -- --base <base> --title "<title>" --body-file <body-file>
```
The helper checks for an existing open PR with the same base/head and returns it instead of creating a duplicate.
If the PR body needs to be changed after creation, update it from a body file:
```powershell
npm run pr:update -- --number <pr-number> --body-file <body-file>
```
For stacked work, pass the parent PR branch as `<base>`. For standalone work, pass `main`.

View File

@ -22,6 +22,7 @@
"pr:auth": "node scripts/gitea-pr.js auth-check",
"pr:create": "node scripts/gitea-pr.js create",
"pr:view": "node scripts/gitea-pr.js view",
"pr:update": "node scripts/gitea-pr.js update",
"pr:merge": "node scripts/gitea-pr.js merge",
"test": "jest --runInBand",
"test:e2e": "npm --prefix frontend run test:e2e --",

View File

@ -63,12 +63,16 @@ Commands:
view --number <pr-number>
Print basic PR status.
update --number <pr-number> [--title <title>] [--body-file <path> | --body <text>]
Update a PR title/body. Prefer --body-file for multi-line PR bodies.
merge --number <pr-number> --yes [--method merge|squash|rebase] [--delete-branch]
Merge a PR. The --yes flag is required to avoid accidental merges.
Examples:
npm run pr:auth
npm run pr:create -- --base feature-custom-store-locations --title "Allow household switcher reordering" --body-file pr-body.md
npm run pr:update -- --number 12 --body-file pr-body.md
npm run pr:view -- --number 12
npm run pr:merge -- --number 12 --method merge --delete-branch --yes
`);
@ -286,6 +290,31 @@ async function viewPull(flags) {
);
}
async function updatePull(flags) {
const number = requiredFlag(flags, "number");
const payload = {};
if (flags.title && flags.title !== true) {
payload.title = flags.title;
}
if (flags["body-file"] || typeof flags.body === "string") {
payload.body = readBody(flags);
}
if (Object.keys(payload).length === 0) {
fail("Nothing to update; pass --title, --body, or --body-file");
}
const pull = await apiRequest(
"PATCH",
repoRoute(`/pulls/${encodeURIComponent(number)}`),
payload
);
console.log(`Updated PR #${pull.number}: ${pull.html_url || pull.url}`);
}
async function mergePull(flags) {
const number = requiredFlag(flags, "number");
if (!flags.yes) {
@ -334,6 +363,9 @@ async function main() {
case "view":
await viewPull(flags);
break;
case "update":
await updatePull(flags);
break;
case "merge":
await mergePull(flags);
break;