Skip to content

Commit bb2cff9

Browse files
committed
Enhance Dependabot merge workflow to check for rebase requirements
1 parent f709f74 commit bb2cff9

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

.github/workflows/dependabot-merge.yml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,41 +55,46 @@ jobs:
5555
echo "Skipping approval and auto-merge."
5656
exit 1
5757
58-
- name: Check for merge conflicts
59-
id: conflict-check
58+
- name: Check merge state
59+
id: merge-check
6060
env:
6161
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6262
GH_REPO: ${{ github.repository }}
6363
PR_NUMBER: ${{ steps.pr.outputs.number }}
6464
run: |
6565
# Get detailed PR info including mergeable state
66+
# mergeStateStatus values: BEHIND, BLOCKED, CLEAN, DIRTY, DRAFT, HAS_HOOKS, UNKNOWN, UNSTABLE
6667
PR_DATA=$(gh pr view "$PR_NUMBER" --repo "$GH_REPO" --json mergeable,mergeStateStatus)
6768
MERGEABLE=$(echo "$PR_DATA" | jq -r '.mergeable')
6869
MERGE_STATE=$(echo "$PR_DATA" | jq -r '.mergeStateStatus')
6970
7071
echo "Mergeable: $MERGEABLE"
7172
echo "Merge State: $MERGE_STATE"
7273
73-
if [ "$MERGEABLE" = "CONFLICTING" ] || [ "$MERGE_STATE" = "DIRTY" ]; then
74-
echo "has_conflict=true" >> "$GITHUB_OUTPUT"
74+
# DIRTY = merge conflict, BEHIND = out-of-date with base branch
75+
# Both cases require a rebase before we can merge
76+
if [ "$MERGEABLE" = "CONFLICTING" ] || [ "$MERGE_STATE" = "DIRTY" ] || [ "$MERGE_STATE" = "BEHIND" ]; then
77+
echo "needs_rebase=true" >> "$GITHUB_OUTPUT"
78+
echo "reason=$MERGE_STATE" >> "$GITHUB_OUTPUT"
7579
else
76-
echo "has_conflict=false" >> "$GITHUB_OUTPUT"
80+
echo "needs_rebase=false" >> "$GITHUB_OUTPUT"
7781
fi
7882
79-
- name: Request rebase if conflicts exist
80-
if: steps.conflict-check.outputs.has_conflict == 'true'
83+
- name: Request rebase
84+
if: steps.merge-check.outputs.needs_rebase == 'true'
8185
env:
8286
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8387
GH_REPO: ${{ github.repository }}
8488
PR_NUMBER: ${{ steps.pr.outputs.number }}
89+
REASON: ${{ steps.merge-check.outputs.reason }}
8590
run: |
86-
echo "Merge conflict detected. Requesting Dependabot to rebase..."
91+
echo "Branch needs rebase (reason: $REASON). Requesting Dependabot to rebase..."
8792
gh pr comment "$PR_NUMBER" --repo "$GH_REPO" --body "@dependabot rebase"
88-
echo "::warning::Merge conflict detected. Requested @dependabot rebase."
93+
echo "::warning::Requested @dependabot rebase (reason: $REASON)"
8994
exit 0
9095
9196
- name: Approve Pull Request
92-
if: steps.conflict-check.outputs.has_conflict != 'true'
97+
if: steps.merge-check.outputs.needs_rebase != 'true'
9398
env:
9499
GH_TOKEN: ${{ secrets.CICDBOT_TOKEN }}
95100
GH_REPO: ${{ github.repository }}
@@ -99,7 +104,7 @@ jobs:
99104
gh pr review "$PR_NUMBER" --repo "$GH_REPO" --approve --body "🤖 Auto-approved by @cicdbot after CI passed"
100105
101106
- name: Enable auto-merge
102-
if: steps.conflict-check.outputs.has_conflict != 'true'
107+
if: steps.merge-check.outputs.needs_rebase != 'true'
103108
env:
104109
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
105110
GH_REPO: ${{ github.repository }}

0 commit comments

Comments
 (0)