Skip to content

Commit e24b9b4

Browse files
authored
feat: Add automated merge conflict detection bot (#901)
Signed-off-by: Adityarya11 <arya050411@gmail.com> Signed-off-by: notsogod <149138960+Adityarya11@users.noreply.github.com>
1 parent 7eaf6ff commit e24b9b4

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: PythonBot - Check Merge Conflicts
2+
3+
on:
4+
pull_request_target:
5+
types: [opened, synchronize, reopened]
6+
7+
permissions:
8+
contents: read
9+
pull-requests: write
10+
11+
concurrency:
12+
group: "check-conflicts-${{ github.event.pull_request.number }}"
13+
cancel-in-progress: true
14+
15+
jobs:
16+
check-conflicts:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Harden the runner (Audit all outbound calls)
21+
uses: step-security/harden-runner@95d9a5deda9de15063e7595e9719c11c38c90ae2 # v2.13.2
22+
with:
23+
egress-policy: audit
24+
25+
- name: Check for merge conflicts
26+
env:
27+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28+
run: |
29+
PR_NUMBER=${{ github.event.pull_request.number }}
30+
REPO="${{ github.repository }}"
31+
32+
echo "Checking merge status for PR #$PR_NUMBER in repository $REPO..."
33+
34+
for i in {1..10}; do
35+
PR_JSON=$(gh api repos/$REPO/pulls/$PR_NUMBER)
36+
MERGEABLE_STATE=$(echo "$PR_JSON" | jq -r '.mergeable_state')
37+
38+
echo "Attempt $i: Current mergeable state: $MERGEABLE_STATE"
39+
40+
if [ "$MERGEABLE_STATE" != "unknown" ]; then
41+
break
42+
fi
43+
44+
echo "State is 'unknown', waiting 2 seconds..."
45+
sleep 2
46+
done
47+
48+
if [ "$MERGEABLE_STATE" = "dirty" ]; then
49+
COMMENT=$(cat <<EOF
50+
Hi, this is MergeConflictBot.
51+
Your pull request cannot be merged because it contains **merge conflicts**.
52+
53+
Please resolve these conflicts locally and push the changes.
54+
55+
To assist you, please read:
56+
- [Resolving Merge Conflicts](docs/sdk_developers/merge_conflicts.md)
57+
- [Rebasing Guide](docs/sdk_developers/rebasing.md)
58+
59+
Thank you for contributing!
60+
61+
From the Hiero Python SDK Team
62+
EOF
63+
)
64+
65+
gh pr view $PR_NUMBER --repo $REPO --json comments --jq '.comments[].body' | grep -F "MergeConflictBot" >/dev/null || \
66+
(gh pr comment $PR_NUMBER --repo $REPO --body "$COMMENT" && echo "Comment added to PR #$PR_NUMBER")
67+
68+
exit 1
69+
else
70+
echo "No merge conflicts detected (State: $MERGEABLE_STATE)."
71+
fi

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
88

99
### Added
1010
- Add example demonstrating usage of `CustomFeeLimit` in `examples/transaction/custom_fee_limit.py`
11+
- Added `.github/workflows/merge-conflict-bot.yml` to automatically detect and notify users of merge conflicts in Pull Requests.
1112

1213
### Changed
1314

@@ -69,7 +70,6 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
6970
- changed to add concurrency to workflow bot
7071
- feat: Refactor `TokenDissociateTransaction` to use set_token_ids method and update transaction fee to Hbar, also update `transaction.py` and expand `examples/token_dissociate.py`, `tests/unit/token_dissociate.py`.
7172

72-
7373
### Fixed
7474

7575
- chore: updated solo action to avoid v5

0 commit comments

Comments
 (0)