Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
237 changes: 0 additions & 237 deletions .github/workflows/merge-conflict-detector.yml

This file was deleted.

63 changes: 63 additions & 0 deletions .github/workflows/pull-request-merge-conflict-detector.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: PR Merge Conflict Detector

on:
workflow_call:
pull_request_target:
Comment thread
coderabbitai[bot] marked this conversation as resolved.
types: [opened, reopened, synchronize, ready_for_review]

jobs:
detect-merge-conflict:
name: Check PR for Merge Conflicts
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read

Comment thread
coderabbitai[bot] marked this conversation as resolved.
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Check PR for merge conflicts
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BASE_REF: ${{ github.event.pull_request.base.ref }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
set -euo pipefail

echo "[CHECK] ========================================"
echo "[CHECK] Checking PR #${PR_NUMBER}"

Comment thread
coderabbitai[bot] marked this conversation as resolved.
git fetch origin "${BASE_REF}"
BASE_SHA=$(git rev-parse "origin/${BASE_REF}")

PR_DATA=$(gh pr view "$PR_NUMBER" --json headRefName,headRefOid,title)

PR_HEAD_REF=$(echo "$PR_DATA" | jq -r '.headRefName')
PR_HEAD_SHA=$(echo "$PR_DATA" | jq -r '.headRefOid')
PR_TITLE=$(echo "$PR_DATA" | jq -r '.title')

git fetch origin "${PR_HEAD_SHA}"

echo "[CHECK] Running merge-tree analysis..."

set +e
MERGE_OUTPUT=$(git merge-tree "$BASE_SHA" "$PR_HEAD_SHA" 2>&1)
MERGE_EXIT_CODE=$?
set -e

echo "[RESULT] ========================================"
printf "[RESULT] PR #%s: %s\n" "$PR_NUMBER" "$PR_TITLE"

if echo "$MERGE_OUTPUT" | grep -q "CONFLICT"; then
echo "[RESULT] ❌ Merge conflicts detected"
echo "$MERGE_OUTPUT" | grep "CONFLICT"
exit 1
elif [ "$MERGE_EXIT_CODE" -ne 0 ]; then
echo "[RESULT] ⚠️ merge-tree exited with error"
exit 1
else
echo "[RESULT] ✅ No conflicts"
fi
Loading
Loading