Skip to content

fix(dev-lead): post Add enable-auto-merge intent for bot approvals resolve on no-changes + enable auto-merge on approval - #297

Merged
don-petry merged 6 commits into
mainfrom
fix/coderabbit-resolve-and-auto-merge
May 20, 2026
Merged

don-petry merged 6 commits into
mainfrom
fix/coderabbit-resolve-and-auto-merge

Conversation

@don-petry

@don-petry don-petry commented May 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • @coderabbitai resolve in no-changes path: notify_coderabbit_resolve was only called when the agent pushed code changes. When the agent made no changes (e.g. CodeRabbit flagged a file outside the PR diff), CodeRabbit's CHANGES_REQUESTED persisted indefinitely. Now called in both branches for fix-reviews, fix-bot-comment, and human-pr.
  • Auto-merge on approval: Added try_enable_auto_merge() called at the end of all three intent completion paths. Added a new enable-auto-merge intent emitted when any trusted bot approves — this lightweight path skips engine install (uses only the gh CLI, no LLM) and enables auto-merge if the PR's reviewDecision is APPROVED.
  • Root cause of PR ci: add required ci.yml workflow #80: CodeRabbit's CHANGES_REQUESTED on 2026-05-17 was on claude.yml, a file outside the PR diff. The fix-reviews run found no open threads to address, made no changes, and never posted @coderabbitai resolve — leaving the PR in CHANGES_REQUESTED for 3 days until unrelated activity triggered CodeRabbit to re-review.

Files changed

File Change
scripts/dev-lead-intent.sh bot-approved skip → enable-auto-merge intent
scripts/dev-lead-fix-reviews.sh Add try_enable_auto_merge(); call notify_coderabbit_resolve in no-changes branches
.github/workflows/dev-lead.yml Add enable-auto-merge step; skip pre-flight/engine install for that intent
tests/dev-lead/unit/test_intent_reviews.bats Update copilot APPROVED test; add coderabbit APPROVED test
tests/dev-lead/unit/test_intent_ci.bats Update copilot APPROVED test
tests/dev-lead/unit/test_fix_reviews.bats Add 4 new tests for no-changes resolve and auto-merge dry-run
tests/dev-lead/fixtures/events/pr_review_coderabbit_approved.json New fixture

Test plan

  • All 121 unit tests pass locally
  • CI passes
  • Verify: on next CodeRabbit CHANGES_REQUESTED + no-changes agent run, @coderabbitai resolve is posted
  • Verify: on next bot APPROVED event for a fully-approved PR, auto-merge is enabled

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Automated pull request auto-merge when approved by designated bot reviewers, streamlining code review workflows and eliminating manual merge steps to improve development velocity.
  • Chores

    • Optimized workflows to skip unnecessary pre-flight checks and dependency installation steps when auto-merge is being enabled, improving overall efficiency.

Review Change Stack

…-merge on approval

Two gaps in the PR review lifecycle:

1. notify_coderabbit_resolve was only called when the agent pushed code changes.
   When the agent ran but made no changes (e.g. CodeRabbit flagged a file outside
   the PR diff), CodeRabbit never got the resolve signal and CHANGES_REQUESTED
   persisted indefinitely. Now called in both branches for fix-reviews,
   fix-bot-comment, and human-pr.

2. PRs were never marked for auto-merge even after reaching full approval. Added
   try_enable_auto_merge() called at the end of all three intent completion paths,
   and a new enable-auto-merge intent triggered when any trusted bot approves.
   The bot-approval path skips engine install (gh CLI only, no LLM).

Root cause of PR #80 delay: CodeRabbit's CHANGES_REQUESTED on 2026-05-17 was on
claude.yml (outside the PR diff). The fix-reviews run made no changes and never
posted @coderabbitai resolve, leaving the PR in CHANGES_REQUESTED for 3 days.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 20, 2026 02:10
@coderabbitai

coderabbitai Bot commented May 20, 2026 •

Copy link
Copy Markdown

Warning

Rate limit exceeded

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

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ 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: c062fbfb-f631-4068-90f0-781a0ac231c1

📥 Commits

Reviewing files that changed from the base of the PR and between 2b04b09 and 71b1cdb.

📒 Files selected for processing (1)
  • scripts/dev-lead-fix-reviews.sh
📝 Walkthrough

Walkthrough

