Skip to content

Commit 64e2e6a

Browse files
rwgkcursoragent
andauthored
[no-ci] Trust any collaborator in restricted-paths guard (#2010)
* Trust any collaborator in restricted-paths guard Restricted-paths review is only meant for authors outside the collaborator set, so read and triage access should count as trusted signals too. Co-authored-by: Cursor <cursoragent@cursor.com> * Post PR comment when restricted-paths review is required Make it easier to discover why Needs-Restricted-Paths-Review was applied by posting a short PR comment with a link to the workflow run summary whenever the label is newly added. Co-authored-by: Cursor <cursoragent@cursor.com> * TEMPORARY: Switch to pull_request trigger for testing This commit is for testing the collaborator permission check and must be reverted before merge: 1. Changes trigger from pull_request_target to pull_request so this branch's workflow definition runs instead of main's. 2. Adds a dummy change to cuda_bindings/pyproject.toml to trigger the restricted-paths detection. REVERT THIS COMMIT BEFORE MERGE. Made-with: Cursor * TEMPORARY: Exclude write permission from trusted collaborators This commit is for testing the label-and-comment path and must be reverted before merge. It temporarily treats write access as untrusted so the current PR will exercise Needs-Restricted-Paths-Review assignment again. Co-authored-by: Cursor <cursoragent@cursor.com> * Revert "TEMPORARY: Exclude write permission from trusted collaborators" This reverts commit 31ddac2. * Revert "TEMPORARY: Switch to pull_request trigger for testing" This reverts commit 9b2fcd8. --------- Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 2849053 commit 64e2e6a

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

.github/workflows/restricted-paths-guard.yml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
3030
PR_NUMBER: ${{ github.event.pull_request.number }}
3131
PR_URL: ${{ github.event.pull_request.html_url }}
32+
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
3233

3334
# Workflow policy inputs
3435
REVIEW_LABEL: Needs-Restricted-Paths-Review
@@ -113,9 +114,25 @@ jobs:
113114
echo '```'
114115
}
115116
117+
post_review_label_comment() {
118+
local comment_body
119+
printf -v comment_body '%s\n\n%s\n' \
120+
"\`$REVIEW_LABEL\` was assigned by \`CI: Restricted Paths Guard\`." \
121+
"For details, open [this workflow run]($RUN_URL) and click **Summary**."
122+
123+
if gh api "repos/$REPO/issues/$PR_NUMBER/comments" \
124+
-f body="$comment_body" >/dev/null; then
125+
COMMENT_ACTION="posted"
126+
else
127+
COMMENT_ACTION="failed (non-fatal)"
128+
echo "::warning::Failed to post PR comment about newly added $REVIEW_LABEL."
129+
fi
130+
}
131+
116132
HAS_TRUSTED_SIGNAL=false
117133
LABEL_ACTION="not needed (no restricted paths)"
118134
TRUSTED_SIGNALS="(none)"
135+
COMMENT_ACTION="not needed"
119136
120137
if [ "$TOUCHES_RESTRICTED_PATHS" = "true" ]; then
121138
# Distinguish a legitimate 404 "not a collaborator" response from
@@ -149,13 +166,13 @@ jobs:
149166
fi
150167
151168
case "$COLLABORATOR_PERMISSION" in
152-
admin|maintain|write)
169+
admin|maintain|write|triage|read)
153170
HAS_TRUSTED_SIGNAL=true
154171
LABEL_ACTION="not needed (collaborator permission is a trusted signal)"
155172
TRUSTED_SIGNALS="collaborator_permission:$COLLABORATOR_PERMISSION"
156173
;;
157174
*)
158-
# triage, read, or none: not a trusted signal
175+
# none: not a trusted signal
159176
;;
160177
esac
161178
fi
@@ -189,6 +206,7 @@ jobs:
189206
exit 1
190207
else
191208
LABEL_ACTION="added"
209+
post_review_label_comment
192210
fi
193211
elif [ "$LABEL_ALREADY_PRESENT" = "true" ]; then
194212
LABEL_ACTION="left in place (manual removal required)"
@@ -203,6 +221,7 @@ jobs:
203221
echo "- **Restricted paths**: \`cuda_bindings/\`, \`cuda_python/\`"
204222
echo "- **Trusted signals**: $TRUSTED_SIGNALS"
205223
echo "- **Label action**: $LABEL_ACTION"
224+
echo "- **Comment action**: $COMMENT_ACTION"
206225
if [ "$TOUCHES_RESTRICTED_PATHS" = "true" ]; then
207226
echo ""
208227
write_matching_restricted_paths

0 commit comments

Comments
 (0)