Files
copilotkit__copilotkit/.github/workflows/update-branch.yml
Martha Schumann b3db4c11b5 ci: switch to pull_request_target and handle 422 gracefully
pull_request runs in the fork context with restricted permissions, which
would block the updateBranch API call. pull_request_target runs in the
base repo with full permissions — the label trigger is safe since no
checkout of PR code happens here.

Also treat 422 responses (already up to date, nothing to merge) as
informational rather than job failures.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-17 10:49:12 -07:00

44 lines
1.3 KiB
YAML

name: Update PR branch
on:
pull_request_target:
types: [labeled]
permissions:
contents: write
pull-requests: write
jobs:
update-branch:
if: github.event.label.name == 'qa:update-branch'
runs-on: ubuntu-latest
steps:
- name: Update PR branch with base
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const pull_number = context.payload.pull_request.number;
try {
await github.rest.pulls.updateBranch({ owner, repo, pull_number });
core.info(`Updated branch for PR #${pull_number}`);
} catch (error) {
if (error.status === 422) {
core.info(`Branch already up to date or cannot be updated: ${error.message}`);
} else {
core.setFailed(`Failed to update branch: ${error.message}`);
}
} finally {
try {
await github.rest.issues.removeLabel({
owner,
repo,
issue_number: pull_number,
name: 'qa:update-branch',
});
} catch (error) {
core.warning(`Could not remove label: ${error.message}`);
}
}