This PR adds an enable-auto-merge intent type to the dev-lead system that detects when trusted bots approve PRs and automatically enables squash auto-merge if the review decision is APPROVED. The feature integrates into existing workflows and review-handling intents via a new GraphQL-based eligibility check function.

Changes

Enable auto-merge on bot-approved reviews

Layer / File(s) Summary
Intent detection and routing
scripts/dev-lead-intent.sh, tests/dev-lead/fixtures/events/pr_review_coderabbit_approved.json
Updated pull_request_review routing to emit enable-auto-merge intent (with reason bot-approved) when trusted bots approve; added fixture demonstrating the APPROVED review event structure and expected intent.
Auto-merge eligibility and execution
scripts/dev-lead-fix-reviews.sh
Introduced try_enable_auto_merge(strict) helper that queries GraphQL reviewDecision, checks if auto-merge is already enabled, and invokes gh pr merge --auto --squash when eligible; respects dry-run mode and strict error propagation.
Integration with existing and new intent handlers
scripts/dev-lead-fix-reviews.sh
Updated fix-reviews, fix-bot-comment, and human-pr intents to call try_enable_auto_merge after commit/no-changes paths; added standalone enable-auto-merge intent handler that validates PR_NUMBER and runs auto-merge in strict mode.
Workflow dispatch routing and gating
.github/workflows/dev-lead-reusable.yml, .github/workflows/dev-lead.yml
Extended pre-flight and engine-install step conditions to also skip when INTENT_TYPE is enable-auto-merge (not just skip); added dedicated dispatch step for enable-auto-merge that invokes dev-lead-fix-reviews.sh without pre-flight/engine setup.
Test coverage for enable-auto-merge flow
tests/dev-lead/unit/test_fix_reviews.bats, tests/dev-lead/unit/test_intent_ci.bats, tests/dev-lead/unit/test_intent_reviews.bats
Added dry-run tests verifying try_enable_auto_merge output for multiple intent types; updated copilot/coderabbit APPROVED event routing tests to expect enable-auto-merge instead of skip.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • petry-projects/.github-private#282: Modifies the shared scripts/dev-lead-fix-reviews.sh commit and post-commit control flow that this PR's try_enable_auto_merge integration depends on.
  • petry-projects/.github-private#285: Also modifies scripts/dev-lead-fix-reviews.sh review-handling and notify_coderabbit_resolve logic that overlaps with this PR's integration of auto-merge into the same code paths.
  • petry-projects/.github-private#179: Introduced the reusable workflow's intent-to-handler dispatch structure in .github/workflows/dev-lead-reusable.yml that this PR extends with the new enable-auto-merge intent path.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title Check ✅ Passed Title check skipped as CodeRabbit has written the PR title.

✏️ 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/coderabbit-resolve-and-auto-merge

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.

@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead — human-pr (no-changes)

No changes were needed for this PR.

@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead — fix-bot-comment (no-changes)

Engine ran but made no changes.

1 similar comment
@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead — fix-bot-comment (no-changes)

Engine ran but made no changes.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR improves the dev-lead automation flow by (1) ensuring CodeRabbit can be unblocked even when the agent makes no code changes and (2) enabling GitHub auto-merge once a PR is fully approved, including a lightweight path triggered by trusted bot approvals.

Changes:

  • Always call notify_coderabbit_resolve in both “changes” and “no-changes” branches for review-fixing intents.
  • Add try_enable_auto_merge() and a new enable-auto-merge intent to enable squash auto-merge when reviewDecision is APPROVED.
  • Update/add unit tests and fixtures for the new routing and behaviors.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
scripts/dev-lead-intent.sh Routes trusted-bot APPROVED reviews to the new enable-auto-merge intent.
scripts/dev-lead-fix-reviews.sh Adds try_enable_auto_merge() and calls CodeRabbit resolve + auto-merge logic in no-change paths.
.github/workflows/dev-lead.yml Skips engine install/preflight for enable-auto-merge and adds an inline auto-merge enablement step.
tests/dev-lead/unit/test_intent_reviews.bats Updates expected intent for bot approvals; adds CodeRabbit-approved routing test.
tests/dev-lead/unit/test_intent_ci.bats Updates expected intent for copilot approval in CI intent tests.
tests/dev-lead/unit/test_fix_reviews.bats Adds dry-run tests for CodeRabbit resolve on no-changes and auto-merge attempts.
tests/dev-lead/fixtures/events/pr_review_coderabbit_approved.json Adds a fixture for CodeRabbit bot approval webhook payload.
Comments suppressed due to low confidence (1)

tests/dev-lead/unit/test_fix_reviews.bats:417

  • These auto-merge dry-run assertions are also too weak because they allow any "[dry-run]" output, which is emitted by other parts of the script. Tighten the checks to look for the specific try_enable_auto_merge message (e.g., "would enable auto-merge") so failures can’t slip through unnoticed.
@test "fix-reviews: try_enable_auto_merge dry-run output present for fix-reviews" {
  export INTENT_TYPE="fix-reviews"
  export DEV_LEAD_DRY_RUN="true"

  run bash "$FIX_REVIEWS_SCRIPT"

  [ "$status" -eq 0 ]
  [[ "$output" == *"auto-merge"* || "$output" == *"[dry-run]"* ]]
}

@test "fix-reviews: try_enable_auto_merge dry-run output present for fix-bot-comment" {
  export INTENT_TYPE="fix-bot-comment"
  export DEV_LEAD_DRY_RUN="true"
  export COMMENT_BODY="SonarQube found issues"

  run bash "$FIX_REVIEWS_SCRIPT"

  [ "$status" -eq 0 ]
  [[ "$output" == *"auto-merge"* || "$output" == *"[dry-run]"* ]]
}

@test "fix-reviews: try_enable_auto_merge dry-run output present for human-pr" {
  export INTENT_TYPE="human-pr"
  export DEV_LEAD_DRY_RUN="true"
  export PR_TITLE="Test PR"
  export PR_DESCRIPTION="A test pull request"

  run bash "$FIX_REVIEWS_SCRIPT"

  [ "$status" -eq 0 ]
  [[ "$output" == *"auto-merge"* || "$output" == *"[dry-run]"* ]]
}

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

Comment thread .github/workflows/dev-lead.yml Resolved
Comment thread .github/workflows/dev-lead.yml Resolved
Comment thread scripts/dev-lead-intent.sh Resolved

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request implements automatic auto-merge (squash) functionality for pull requests. Key changes include the addition of a try_enable_auto_merge function in dev-lead-fix-reviews.sh that utilizes the GitHub CLI to enable auto-merge on approved PRs, and updates to dev-lead-intent.sh to emit an enable-auto-merge intent when trusted bots approve a PR. The PR also ensures notify_coderabbit_resolve is called in no-change scenarios and adds corresponding unit tests and fixtures. I have no feedback to provide.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8e4b5f8395

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread .github/workflows/dev-lead.yml Resolved
Comment thread scripts/dev-lead-fix-reviews.sh Resolved
Comment thread .github/workflows/dev-lead.yml Resolved
Comment thread .github/workflows/dev-lead.yml Resolved
coderabbitai[bot]
coderabbitai Bot previously approved these changes May 20, 2026
@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead — fix-reviews (applied)

Changes committed and pushed.

coderabbitai[bot]
coderabbitai Bot previously approved these changes May 20, 2026
@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead — human-pr (applied)

Changes committed and pushed.

@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead — fix-bot-comment (no-changes)

Engine ran but made no changes.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 48d1c58e72

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/dev-lead-intent.sh Resolved
coderabbitai[bot]
coderabbitai Bot previously approved these changes May 20, 2026
@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead — fix-reviews (applied)

Changes committed and pushed.

@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead — human-pr (no-changes)

No changes were needed for this PR.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 955e4f811a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/dev-lead-fix-reviews.sh Resolved
@coderabbitai coderabbitai Bot changed the title fix(dev-lead): post @coderabbitai resolve on no-changes + enable auto-merge on approval fix(dev-lead): post Add enable-auto-merge intent for bot approvals resolve on no-changes + enable auto-merge on approval May 20, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/dev-lead-reusable.yml:
- Around line 247-257: The workflow step "Enable auto-merge on bot approval" was
added directly to the workflow instead of using the approved template; revert
this direct step and implement the change inside the canonical template under
standards/workflows/ so the workflow remains verbatim. Specifically, remove the
added step that uses env.INTENT_TYPE checks, PR_NUMBER/HEAD_SHA envs and the run
of .dev-lead/scripts/dev-lead-fix-reviews.sh from this file, then add or update
the corresponding template file in standards/workflows/ to include that behavior
(or reference an existing template) so the repository workflow pulls from the
template verbatim; ensure the step name "Enable auto-merge on bot approval" and
the script invocation remain in the template rather than in this workflow file.

In @.github/workflows/dev-lead.yml:
- Around line 224-235: The workflow file was modified directly (the "Enable
auto-merge on bot approval" job and its env vars like INTENT_TYPE, PR_NUMBER,
HEAD_SHA and the run step invoking scripts/dev-lead-fix-reviews.sh) which
violates the rule that workflows must be sourced verbatim from
standards/workflows/; revert this direct change and instead apply the same
change to the canonical template in standards/workflows/ (or update the
template-import mechanism used by your CI) so the workflow file is regenerated
from that template, ensuring the job "Enable auto-merge on bot approval" and its
environment variables and run step are defined only in the canonical template
rather than edited in-place.

In `@scripts/dev-lead-fix-reviews.sh`:
- Around line 156-162: Replace the Bash-only array merge_args with a POSIX-safe
positional-parameter assembly: use set -- --auto --squash to initialise the
arguments, conditionally append the head match with [ -n "${HEAD_SHA:-}" ] &&
set -- "$@" --match-head-commit "$HEAD_SHA", then call gh pr merge "$PR_NUMBER"
--repo "$REPO" "$@" (and keep the strict branch and fallback warning logic
intact); update references to merge_args, HEAD_SHA, PR_NUMBER, REPO and the gh
pr merge invocation accordingly so the script works in POSIX sh.
🪄 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: f32c1f46-ee0e-4b03-81d7-5dc6a166dc53

📥 Commits

Reviewing files that changed from the base of the PR and between 5ddcd76 and 2b04b09.

📒 Files selected for processing (8)
  • .github/workflows/dev-lead-reusable.yml
  • .github/workflows/dev-lead.yml
  • scripts/dev-lead-fix-reviews.sh
  • scripts/dev-lead-intent.sh
  • tests/dev-lead/fixtures/events/pr_review_coderabbit_approved.json
  • tests/dev-lead/unit/test_fix_reviews.bats
  • tests/dev-lead/unit/test_intent_ci.bats
  • tests/dev-lead/unit/test_intent_reviews.bats

Comment thread .github/workflows/dev-lead-reusable.yml Resolved
Comment thread .github/workflows/dev-lead.yml Resolved
Comment thread scripts/dev-lead-fix-reviews.sh Resolved
…rge args

Two fixes in try_enable_auto_merge:

1. HEAD_SHA refresh: commit_and_push may create a new commit after HEAD_SHA
   is resolved at script startup. Without refreshing, --match-head-commit
   uses a stale SHA and the gh pr merge call fails silently (downgraded to
   a warning in non-strict mode), so auto-merge never activates on the
   "applied changes" path. Fix: git rev-parse HEAD at function entry.

2. POSIX-safe merge args: replaced bash-only array (merge_args+= syntax)
   with positional-parameter assembly via set -- so the merge call works
   in any POSIX-compatible shell.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@don-petry

Copy link
Copy Markdown
Collaborator Author

Addressing CodeRabbit's review comments:

Fixed (2 legitimate issues):

  • Stale HEAD_SHA: added git rev-parse HEAD refresh at the start of try_enable_auto_merge so --match-head-commit always uses the post-push SHA, not the pre-run value.
  • POSIX-safe merge args: replaced the bash-only merge_args+=() array with set -- --auto --squash / set -- "$@" --match-head-commit "$HEAD_SHA" positional-parameter assembly.

Resolved as false positives (2 template-rule threads):
The threads on dev-lead.yml and dev-lead-reusable.yml flag a template rule that applies only to externally-managed workflows (like dependabot-automerge.yml, which carries a # SOURCE OF TRUTH: header pointing to petry-projects/.github). Neither dev-lead.yml nor dev-lead-reusable.yml carries that header — they are native to this repo and are edited in place, exactly as every prior PR on this repo has done. No template update is needed.

@sonarqubecloud

Copy link
Copy Markdown

@don-petry
don-petry merged commit 9ee0f4e into main May 20, 2026
16 checks passed
@don-petry
don-petry deleted the fix/coderabbit-resolve-and-auto-merge branch May 20, 2026 03:02
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.

3 participants