Skip to content

Commit f5576e0

Browse files
authored
Use repo permission to skip contribution quality (#2956)
GitHub did not report trusted authors in a stable way on pull requests. Some Miden team members showed up as CONTRIBUTORS, so role checks could not tell team PRs from outside PRs. That pushed the workflow to skip too much.\n\nThis change uses the author's repo permission instead. The workflow now skips only authors with admin, maintain, or write access.
1 parent c30aeb9 commit f5576e0

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

.github/workflows/contribution-quality.yml

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
name: Contribution Quality
22

3-
# Use pull_request_target to get write permissions for fork PRs.
4-
# IMPORTANT: This workflow runs in the context of the BASE branch, not the PR branch.
5-
# Do NOT checkout or run code from the PR itself, only inspect PR metadata via the API.
3+
# Use pull_request_target so the workflow can safely comment/label on PRs.
4+
# IMPORTANT: This runs in the context of the BASE branch, not the PR branch.
5+
# Do NOT checkout or run code from the PR itself; only inspect PR metadata via the API.
66
on:
77
pull_request_target:
88
types: [opened, reopened, edited, synchronize, ready_for_review]
@@ -28,8 +28,7 @@ jobs:
2828
gate:
2929
if: >
3030
github.event_name == 'workflow_dispatch' ||
31-
(github.event_name == 'pull_request' &&
32-
github.event.pull_request.head.repo.fork == true)
31+
github.event_name == 'pull_request_target'
3332
runs-on: ubuntu-latest
3433
env:
3534
DISPATCH_PR_NUMBER: ${{ inputs.pr_number }}
@@ -64,24 +63,46 @@ jobs:
6463
repo: context.repo.repo,
6564
pull_number: prNumber
6665
});
67-
core.setOutput('author_association', pr.author_association || 'NONE');
66+
core.setOutput('author_login', pr.user?.login || '');
6867
core.setOutput('draft', pr.draft ? 'true' : 'false');
6968
core.setOutput('body', (pr.body || '').replace(/\r/g,''));
7069
core.setOutput('number', String(pr.number));
7170
72-
- name: Skip trusted or drafts (unless forced)
71+
- name: Resolve author permission
72+
id: perm
73+
uses: actions/github-script@v7
74+
with:
75+
script: |
76+
const login = "${{ steps.pr.outputs.author_login }}".toLowerCase();
77+
let permission = 'none';
78+
try {
79+
const { data } = await github.rest.repos.getCollaboratorPermissionLevel({
80+
owner: context.repo.owner,
81+
repo: context.repo.repo,
82+
username: login,
83+
});
84+
permission = (data.permission || 'none').toLowerCase();
85+
} catch (error) {
86+
if (error.status !== 404) {
87+
core.warning(`Failed to resolve collaborator permission for ${login}: ${error.message}`);
88+
}
89+
}
90+
91+
const skip = ['admin', 'maintain', 'write'].includes(permission);
92+
core.info(`author=${login} permission=${permission} skip=${skip}`);
93+
core.setOutput('permission', permission);
94+
core.setOutput('skip', skip ? 'true' : 'false');
95+
96+
- name: Skip trusted authors or drafts (unless forced)
7397
id: gate
7498
run: |
75-
assoc="${{ steps.pr.outputs.author_association }}"
7699
draft="${{ steps.pr.outputs.draft }}"
77100
force="${{ steps.ctx.outputs.force_all }}"
101+
skip_by_permission="${{ steps.perm.outputs.skip }}"
78102
if [ "$force" = "true" ]; then
79103
echo "skip=false" >> "$GITHUB_OUTPUT"
80104
else
81-
case "$assoc" in
82-
OWNER|COLLABORATOR|MEMBER) echo "skip=true" >> "$GITHUB_OUTPUT" ;;
83-
*) echo "skip=false" >> "$GITHUB_OUTPUT" ;;
84-
esac
105+
[ "$skip_by_permission" = "true" ] && echo "skip=true" >> "$GITHUB_OUTPUT" || echo "skip=false" >> "$GITHUB_OUTPUT"
85106
[ "$draft" = "true" ] && echo "skip=true" >> "$GITHUB_OUTPUT" || true
86107
fi
87108

0 commit comments

Comments
 (0)