|
6 | 6 |
|
7 | 7 | permissions: |
8 | 8 | issues: write |
9 | | - contents: read |
10 | | - pull-requests: read |
| 9 | + contents: write # was: read -> needed for merging |
| 10 | + pull-requests: write # was: read -> needed for merging |
| 11 | + checks: read |
| 12 | + statuses: read |
11 | 13 |
|
12 | 14 | jobs: |
13 | 15 | create_issue_for_high_critical: |
|
70 | 72 | `- **Update type**: ${updateType}`, |
71 | 73 | `- **Dependency type**: ${dependencyType}`, |
72 | 74 | `- **PR**: #${pr.number}`, |
73 | | - `- **PR URL**: ${alertUrl}`, |
74 | 75 | ]; |
75 | 76 |
|
76 | 77 | if (ghsa) { |
|
97 | 98 | labels, |
98 | 99 | assignees: ['Dopeamin'], |
99 | 100 | }); |
| 101 | +
|
| 102 | + auto_merge_dependabot: |
| 103 | + runs-on: ubuntu-latest |
| 104 | + needs: create_issue_for_high_critical |
| 105 | + if: github.event.pull_request.user.login == 'dependabot[bot]' |
| 106 | + |
| 107 | + steps: |
| 108 | + - name: Check if all required checks passed |
| 109 | + id: status |
| 110 | + uses: actions/github-script@v7 |
| 111 | + with: |
| 112 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 113 | + script: | |
| 114 | + const { owner, repo } = context.repo; |
| 115 | + const pr = context.payload.pull_request; |
| 116 | + const sha = pr.head.sha; |
| 117 | +
|
| 118 | + // Combined status (old API) |
| 119 | + const { data: combined } = await github.rest.repos.getCombinedStatusForRef({ |
| 120 | + owner, |
| 121 | + repo, |
| 122 | + ref: sha, |
| 123 | + }); |
| 124 | +
|
| 125 | + // Checks API (GitHub Actions and other checks) |
| 126 | + const { data: checks } = await github.rest.checks.listForRef({ |
| 127 | + owner, |
| 128 | + repo, |
| 129 | + ref: sha, |
| 130 | + }); |
| 131 | +
|
| 132 | + const allStatusesSuccess = |
| 133 | + (combined.state === 'success' || combined.state === 'pending') && |
| 134 | + combined.statuses.every(s => |
| 135 | + ['success', 'neutral', 'skipped', 'pending'].includes(s.state) |
| 136 | + ); |
| 137 | +
|
| 138 | + const allChecksSuccess = |
| 139 | + checks.check_runs.length === 0 || |
| 140 | + checks.check_runs.every(c => |
| 141 | + ['success', 'neutral', 'skipped'].includes(c.conclusion) |
| 142 | + ); |
| 143 | +
|
| 144 | + if (!allStatusesSuccess || !allChecksSuccess) { |
| 145 | + core.info('Not all checks are successful yet – skipping merge.'); |
| 146 | + core.setOutput('can_merge', 'false'); |
| 147 | + } else { |
| 148 | + core.info('All checks look good – ready to merge.'); |
| 149 | + core.setOutput('can_merge', 'true'); |
| 150 | + } |
| 151 | +
|
| 152 | + - name: Merge Dependabot PR |
| 153 | + if: steps.status.outputs.can_merge == 'true' |
| 154 | + uses: actions/github-script@v7 |
| 155 | + with: |
| 156 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 157 | + script: | |
| 158 | + const { owner, repo } = context.repo; |
| 159 | + const pr = context.payload.pull_request; |
| 160 | +
|
| 161 | + await github.rest.pulls.merge({ |
| 162 | + owner, |
| 163 | + repo, |
| 164 | + pull_number: pr.number, |
| 165 | + merge_method: 'squash', // or 'merge' / 'rebase' |
| 166 | + }); |
| 167 | +
|
| 168 | + core.info(`Merged Dependabot PR #${pr.number}`); |
0 commit comments