dependabot-automerge #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: dependabot-automerge | |
| on: | |
| workflow_run: | |
| workflows: ["build"] | |
| types: [completed] | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| automerge: | |
| if: github.event.workflow_run.conclusion == 'success' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Merge Dependabot PR if eligible | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const prs = context.payload.workflow_run.pull_requests; | |
| if (!prs || prs.length === 0) { | |
| core.info('No pull requests associated with this workflow_run.'); | |
| return; | |
| } | |
| const prNumber = prs[0].number; | |
| const { owner, repo } = context.repo; | |
| const { data: pr } = await github.rest.pulls.get({ owner, repo, pull_number: prNumber }); | |
| const author = pr.user?.login || ''; | |
| if (author !== 'dependabot[bot]' && author !== 'dependabot') { | |
| core.info(`PR #${prNumber} is not from Dependabot (${author}).`); | |
| return; | |
| } | |
| if (pr.mergeable_state !== 'clean') { | |
| core.info(`PR #${prNumber} is not mergeable yet (state: ${pr.mergeable_state}).`); | |
| return; | |
| } | |
| await github.rest.pulls.merge({ | |
| owner, | |
| repo, | |
| pull_number: prNumber, | |
| merge_method: 'merge' | |
| }); | |
| core.info(`Merged Dependabot PR #${prNumber}.`); |