Skip to content

fix(dependabot-rebase): fall back to @dependabot rebase when update-branch is blocked by workflows permission#143

Merged
don-petry merged 2 commits intomainfrom
fix/dependabot-rebase-workflows-403
Apr 17, 2026
Merged

fix(dependabot-rebase): fall back to @dependabot rebase when update-branch is blocked by workflows permission#143
don-petry merged 2 commits intomainfrom
fix/dependabot-rebase-workflows-403

Conversation

@don-petry
Copy link
Copy Markdown
Contributor

@don-petry don-petry commented Apr 16, 2026

Problem

GitHub blocks the `update-branch` API when the merge would introduce `.github/workflows/` changes into the PR branch. This restriction applies to all tokens — both `GITHUB_TOKEN` and GitHub App tokens require the explicit GitHub App `workflows` permission for this operation. The `dependabot-automerge-petry` app does not have this permission.

Result: PRs #125 and #129 have been stuck BEHIND for days, because every push to `main` (our recent fixes) advances the workflow files, and `update-branch` always fails with:

```
gh: refusing to allow a GitHub App to create or update workflow
`.github/workflows/feature-ideation-reusable.yml`
without `workflows` permission (HTTP 403)
```

Fix

When `update-branch` fails with a `workflows` permission error, fall back to posting a `@dependabot rebase` comment on the PR. Dependabot always has permission to push to its own branches including workflow files. After Dependabot rebases:

  1. `pull_request_target` fires with `synchronize` action
  2. `dependabot-automerge` re-approves and re-enables auto-merge
  3. Next push to `main` triggers this workflow, which merges the now-current PR

Flow

Before (stuck):
```
PR behind → update-branch → HTTP 403 → warning → stuck forever
```

After (fallback chain):
```
PR behind → update-branch → 403 → @dependabot rebase comment
→ Dependabot rebases → automerge workflow approves
→ next push → rebase workflow merges → ✓
```

Why not add workflows permission to the app?

That requires a GitHub UI change and all installation approvals. The fallback is equally effective and works without admin action.

Also fixed

Removed dead-code `else/fi` block left over from an earlier refactor that would have printed a wrong "Warning: failed to update" message when PRs were NOT behind.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Enhanced Dependabot pull request automation with improved error handling and permission-aware fallback logic for more reliable automated branch updates.

…ranch blocked

GitHub blocks the update-branch API when the merge would introduce
.github/workflows/ changes, regardless of which token is used — the
token must have the GitHub App 'workflows' permission, which neither
GITHUB_TOKEN nor the dependabot-automerge-petry app has.

Fallback: when update-branch fails with a 'workflows permission' error,
post '@dependabot rebase' as a PR comment. Dependabot always has permission
to push to its own branches including workflow files. After Dependabot
rebases, the dependabot-automerge workflow (pull_request_target/synchronize)
re-approves the PR and the serialization chain continues.

Also fix dead-code else/fi left over from earlier refactor.
Copilot AI review requested due to automatic review settings April 16, 2026 18:12
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 16, 2026

Warning

Rate limit exceeded

@don-petry has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 58 minutes and 56 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 58 minutes and 56 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: e2f8466c-b693-4ee4-8b2e-35cb30eed85e

📥 Commits

Reviewing files that changed from the base of the PR and between 9ef30a5 and f65f095.

📒 Files selected for processing (1)
  • .github/workflows/dependabot-rebase-reusable.yml
📝 Walkthrough

Walkthrough

This change modifies the Dependabot rebase reusable workflow to capture GitHub API command output and exit status, detect permission-related failures, and implement a fallback mechanism that posts @dependabot rebase when update-branch API calls lack required permissions.

Changes

