From fcfd94c0094ed3339a3d5348a278b9a5a63e3c80 Mon Sep 17 00:00:00 2001 From: JounQin Date: Thu, 5 Nov 2026 07:11:20 +0000 Subject: [PATCH 1/3] feat: add pr update-branch action --- .changeset/catalog-update-branch.md | 7 +++++++ README.md | 1 + packages/core/src/actions.ts | 13 +++++++++++++ test/unit/actions.test.ts | 16 ++++++++++++++++ 4 files changed, 37 insertions(+) create mode 100644 .changeset/catalog-update-branch.md diff --git a/.changeset/catalog-update-branch.md b/.changeset/catalog-update-branch.md new file mode 100644 index 00000000..30989543 --- /dev/null +++ b/.changeset/catalog-update-branch.md @@ -0,0 +1,7 @@ +--- +'gcb-core': minor +--- + +Add `pr:update-branch` to the action catalog. It takes an optional `--rebase`, uses +`pull_requests: write` and `contents: write`, and sets `appUser`, so bare `--as-user` works through +the app broker. diff --git a/README.md b/README.md index 0075d67d..bea840b6 100644 --- a/README.md +++ b/README.md @@ -770,6 +770,7 @@ actions. Grant them on the App, then approve any changed permissions on each ins | `pr ready` | `pull_requests: write` | | `pr lock` | `pull_requests: write` | | `pr unlock` | `pull_requests: write` | +| `pr update-branch` | `pull_requests: write`, `contents: write` | | `pr checks` | `pull_requests: read`, `checks: read`, `statuses: read` | | `pr status` | `pull_requests: read`, `checks: read`, `statuses: read` | | `pr comment` | `pull_requests: write` | diff --git a/packages/core/src/actions.ts b/packages/core/src/actions.ts index 1f92ea78..c777ea9e 100644 --- a/packages/core/src/actions.ts +++ b/packages/core/src/actions.ts @@ -209,6 +209,18 @@ const PR_READY: GhAction = { timeoutSeconds: 60, }; +// GitHub GraphQL: +// https://docs.github.com/en/graphql/reference/pulls#mutation-updatepullrequestbranch +const PR_UPDATE_BRANCH: GhAction = { + name: 'pr:update-branch', + command: ['pr', 'update-branch'], + positionals: [{ name: 'number', type: 'number', required: true }], + flags: [{ name: 'rebase', type: 'boolean' }], + permissions: { pull_requests: 'write', contents: 'write' }, + timeoutSeconds: 120, + appUser: true, +}; + // GitHub GraphQL: // https://docs.github.com/en/graphql/reference/issues#mutation-locklockable // https://docs.github.com/en/graphql/reference/issues#mutation-unlocklockable @@ -525,6 +537,7 @@ export const GH_ACTIONS: Readonly> = Object.freeze({ 'pr:ready': PR_READY, 'pr:lock': PR_LOCK, 'pr:unlock': PR_UNLOCK, + 'pr:update-branch': PR_UPDATE_BRANCH, 'pr:checks': PR_CHECKS, 'pr:status': PR_STATUS, 'pr:comment': PR_COMMENT, diff --git a/test/unit/actions.test.ts b/test/unit/actions.test.ts index c2e69102..30469b55 100644 --- a/test/unit/actions.test.ts +++ b/test/unit/actions.test.ts @@ -23,6 +23,7 @@ describe('gh action catalog', () => { 'pr:ready', 'pr:lock', 'pr:unlock', + 'pr:update-branch', 'pr:checks', 'pr:status', 'pr:comment', @@ -94,15 +95,21 @@ describe('gh action catalog', () => { assert.equal(getGhAction('pr:ready').appUser, undefined); assert.equal(getGhAction('pr:lock').appUser, undefined); assert.equal(getGhAction('pr:unlock').appUser, undefined); + assert.equal(getGhAction('pr:update-branch').appUser, true); assert.deepEqual(getGhAction('pr:ready').permissions, { pull_requests: 'write' }); assert.deepEqual(getGhAction('pr:lock').permissions, { pull_requests: 'write' }); assert.deepEqual(getGhAction('pr:unlock').permissions, { pull_requests: 'write' }); + assert.deepEqual(getGhAction('pr:update-branch').permissions, { + pull_requests: 'write', + contents: 'write', + }); assert.deepEqual(getGhAction('run:cancel').permissions, { actions: 'write' }); assert.deepEqual(getGhAction('run:rerun').permissions, { actions: 'write' }); for (const [name, seconds] of [ ['pr:ready', 60], ['pr:lock', 60], ['pr:unlock', 60], + ['pr:update-branch', 120], ['run:cancel', 60], ['run:rerun', 120], ] as const) { @@ -270,6 +277,15 @@ describe('buildGhArgv', () => { ]); assert.throws(() => buildGhArgv('pr:lock', {}, 'acme/widget'), /needs number/u); assert.throws(() => buildGhArgv('pr:unlock', {}, 'acme/widget'), /needs number/u); + assert.deepEqual(buildGhArgv('pr:update-branch', { number: 7, rebase: true }, 'acme/widget'), [ + 'pr', + 'update-branch', + '7', + '--rebase', + '--repo', + 'acme/widget', + ]); + assert.throws(() => buildGhArgv('pr:update-branch', {}, 'acme/widget'), /needs number/u); assert.deepEqual(buildGhArgv('run:cancel', { runId: 42, force: true }, 'acme/widget'), [ 'run', 'cancel', From d2b3ac716143d5c45e1f5f3bbbfdc26fd665820f Mon Sep 17 00:00:00 2001 From: JounQin Date: Thu, 5 Nov 2026 07:23:59 +0000 Subject: [PATCH 2/3] docs: explain update-branch identity and fork scope --- .changeset/catalog-update-branch.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.changeset/catalog-update-branch.md b/.changeset/catalog-update-branch.md index 30989543..58748ef6 100644 --- a/.changeset/catalog-update-branch.md +++ b/.changeset/catalog-update-branch.md @@ -4,4 +4,7 @@ Add `pr:update-branch` to the action catalog. It takes an optional `--rebase`, uses `pull_requests: write` and `contents: write`, and sets `appUser`, so bare `--as-user` works through -the app broker. +the app broker. `appUser` follows `pr:edit`: updating a branch is an author operation, while +close/reopen/ready/lock stay host-account only. For a PR whose head is a fork, the app installation +token is scoped to the base repository and cannot write the head fork; use `--as-user ` for +that case. From aecbb3ae6317dee3fba13f15438a16886a4239af Mon Sep 17 00:00:00 2001 From: JounQin Date: Thu, 5 Nov 2026 07:34:33 +0000 Subject: [PATCH 3/3] docs: state the update-branch token requirement --- .changeset/catalog-update-branch.md | 8 +++++--- README.md | 5 +++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.changeset/catalog-update-branch.md b/.changeset/catalog-update-branch.md index 58748ef6..ce0106e9 100644 --- a/.changeset/catalog-update-branch.md +++ b/.changeset/catalog-update-branch.md @@ -5,6 +5,8 @@ Add `pr:update-branch` to the action catalog. It takes an optional `--rebase`, uses `pull_requests: write` and `contents: write`, and sets `appUser`, so bare `--as-user` works through the app broker. `appUser` follows `pr:edit`: updating a branch is an author operation, while -close/reopen/ready/lock stay host-account only. For a PR whose head is a fork, the app installation -token is scoped to the base repository and cannot write the head fork; use `--as-user ` for -that case. +close/reopen/ready/lock stay host-account only. Bare `--as-user` needs a user token with +`contents: write`; the recommended `Contents: Read` token is enough for PR editing but not for +updating a branch. The default app route and `--as-user ` do not depend on that token. For a +PR whose head is a fork, the app installation token is scoped to the base repository and cannot +write the head fork; use `--as-user ` for that case. diff --git a/README.md b/README.md index bea840b6..291f3b90 100644 --- a/README.md +++ b/README.md @@ -492,8 +492,9 @@ than promised here. `userTokens` is consulted for opening, replying, editing or and for an issue creation or resolve when no `user.refresh` exists. Resolving a review thread needs **Contents: Read and write** (`resolveReviewThread` is refused without it), which would also let that token push and merge; if that trade is not acceptable, resolve through `authorize`, whose token is the person's own. -`user.refresh` wins over `userTokens` when it exists. A plain `gcb pr` stays on the app's -installation token. Dropping the field does not change the default; it only makes bare `--as-user` +`pr:update-branch --as-user` also needs **Contents: Read and write** for the same reason; without it, +use the default app route or `--as-user `. `user.refresh` wins over `userTokens` when it +exists. A plain `gcb pr` stays on the app's installation token. Dropping the field does not change the default; it only makes bare `--as-user` fail with `no authorized user token`. #### Authorizing as a person instead