|
31 | 31 | if: > |
32 | 32 | github.event_name == 'schedule' || |
33 | 33 | github.event_name == 'workflow_dispatch' || |
34 | | - (github.event_name == 'pull_request_target' && contains(fromJSON('["zakisk", "infernus01", "savitaashture", "chmouel", "vdemeester", "enarha", "aThorp96", "waveywaves", "mathur07", "dependabot[bot]"]'), github.event.pull_request.user.login)) |
| 34 | + github.event_name == 'pull_request_target' |
35 | 35 | concurrency: |
36 | 36 | group: ${{ github.workflow }}-${{ matrix.provider }}-${{ github.event.pull_request.number || github.ref_name }} |
37 | 37 | cancel-in-progress: true |
|
72 | 72 | with: |
73 | 73 | ref: ${{ inputs.target_ref || github.event.pull_request.head.sha || github.sha }} |
74 | 74 |
|
| 75 | + # Step to check PR author's org membership and repo permissions. |
| 76 | + # This step will fail the job if checks do not pass, skipping subsequent steps. |
| 77 | + - name: Check user permissions on PRs |
| 78 | + if: github.event_name == 'pull_request_target' |
| 79 | + uses: actions/github-script@v7 |
| 80 | + with: |
| 81 | + script: | |
| 82 | + const actor = context.payload.pull_request.user.login; |
| 83 | + const org = context.repo.owner; |
| 84 | +
|
| 85 | + // Allow dependabot and other bots unconditionally. |
| 86 | + if (actor.endsWith('[bot]')) { |
| 87 | + core.info(`User @${actor} is a bot, allowing.`); |
| 88 | + return; |
| 89 | + } |
| 90 | +
|
| 91 | + try { |
| 92 | + // Directly check the user's permission level on the repository. |
| 93 | + // This covers both org members and external collaborators with sufficient access. |
| 94 | + const response = await github.rest.repos.getCollaboratorPermissionLevel({ |
| 95 | + owner: org, |
| 96 | + repo: context.repo.repo, |
| 97 | + username: actor, |
| 98 | + }); |
| 99 | +
|
| 100 | + const permission = response.data.permission; |
| 101 | + if (permission !== 'admin' && permission !== 'write') { |
| 102 | + core.setFailed(`❌ User @${actor} has only '${permission}' repository permission. 'write' or 'admin' is required.`); |
| 103 | + } else { |
| 104 | + core.info(`✅ User @${actor} has '${permission}' repository permission. Proceeding.`); |
| 105 | + } |
| 106 | + } catch (error) { |
| 107 | + core.setFailed(`Permission check failed for @${actor}. They are likely not a collaborator on the repository. Error: ${error.message}`); |
| 108 | + } |
| 109 | +
|
75 | 110 | - uses: actions/setup-go@v5 |
76 | 111 | with: |
77 | 112 | go-version-file: "go.mod" |
|
0 commit comments