Skip to content

feat: add assignment guard for advanced issues (#1142) #347

feat: add assignment guard for advanced issues (#1142)

feat: add assignment guard for advanced issues (#1142) #347

name: PythonBot - Check Merge Conflicts
on:
pull_request_target:
types: [opened, synchronize, reopened]
permissions:
contents: read
pull-requests: write
concurrency:
group: "check-conflicts-${{ github.event.pull_request.number }}"
cancel-in-progress: true
jobs:
check-conflicts:
runs-on: ubuntu-latest
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
with:
egress-policy: audit
- name: Check for merge conflicts
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
REPO="${{ github.repository }}"
echo "Checking merge status for PR #$PR_NUMBER in repository $REPO..."
for i in {1..10}; do
PR_JSON=$(gh api repos/$REPO/pulls/$PR_NUMBER)
MERGEABLE_STATE=$(echo "$PR_JSON" | jq -r '.mergeable_state')
echo "Attempt $i: Current mergeable state: $MERGEABLE_STATE"
if [ "$MERGEABLE_STATE" != "unknown" ]; then
break
fi
echo "State is 'unknown', waiting 2 seconds..."
sleep 2
done
if [ "$MERGEABLE_STATE" = "dirty" ]; then
COMMENT=$(cat <<EOF
Hi, this is MergeConflictBot.
Your pull request cannot be merged because it contains **merge conflicts**.
Please resolve these conflicts locally and push the changes.
To assist you, please read:
- [Resolving Merge Conflicts](docs/sdk_developers/merge_conflicts.md)
- [Rebasing Guide](docs/sdk_developers/rebasing.md)
Thank you for contributing!
From the Hiero Python SDK Team
EOF
)
gh pr view $PR_NUMBER --repo $REPO --json comments --jq '.comments[].body' | grep -F "MergeConflictBot" >/dev/null || \
(gh pr comment $PR_NUMBER --repo $REPO --body "$COMMENT" && echo "Comment added to PR #$PR_NUMBER")
exit 1
else
echo "No merge conflicts detected (State: $MERGEABLE_STATE)."
fi