|
| 1 | +name: Auto Merge - No Conflict |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, reopened] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: write |
| 9 | + pull-requests: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + auto-merge-no-conflict: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout repository |
| 17 | + uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + fetch-depth: 0 |
| 20 | + |
| 21 | + - name: Check mergeability |
| 22 | + id: check-mergeable |
| 23 | + run: | |
| 24 | + PR_NUMBER=${{ github.event.pull_request.number }} |
| 25 | +
|
| 26 | + MERGEABLE=$(gh pr view "$PR_NUMBER" \ |
| 27 | + --json mergeable,mergeStateStatus,state \ |
| 28 | + --jq '.mergeable + " " + .mergeStateStatus + " " + .state') |
| 29 | +
|
| 30 | + echo "Raw mergeability: $MERGEABLE" |
| 31 | +
|
| 32 | + MERGEABLE_FLAG=$(echo "$MERGEABLE" | awk '{print $1}') |
| 33 | + MERGE_STATE_STATUS=$(echo "$MERGEABLE" | awk '{print $2}') |
| 34 | + PR_STATE=$(echo "$MERGEABLE" | awk '{print $3}') |
| 35 | +
|
| 36 | + echo "mergeable_flag=$MERGEABLE_FLAG" >> $GITHUB_OUTPUT |
| 37 | + echo "merge_state_status=$MERGE_STATE_STATUS" >> $GITHUB_OUTPUT |
| 38 | + echo "pr_state=$PR_STATE" >> $GITHUB_OUTPUT |
| 39 | + env: |
| 40 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 41 | + |
| 42 | + - name: Auto merge PR (no conflict) |
| 43 | + if: | |
| 44 | + steps.check-mergeable.outputs.pr_state == 'OPEN' && |
| 45 | + steps.check-mergeable.outputs.mergeable_flag == 'MERGEABLE' && |
| 46 | + steps.check-mergeable.outputs.merge_state_status != 'BLOCKED' |
| 47 | + run: | |
| 48 | + PR_NUMBER=${{ github.event.pull_request.number }} |
| 49 | + PR_TITLE=${{ github.event.pull_request.title }} |
| 50 | +
|
| 51 | + echo "PR #$PR_NUMBER tidak punya conflict dan tidak diblok. Melakukan auto-merge..." |
| 52 | +
|
| 53 | + gh pr merge "$PR_NUMBER" \ |
| 54 | + --squash \ |
| 55 | + --auto \ |
| 56 | + --subject "Auto-merge: $PR_TITLE" \ |
| 57 | + --body "Auto-merged oleh GitHub Actions karena tidak ada conflict dan status merge bisa dilakukan." |
| 58 | + env: |
| 59 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 60 | + |
| 61 | + - name: Skip merge (punya conflict atau diblok) |
| 62 | + if: | |
| 63 | + steps.check-mergeable.outputs.pr_state != 'OPEN' || |
| 64 | + steps.check-mergeable.outputs.mergeable_flag != 'MERGEABLE' || |
| 65 | + steps.check-mergeable.outputs.merge_state_status == 'BLOCKED' |
| 66 | + run: | |
| 67 | + PR_NUMBER=${{ github.event.pull_request.number }} |
| 68 | +
|
| 69 | + echo "Auto-merge dilewati. Detail:" |
| 70 | + echo " state : ${{ steps.check-mergeable.outputs.pr_state }}" |
| 71 | + echo " mergeable_flag : ${{ steps.check-mergeable.outputs.mergeable_flag }}" |
| 72 | + echo " merge_state : ${{ steps.check-mergeable.outputs.merge_state_status }}" |
| 73 | +
|
| 74 | + gh pr comment "$PR_NUMBER" \ |
| 75 | + --body "**Auto-merge dilewati** |
| 76 | +
|
| 77 | + PR ini **belum bisa di-merge otomatis**. |
| 78 | +
|
| 79 | + State: \`${{ steps.check-mergeable.outputs.pr_state }}\` |
| 80 | + mergeable: \`${{ steps.check-mergeable.outputs.mergeable_flag }}\` |
| 81 | + mergeStateStatus: \`${{ steps.check-mergeable.outputs.merge_state_status }}\` |
| 82 | +
|
| 83 | + Pastikan tidak ada conflict, checks lulus, dan requirements lain terpenuhi, lalu push ulang." |
| 84 | + env: |
| 85 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 86 | + |
0 commit comments