|
1 | 1 | name: Dependabot Auto-merge |
2 | 2 |
|
3 | | -# NOTE: `merge-me-action` still needs the bot PAT here. |
4 | | -# Using `secrets.GITHUB_TOKEN` fails on `workflow_run` with |
5 | | -# "Resource not accessible by integration" when the action queries |
6 | | -# branch protection rules over GraphQL. |
7 | | -# See: https://github.com/ridedott/merge-me-action/issues/1581 |
| 3 | +# Run in the trusted `workflow_run` context and merge Dependabot PRs directly |
| 4 | +# with the repository token instead of depending on an external PAT. |
8 | 5 |
|
9 | 6 | on: |
10 | 7 | workflow_run: |
|
14 | 11 | # List all required workflow names here. |
15 | 12 | - Build |
16 | 13 |
|
| 14 | +permissions: |
| 15 | + contents: write |
| 16 | + pull-requests: write |
| 17 | + |
17 | 18 | jobs: |
18 | 19 | auto_merge: |
19 | 20 | name: Auto-merge |
|
24 | 25 | github.actor == 'dependabot[bot]' |
25 | 26 |
|
26 | 27 | steps: |
27 | | - - uses: ridedott/merge-me-action@bb09d7d3c3504d3837816cc4eb821e663dc7ffde |
| 28 | + - uses: actions/github-script@v9 |
28 | 29 | with: |
29 | | - GITHUB_TOKEN: ${{ secrets.AWBOT_GH_TOKEN }} |
| 30 | + script: | |
| 31 | + const pr = context.payload.workflow_run.pull_requests?.[0]; |
| 32 | + if (!pr) { |
| 33 | + core.setFailed("No pull request found in workflow_run payload."); |
| 34 | + return; |
| 35 | + } |
| 36 | +
|
| 37 | + const { data: pull } = await github.rest.pulls.get({ |
| 38 | + owner: context.repo.owner, |
| 39 | + repo: context.repo.repo, |
| 40 | + pull_number: pr.number, |
| 41 | + }); |
| 42 | +
|
| 43 | + if (pull.state !== "open") { |
| 44 | + core.info(`PR #${pull.number} is already ${pull.state}; nothing to do.`); |
| 45 | + return; |
| 46 | + } |
| 47 | +
|
| 48 | + if (pull.draft) { |
| 49 | + core.info(`PR #${pull.number} is a draft; skipping.`); |
| 50 | + return; |
| 51 | + } |
| 52 | +
|
| 53 | + await github.rest.pulls.merge({ |
| 54 | + owner: context.repo.owner, |
| 55 | + repo: context.repo.repo, |
| 56 | + pull_number: pull.number, |
| 57 | + merge_method: "squash", |
| 58 | + sha: context.payload.workflow_run.head_sha, |
| 59 | + }); |
| 60 | +
|
| 61 | + core.info(`Merged Dependabot PR #${pull.number}.`); |
0 commit comments