|
| 1 | +# Responds to GitHub's native auto-merge being enabled or disabled on a PR: |
| 2 | +# |
| 3 | +# 1. Enabled: adds a notice to the PR description. |
| 4 | +# 2. Disabled: updates the PR description notice and removes auto-merge |
| 5 | +# labels so the scheduled auto_merge.yml cron no longer re-processes |
| 6 | +# the PR. |
| 7 | +# |
| 8 | +# Note: Adding an `auto-merge*` label no longer auto-promotes draft PRs. |
| 9 | +# The connectors_up_to_date pipeline handles draft promotion and auto-merge |
| 10 | +# enablement directly. Draft PRs must be explicitly marked "Ready for review" |
| 11 | +# before native auto-merge and label-based automation will take effect. |
| 12 | + |
| 13 | +name: "Auto-Merge Toggle" |
| 14 | + |
| 15 | +permissions: {} |
| 16 | + |
| 17 | +on: |
| 18 | + pull_request_target: |
| 19 | + types: [auto_merge_enabled, auto_merge_disabled] |
| 20 | + |
| 21 | +jobs: |
| 22 | + # ---------- Update PR description notice ---------- |
| 23 | + update-description: |
| 24 | + runs-on: ubuntu-24.04 |
| 25 | + permissions: |
| 26 | + pull-requests: write |
| 27 | + steps: |
| 28 | + - name: Add Auto-Merge Notice |
| 29 | + if: github.event.action == 'auto_merge_enabled' |
| 30 | + uses: bcgov/action-pr-description-add@14338bfe0278ead273b3c1189e5aa286ff6709c4 # v2.0.0 |
| 31 | + with: |
| 32 | + add_markdown: | |
| 33 | + > [!IMPORTANT] |
| 34 | + > ⚡ **Auto-merge enabled.** |
| 35 | + > |
| 36 | + > _This PR is set to merge automatically when all requirements are met._ |
| 37 | +
|
| 38 | + - name: Remove Auto-Merge Notice |
| 39 | + if: github.event.action == 'auto_merge_disabled' |
| 40 | + uses: bcgov/action-pr-description-add@14338bfe0278ead273b3c1189e5aa286ff6709c4 # v2.0.0 |
| 41 | + with: |
| 42 | + add_markdown: | |
| 43 | + > [!NOTE] |
| 44 | + > **Auto-merge may have been disabled. Please check the PR status to confirm.** |
| 45 | +
|
| 46 | + # ---------- Remove auto-merge labels when native auto-merge is disabled ---------- |
| 47 | + remove-labels: |
| 48 | + name: Remove auto-merge labels |
| 49 | + if: > |
| 50 | + github.event.action == 'auto_merge_disabled' |
| 51 | + && ( |
| 52 | + contains(github.event.pull_request.labels.*.name, 'auto-merge') |
| 53 | + || contains(github.event.pull_request.labels.*.name, 'auto-merge/bypass-ci-checks') |
| 54 | + ) |
| 55 | + permissions: {} |
| 56 | + runs-on: ubuntu-24.04 |
| 57 | + steps: |
| 58 | + - name: Authenticate as 'octavia-bot-hoard' GitHub App |
| 59 | + uses: actions/create-github-app-token@67018539274d69449ef7c02e8e71183d1719ab42 # v2.1.4 |
| 60 | + id: get-app-token |
| 61 | + with: |
| 62 | + owner: "airbytehq" |
| 63 | + repositories: "airbyte" |
| 64 | + app-id: ${{ secrets.OCTAVIA_BOT_HOARD_APP_ID }} |
| 65 | + private-key: ${{ secrets.OCTAVIA_BOT_HOARD_PRIVATE_KEY }} |
| 66 | + |
| 67 | + - name: Remove auto-merge label |
| 68 | + if: contains(github.event.pull_request.labels.*.name, 'auto-merge') |
| 69 | + env: |
| 70 | + GH_TOKEN: ${{ steps.get-app-token.outputs.token }} |
| 71 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 72 | + run: > |
| 73 | + gh pr edit "$PR_NUMBER" |
| 74 | + --repo "${{ github.repository }}" |
| 75 | + --remove-label "auto-merge" |
| 76 | +
|
| 77 | + - name: Remove bypass-ci-checks label |
| 78 | + if: contains(github.event.pull_request.labels.*.name, 'auto-merge/bypass-ci-checks') |
| 79 | + env: |
| 80 | + GH_TOKEN: ${{ steps.get-app-token.outputs.token }} |
| 81 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 82 | + run: > |
| 83 | + gh pr edit "$PR_NUMBER" |
| 84 | + --repo "${{ github.repository }}" |
| 85 | + --remove-label "auto-merge/bypass-ci-checks" |
| 86 | +
|
| 87 | + - name: Post notice comment |
| 88 | + env: |
| 89 | + GH_TOKEN: ${{ steps.get-app-token.outputs.token }} |
| 90 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 91 | + run: > |
| 92 | + gh pr comment "$PR_NUMBER" |
| 93 | + --repo "${{ github.repository }}" |
| 94 | + --body "Auto-merge labels removed because native auto-merge was disabled on this PR. Re-add the label to re-enable." |
0 commit comments