Skip to content

Commit 8de5062

Browse files
committed
created separate files
1 parent 5dc6980 commit 8de5062

3 files changed

Lines changed: 162 additions & 237 deletions

File tree

.github/workflows/merge-conflict-detector.yml

Lines changed: 0 additions & 237 deletions
This file was deleted.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: PR Merge Conflict Detector
2+
3+
on:
4+
workflow_call:
5+
pull_request_target:
6+
7+
jobs:
8+
detect-merge-conflict:
9+
name: Check PR for Merge Conflicts
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0
17+
18+
- name: Check PR for merge conflicts
19+
env:
20+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21+
run: |
22+
set -euo pipefail
23+
24+
echo "[CHECK] ========================================"
25+
echo "[CHECK] Checking PR #${{ github.event.pull_request.number }}"
26+
27+
BASE_REF="${{ github.event.pull_request.base.ref }}"
28+
PR_NUMBER="${{ github.event.pull_request.number }}"
29+
30+
git fetch origin "${BASE_REF}"
31+
BASE_SHA=$(git rev-parse "origin/${BASE_REF}")
32+
33+
PR_DATA=$(gh pr view "$PR_NUMBER" --json headRefName,headRefOid,title)
34+
35+
PR_HEAD_REF=$(echo "$PR_DATA" | jq -r '.headRefName')
36+
PR_HEAD_SHA=$(echo "$PR_DATA" | jq -r '.headRefOid')
37+
PR_TITLE=$(echo "$PR_DATA" | jq -r '.title')
38+
39+
git fetch origin "${PR_HEAD_SHA}"
40+
41+
echo "[CHECK] Running merge-tree analysis..."
42+
43+
set +e
44+
MERGE_OUTPUT=$(git merge-tree "$BASE_SHA" "$PR_HEAD_SHA" 2>&1)
45+
MERGE_EXIT_CODE=$?
46+
set -e
47+
48+
echo "[RESULT] ========================================"
49+
printf "[RESULT] PR #%s: %s\n" "$PR_NUMBER" "$PR_TITLE"
50+
51+
if echo "$MERGE_OUTPUT" | grep -q "CONFLICT"; then
52+
echo "[RESULT] ❌ Merge conflicts detected"
53+
echo "$MERGE_OUTPUT" | grep "CONFLICT"
54+
exit 1
55+
elif [ "$MERGE_EXIT_CODE" -ne 0 ]; then
56+
echo "[RESULT] ⚠️ merge-tree exited with error"
57+
exit 1
58+
else
59+
echo "[RESULT] ✅ No conflicts"
60+
fi

0 commit comments

Comments
 (0)