-
Notifications
You must be signed in to change notification settings - Fork 272
ci: require Milestone and Projects fields on PRs before merge #736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| name: PR merge requirements | ||
|
|
||
| # Blocks merging until the PR has a Milestone and is on at least one Project | ||
| # board. Runs as `pull_request_target` so that PRs from forks get the repo | ||
| # secrets; this is safe because the job never checks out or executes PR code — | ||
| # it only queries PR metadata. | ||
| on: | ||
| pull_request_target: | ||
| types: | ||
| - opened | ||
| - reopened | ||
| - synchronize | ||
| - ready_for_review | ||
| - edited | ||
| - labeled | ||
| - unlabeled | ||
| - milestoned | ||
| - demilestoned | ||
|
|
||
| permissions: | ||
| pull-requests: read | ||
|
|
||
| jobs: | ||
| merge-requirements: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Check milestone and project assignment | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| # Fine-grained PAT with organization "Projects: read" access; the | ||
| # built-in GITHUB_TOKEN cannot read Projects v2. | ||
| PROJECT_READ_TOKEN: ${{ secrets.PROJECT_READ_TOKEN }} | ||
| REPO: ${{ github.repository }} | ||
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| AUTHOR_TYPE: ${{ github.event.pull_request.user.type }} | ||
| run: | | ||
| set -u | ||
|
|
||
| # Bot PRs (dependabot, github-actions, ...) are exempt. | ||
| if [ "${AUTHOR_TYPE}" = "Bot" ]; then | ||
| echo "PR author is a bot — merge requirements do not apply." | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Query live PR state rather than the (possibly stale) event | ||
| # payload, so that re-running this check after fixing the fields | ||
| # passes without needing a new PR event. | ||
| pr_json=$(gh api "repos/${REPO}/pulls/${PR_NUMBER}") | ||
|
|
||
| if echo "${pr_json}" | jq -e 'any(.labels[]; .name == "cat-routine-update")' > /dev/null; then | ||
| echo "PR is labeled cat-routine-update — merge requirements do not apply." | ||
| exit 0 | ||
| fi | ||
|
|
||
| failed=0 | ||
|
|
||
| milestone=$(echo "${pr_json}" | jq -r '.milestone.title // empty') | ||
| if [ -n "${milestone}" ]; then | ||
| echo "Milestone: ${milestone}" | ||
| else | ||
| echo "::error::This PR has no Milestone." | ||
| failed=1 | ||
| fi | ||
|
|
||
| if [ -z "${PROJECT_READ_TOKEN:-}" ]; then | ||
| echo "::error::The PROJECT_READ_TOKEN repository secret is not configured, so the Projects field cannot be verified. Ask a repository admin to set it (a PAT with read access to organization projects)." | ||
| failed=1 | ||
| else | ||
| project_count=$(GH_TOKEN="${PROJECT_READ_TOKEN}" gh api graphql \ | ||
| -F owner="${REPO%/*}" -F name="${REPO#*/}" -F number="${PR_NUMBER}" \ | ||
| -f query='query($owner: String!, $name: String!, $number: Int!) { | ||
| repository(owner: $owner, name: $name) { | ||
| pullRequest(number: $number) { | ||
| projectItems(first: 1) { totalCount } | ||
| } | ||
| } | ||
| }' --jq '.data.repository.pullRequest.projectItems.totalCount') | ||
| if [ "${project_count}" -gt 0 ] 2> /dev/null; then | ||
| echo "PR is on ${project_count} project board(s)." | ||
| else | ||
| echo "::error::This PR is not on any Project board." | ||
| failed=1 | ||
| fi | ||
| fi | ||
|
|
||
| if [ "${failed}" -ne 0 ]; then | ||
| echo "" | ||
| echo "Set the Milestone and Projects fields in the PR sidebar, then re-run this check from the Checks tab." | ||
| echo "(Adding a PR to a Project does not automatically re-trigger this check; changing the milestone does.)" | ||
| exit 1 | ||
| fi | ||
| echo "All merge requirements satisfied." | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
Repository: NVIDIA/cudnn-frontend
Length of output: 9879
🌐 Web query:
GitHub Actions pull_request_target activity types projects_v2_item project membership changes💡 Result:
There is no direct GitHub Actions event trigger for
projects_v2_itemactivity [1]. Thepull_request_targetevent andprojects_v2_itemare entirely separate, unrelated webhook events [2][3]. 1. projects_v2_item is a webhook event used to monitor activity on GitHub Projects (v2) items (e.g., when an item is created, edited, deleted, archived, restored, or converted) [1][2][4]. It is not a supported trigger for GitHub Actions workflows [1]. 2. pull_request_target is a GitHub Actions workflow trigger designed to run workflows when activity occurs on a pull request within the repository [3][5]. It is commonly used for automation like labeling or triaging pull requests from forks, as it runs in the context of the base repository's default branch for security [6]. Becauseprojects_v2_itemis not a valid workflow trigger, you cannot configure a workflow to run automatically based on project item changes using that event name [1]. To automate workflows based on changes to Project (v2) items, developers typically use third-party tools, create custom serverless functions (e.g., using GitHub Webhooks via an API gateway), or interact with the GitHub GraphQL API to poll for changes or perform actions [1][7][4].Citations:
Close the stale-success bypass for Project removal.
If a PR passes this check and is later removed from its Project, no configured
pull_request_targetactivity triggers this workflow. The previous successful required check can then permit a merge without a Project assignment.Use a trusted webhook or merge-time validation to update the PR status after Project removal. Do not rely on a manual re-run.
🧰 Tools
🪛 zizmor (1.29.0)
[error] 7-18: use of fundamentally insecure workflow trigger (dangerous-triggers): pull_request_target is almost always used insecurely
(dangerous-triggers)
🤖 Prompt for AI Agents