Cohort / File(s) Summary
Dependabot Rebase Workflow
.github/workflows/dependabot-rebase-reusable.yml
Refactored error handling to capture gh api output and exit status, detect permission errors via grep, and post @dependabot rebase comment as fallback when update-branch API lacks permissions. Prints output before proceeding with auto-merge logic.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: implementing a fallback to @dependabot rebase when the update-branch API is blocked by workflows permission restrictions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/dependabot-rebase-workflows-403

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the org’s reusable Dependabot rebase/merge workflow to avoid getting stuck when GitHub blocks the update-branch API due to .github/workflows/ changes requiring workflows permission.

Changes:

  • Capture update-branch output/exit status and branch-update failure details.
  • On a detected “workflows permission” failure, fall back to posting an @dependabot rebase PR comment.
  • Remove a dead else/fi block that could emit an incorrect warning when PRs were not behind.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .github/workflows/dependabot-rebase-reusable.yml Outdated
Comment thread .github/workflows/dependabot-rebase-reusable.yml Outdated
Comment thread .github/workflows/dependabot-rebase-reusable.yml Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.github/workflows/dependabot-rebase-reusable.yml:
- Around line 94-97: The current assignment captures UPDATE_OUTPUT with gh api
and only afterward reads UPDATE_EXIT, but under bash -e the failing gh api will
terminate the step before UPDATE_EXIT is set; change the pattern to run the
command inside an if to prevent immediate exit: invoke gh api
"repos/$REPO/pulls/$PR_NUMBER/update-branch" -X PUT -f update_method=merge
inside an if ! ...; then set UPDATE_OUTPUT and UPDATE_EXIT from that block
(referencing UPDATE_OUTPUT, UPDATE_EXIT, and the gh api call) so you can handle
the non-zero exit (403) path and run the fallback that posts "@dependabot
rebase".
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 950473cc-826f-4316-93e3-c22eca311905

📥 Commits

Reviewing files that changed from the base of the PR and between 6810a7f and 9ef30a5.

📒 Files selected for processing (1)
  • .github/workflows/dependabot-rebase-reusable.yml

Comment thread .github/workflows/dependabot-rebase-reusable.yml Outdated
@don-petry
Copy link
Copy Markdown
Contributor Author

Review — fix requested (cycle 1/3)

The automated review identified the following issues. Please address each one:

Findings to fix

  • [major] .github/workflows/dependabot-rebase-reusable.yml:94 — With GitHub Actions' default bash -e -o pipefail shell, a failing gh api call (e.g. HTTP 403) causes the assignment UPDATE_OUTPUT=$(gh api ...) to exit immediately — UPDATE_EXIT=$? is never reached and the @dependabot rebase fallback never fires. The fix is to wrap the call so set -e is suppressed: UPDATE_OUTPUT=$(gh api ... 2>&1) || UPDATE_EXIT=$? or use if ! UPDATE_OUTPUT=$(gh api ... 2>&1); then ... fi.
  • [minor] CodeRabbit submitted CHANGES_REQUESTED citing the same bash set -e bug. This review is unresolved and the PR mergeStateStatus is BLOCKED.

Additional tasks

  1. Resolve all unresolved review thread comments from other reviewers
  2. Ensure all CI checks pass after your changes
  3. Rebase on main if the branch is behind
  4. Do NOT modify files unrelated to the findings above

The review cascade will automatically re-review after new commits are pushed.

…back

- Fix critical bash -e bug: use 'if UPDATE_OUTPUT=$(cmd)' pattern instead
  of capturing output then checking $?, which never runs under set -e
- Narrow grep to exact string 'without `workflows` permission' to avoid
  false-positives from other permission errors
- Add error handling for the @dependabot rebase comment posting
- Make fallback idempotent: check for existing @dependabot rebase comment
  before posting to avoid spamming PRs on every push-to-main trigger
@sonarqubecloud
Copy link
Copy Markdown

@don-petry don-petry merged commit 3c6335c into main Apr 17, 2026
19 checks passed
@don-petry don-petry deleted the fix/dependabot-rebase-workflows-403 branch April 17, 2026 02:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants