Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions .github/workflows/dev-lead-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
echo "::notice::Skipping event: $INTENT_REASON"

- name: Pre-flight checks
if: env.INTENT_TYPE != 'skip'
if: env.INTENT_TYPE != 'skip' && env.INTENT_TYPE != 'enable-auto-merge'
env:
CLAUDE_CODE_OAUTH_TOKEN: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
GH_PAT_WORKFLOWS: ${{ secrets.GH_PAT_WORKFLOWS }}
Expand All @@ -111,14 +111,14 @@ jobs:

# ── Install engine CLIs ───────────────────────────────────────────────
- name: Cache claude-code CLI
if: env.INTENT_TYPE != 'skip'
if: env.INTENT_TYPE != 'skip' && env.INTENT_TYPE != 'enable-auto-merge'
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
with:
path: ~/.npm-global
key: claude-code-${{ vars.CLAUDE_CODE_VERSION || 'latest' }}-${{ runner.os }}

- name: Install engine CLIs
if: env.INTENT_TYPE != 'skip'
if: env.INTENT_TYPE != 'skip' && env.INTENT_TYPE != 'enable-auto-merge'
env:
CLAUDE_CODE_VERSION: ${{ vars.CLAUDE_CODE_VERSION || 'latest' }}
run: |
Expand Down Expand Up @@ -244,6 +244,17 @@ jobs:
PROMPTS_DIR: .dev-lead/prompts/dev-lead
run: bash .dev-lead/scripts/dev-lead-fix-reviews.sh

# ── enable-auto-merge ─────────────────────────────────────────────────
# Triggered when a trusted bot approves a PR. Skips engine install and
# pre-flight — just checks reviewDecision and enables auto-merge if APPROVED.
- name: Enable auto-merge on bot approval
if: env.INTENT_TYPE == 'enable-auto-merge'
env:
PR_NUMBER: ${{ env.INTENT_PR_NUMBER }}
HEAD_SHA: ${{ env.INTENT_HEAD_SHA }}
REPO: ${{ github.repository }}
run: bash .dev-lead/scripts/dev-lead-fix-reviews.sh

Comment thread
don-petry marked this conversation as resolved.
Resolved
# ── ci-relay ──────────────────────────────────────────────────────────────────
# Handles check_run completed failure events. No LLM — resolves PR number and
# fires repository_dispatch dev-lead-ci-failure back to the calling repo.
Expand Down
20 changes: 16 additions & 4 deletions .github/workflows/dev-lead.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,25 +102,25 @@ jobs:
echo "::notice::Skipping event: $INTENT_REASON"

- name: Pre-flight checks
if: env.INTENT_TYPE != 'skip'
if: env.INTENT_TYPE != 'skip' && env.INTENT_TYPE != 'enable-auto-merge'
run: bash scripts/dev-lead-preflight.sh

- name: Configure git identity
if: env.INTENT_TYPE != 'skip'
if: env.INTENT_TYPE != 'skip' && env.INTENT_TYPE != 'enable-auto-merge'
run: |
git config --global user.email "donpetry-bot@users.noreply.github.com"
git config --global user.name "donpetry-bot"

# ── Install engine CLIs ───────────────────────────────────────────────
- name: Cache claude-code CLI
if: env.INTENT_TYPE != 'skip'
if: env.INTENT_TYPE != 'skip' && env.INTENT_TYPE != 'enable-auto-merge'
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
with:
path: ~/.npm-global
key: claude-code-${{ vars.CLAUDE_CODE_VERSION || 'latest' }}-${{ runner.os }}

- name: Install engine CLIs
if: env.INTENT_TYPE != 'skip'
if: env.INTENT_TYPE != 'skip' && env.INTENT_TYPE != 'enable-auto-merge'
env:
CLAUDE_CODE_VERSION: ${{ vars.CLAUDE_CODE_VERSION || 'latest' }}
# Pass keys during install if needed for extension setup
Expand Down Expand Up @@ -221,6 +221,18 @@ jobs:
REVIEW_ENGINE: ${{ env.DEV_LEAD_ENGINE }}
run: bash scripts/dev-lead-fix-reviews.sh

# ── enable-auto-merge ─────────────────────────────────────────────────
# Triggered when a trusted bot approves a PR. Skips engine install and
# pre-flight — just checks reviewDecision and enables auto-merge if APPROVED.
- name: Enable auto-merge on bot approval
if: env.INTENT_TYPE == 'enable-auto-merge'
env:
INTENT_TYPE: enable-auto-merge
PR_NUMBER: ${{ env.INTENT_PR_NUMBER }}
HEAD_SHA: ${{ env.INTENT_HEAD_SHA }}
REPO: ${{ github.repository }}
run: bash scripts/dev-lead-fix-reviews.sh

Comment thread
don-petry marked this conversation as resolved.
Resolved
Comment thread
don-petry marked this conversation as resolved.
Resolved
# ── ci-relay ────────────────────────────────────────────────────────────────
# Handles check_run completed events only.
# No LLM involved — resolves the PR number from the check and fires
Expand Down
79 changes: 79 additions & 0 deletions scripts/dev-lead-fix-reviews.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,72 @@ notify_coderabbit_resolve() {
fi
}

# try_enable_auto_merge: enables auto-merge (squash) on the PR if reviewDecision is
# APPROVED and auto-merge is not already set. Safe to call speculatively — checks
# eligibility first and is idempotent if auto-merge is already on.
# Pass "true" as first arg for strict mode: API errors propagate and a merge failure
# exits non-zero rather than emitting a warning (use for the enable-auto-merge intent).
try_enable_auto_merge() {
local strict="${1:-false}"
if [ "${DEV_LEAD_DRY_RUN:-false}" = "true" ]; then
echo "[dry-run] would enable auto-merge if PR #${PR_NUMBER} is APPROVED"
return 0
fi
# Refresh HEAD_SHA to the commit that is now the PR head. commit_and_push may
# have created a new commit after HEAD_SHA was resolved at script startup, so
# --match-head-commit would fail with the stale value.
local current_head
current_head=$(git rev-parse HEAD 2>/dev/null || true)
[ -n "$current_head" ] && HEAD_SHA="$current_head"

local auto_merge_state review_decision

if [ "$strict" = "true" ]; then
auto_merge_state=$(gh api "repos/${REPO}/pulls/${PR_NUMBER}" --jq '.auto_merge // empty')
if [ -n "$auto_merge_state" ]; then
echo "::notice::PR #${PR_NUMBER} auto-merge already enabled"
return 0
fi
review_decision=$(gh api graphql -f query='
query($owner:String!,$repo:String!,$pr:Int!){
repository(owner:$owner,name:$repo){
pullRequest(number:$pr){reviewDecision}
}
}' \
-F owner="${REPO%%/*}" -F repo="${REPO##*/}" -F pr="$PR_NUMBER" \
--jq '.data.repository.pullRequest.reviewDecision')
else
auto_merge_state=$(gh api "repos/${REPO}/pulls/${PR_NUMBER}" \
--jq '.auto_merge // empty' 2>/dev/null || true)
if [ -n "$auto_merge_state" ]; then
echo "::notice::PR #${PR_NUMBER} auto-merge already enabled"
return 0
fi
review_decision=$(gh api graphql -f query='
query($owner:String!,$repo:String!,$pr:Int!){
repository(owner:$owner,name:$repo){
pullRequest(number:$pr){reviewDecision}
}
}' \
-F owner="${REPO%%/*}" -F repo="${REPO##*/}" -F pr="$PR_NUMBER" \
--jq '.data.repository.pullRequest.reviewDecision' 2>/dev/null || true)
fi

if [ "${review_decision:-}" = "APPROVED" ]; then
echo "::notice::PR #${PR_NUMBER} is APPROVED — enabling auto-merge (squash)"
set -- --auto --squash
[ -n "${HEAD_SHA:-}" ] && set -- "$@" --match-head-commit "$HEAD_SHA"
if [ "$strict" = "true" ]; then
gh pr merge "$PR_NUMBER" --repo "$REPO" "$@"
else
gh pr merge "$PR_NUMBER" --repo "$REPO" "$@" 2>/dev/null || \
echo "::warning::auto-merge could not be enabled on PR #${PR_NUMBER} — check repository settings and token permissions"
fi
else
echo "::notice::PR #${PR_NUMBER} reviewDecision=${review_decision:-unknown} — not yet eligible for auto-merge"
fi
}

# commit_and_push: stages any uncommitted changes (including untracked files),
# commits if needed, and pushes. Returns 0 if changes were pushed, 1 if nothing to push.
# Handles two cases:
Expand Down Expand Up @@ -303,8 +369,10 @@ case "$INTENT_TYPE" in
notify_coderabbit_resolve
post_reviews_terminal "fix-reviews" "applied" "Changes committed and pushed."
else
notify_coderabbit_resolve
post_reviews_terminal "fix-reviews" "no-changes" "No changes were needed for the open review threads."
fi
try_enable_auto_merge
fi
exit "$rc"
;;
Expand All @@ -319,8 +387,10 @@ case "$INTENT_TYPE" in
notify_coderabbit_resolve
post_reviews_terminal "fix-bot-comment" "applied" "Changes committed and pushed."
else
notify_coderabbit_resolve
post_reviews_terminal "fix-bot-comment" "no-changes" "Engine ran but made no changes."
fi
try_enable_auto_merge
fi
exit "$rc"
;;
Expand Down Expand Up @@ -365,8 +435,10 @@ case "$INTENT_TYPE" in
notify_coderabbit_resolve
post_reviews_terminal "human-pr" "applied" "Changes committed and pushed."
else
notify_coderabbit_resolve
post_reviews_terminal "human-pr" "no-changes" "No changes were needed for this PR."
fi
try_enable_auto_merge
fi
exit "$rc"
;;
Expand Down Expand Up @@ -397,6 +469,13 @@ case "$INTENT_TYPE" in
fi
exit "$rc"
;;
enable-auto-merge)
if [ -z "$PR_NUMBER" ]; then
echo "::error::PR_NUMBER is required for enable-auto-merge"
exit 1
fi
try_enable_auto_merge "true"
;;
*)
echo "::error::Unknown intent type: $INTENT_TYPE"
exit 1
Expand Down
4 changes: 2 additions & 2 deletions scripts/dev-lead-intent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ set -euo pipefail
# human-pr — Human review changes-requested
# issue — Issue labeled dev-lead/claude
# rebase — Rebase conflict sentinel
# enable-auto-merge — Bot approval: enable auto-merge if PR is APPROVED
# ci-relay — check_run relay (handled by ci-relay job, not this script)
# skip — Event should be ignored

Expand Down Expand Up @@ -219,9 +220,8 @@ case "$EVENT_NAME" in
'{"pr_number":$pr_number,"head_sha":$head_sha,"actor":$actor,"body":$body}')

if is_trusted_bot "$reviewer"; then
# Bot review: only route non-APPROVED states
if [ "$review_state" = "APPROVED" ]; then
emit_skip "bot-approved"
emit_intent "enable-auto-merge" "bot-approved" "$context"
Comment thread
don-petry marked this conversation as resolved.
Resolved
else
emit_intent "fix-reviews" "bot-review-${review_state}" "$context"
fi
Comment thread
don-petry marked this conversation as resolved.
Resolved
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"_test_expected_intent": "enable-auto-merge",
"action": "submitted",
"review": {
"id": 1010,
"state": "APPROVED",
"body": "All comments resolved. LGTM!",
"user": {
"login": "coderabbitai[bot]",
"type": "Bot"
}
},
"pull_request": {
"number": 80,
"title": "ci: add required ci.yml workflow",
"state": "open",
"author_association": "OWNER",
"head": {
"sha": "03b4349fda588edd13a7a78b823d9a7a9973f5e2",
"ref": "claude/issue-46-20260508-1409",
"repo": { "full_name": "petry-projects/.github-private" }
},
"base": {
"ref": "main",
"repo": { "full_name": "petry-projects/.github-private" }
}
},
"repository": { "full_name": "petry-projects/.github-private" },
"sender": { "login": "coderabbitai[bot]", "type": "Bot" }
}
43 changes: 43 additions & 0 deletions tests/dev-lead/unit/test_fix_reviews.bats
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,49 @@ STUB
[[ "$output" == *"skipping duplicate"* ]]
}

@test "fix-reviews: no-changes path also calls notify_coderabbit_resolve (dry-run)" {
export INTENT_TYPE="fix-reviews"
export DEV_LEAD_DRY_RUN="true"

run bash "$FIX_REVIEWS_SCRIPT"

[ "$status" -eq 0 ]
[[ "$output" == *"would check for coderabbitai CHANGES_REQUESTED"* ]]
}
Comment thread
don-petry marked this conversation as resolved.
Resolved

@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" == *"would enable auto-merge"* ]]
}

@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" == *"would enable auto-merge"* ]]
}

@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" == *"would enable auto-merge"* ]]
}

@test "fix-reviews: terminal marker written after successful fix-reviews run" {
export INTENT_TYPE="fix-reviews"
export DEV_LEAD_DRY_RUN="true"
Expand Down
4 changes: 2 additions & 2 deletions tests/dev-lead/unit/test_intent_ci.bats
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ EOF
[ "$(_get_env INTENT_TYPE)" = "fix-reviews" ]
}

@test "ci: pull_request review from copilot APPROVED → skip" {
@test "ci: pull_request review from copilot APPROVED → enable-auto-merge" {
export GITHUB_EVENT_NAME="pull_request_review"
export GITHUB_EVENT_PATH="$FIXTURES_DIR/pr_review_copilot_approved.json"
export TRUSTED_BOTS="copilot-pull-request-reviewer[bot],gemini-code-assist[bot],sonarqubecloud[bot],coderabbitai[bot]"

run bash "$INTENT_SCRIPT"

[ "$status" -eq 0 ]
[ "$(_get_env INTENT_TYPE)" = "skip" ]
[ "$(_get_env INTENT_TYPE)" = "enable-auto-merge" ]
}

@test "ci: issues labeled dev-lead → issue" {
Expand Down
14 changes: 12 additions & 2 deletions tests/dev-lead/unit/test_intent_reviews.bats
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,24 @@ _get_env() {
[ "$(_get_env INTENT_TYPE)" = "fix-reviews" ]
}

@test "reviews: pull_request_review copilot APPROVED → skip" {
@test "reviews: pull_request_review copilot APPROVED → enable-auto-merge" {
export GITHUB_EVENT_NAME="pull_request_review"
export GITHUB_EVENT_PATH="$FIXTURES_DIR/pr_review_copilot_approved.json"

run bash "$INTENT_SCRIPT"

[ "$status" -eq 0 ]
[ "$(_get_env INTENT_TYPE)" = "skip" ]
[ "$(_get_env INTENT_TYPE)" = "enable-auto-merge" ]
}

@test "reviews: pull_request_review coderabbit APPROVED → enable-auto-merge" {
export GITHUB_EVENT_NAME="pull_request_review"
export GITHUB_EVENT_PATH="$FIXTURES_DIR/pr_review_coderabbit_approved.json"

run bash "$INTENT_SCRIPT"

[ "$status" -eq 0 ]
[ "$(_get_env INTENT_TYPE)" = "enable-auto-merge" ]
}

@test "reviews: pull_request_review gemini CHANGES_REQUESTED → fix-reviews" {
Expand Down