| 1 | name: "Automerge" |
| 2 | on: |
| 3 | workflow_run: |
| 4 | workflows: |
| 5 | - CI |
| 6 | types: |
| 7 | - completed |
| 8 | |
| 9 | jobs: |
| 10 | Automerge: |
| 11 | runs-on: ubuntu-latest |
| 12 | if: | |
| 13 | github.event.workflow_run.event == 'pull_request' && |
| 14 | github.event.workflow_run.conclusion == 'success' |
| 15 | steps: |
| 16 | - name: "Merge PR" |
| 17 | uses: actions/github-script@v8 |
| 18 | with: |
| 19 | github-token: ${{ secrets.GITHUB_TOKEN }} |
| 20 | script: | |
| 21 | const pr = await github.rest.pulls.get({ |
| 22 | owner: context.repo.owner, |
| 23 | repo: context.repo.repo, |
| 24 | pull_number: context.payload.workflow_run.pull_requests[0].number, |
| 25 | }); |
| 26 | if (!pr.data.title.startsWith('chore(deps-dev):')) { |
| 27 | console.log('Not Merged 🚫'); |
| 28 | console.log(`Title === '${pr.data.title}'`); |
| 29 | } else if (pr.data.user.login !== 'dependabot[bot]') { |
| 30 | console.log('Not Merged 🚫'); |
| 31 | console.log(`User === '${pr.data.user.login}'`); |
| 32 | } else { |
| 33 | await github.rest.pulls.merge({ |
| 34 | owner: context.repo.owner, |
| 35 | repo: context.repo.repo, |
| 36 | pull_number: context.payload.workflow_run.pull_requests[0].number, |
| 37 | }); |
| 38 | console.log('Merged 🎉'); |
| 39 | } |