|
| 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 |
0 commit comments