-
Notifications
You must be signed in to change notification settings - Fork 540
ci: gate PRs on AI disclosure and flag unreviewed AI attribution #728
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
+137
−3
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| ## What and why | ||
|
|
||
| <!-- The problem, the approach, and any behavior or compatibility changes. Link related issues. --> | ||
|
|
||
| ## Testing | ||
|
|
||
| <!-- What you ran (`pnpm check`, `anchor test`, `pnpm build-and-test` in the affected examples) and any manual verification. --> | ||
|
|
||
| ## AI disclosure | ||
|
|
||
| Check exactly one. See [CONTRIBUTING.md](https://github.com/solana-foundation/program-examples/blob/main/CONTRIBUTING.md#ai-use). | ||
|
|
||
| - [ ] No AI tooling was used beyond editor autocomplete. | ||
| - [ ] AI tooling was used. Tool and extent: <!-- e.g. Claude Code wrote the tests, I wrote and reviewed everything else --> |
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,109 @@ | ||
| name: PR hygiene | ||
|
|
||
| on: | ||
| pull_request_target: | ||
| branches: [main] | ||
| types: [opened, edited, synchronize, reopened] | ||
|
|
||
| permissions: | ||
| contents: read | ||
| issues: write | ||
| pull-requests: write | ||
|
|
||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| GH_REPO: ${{ github.repository }} | ||
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||
|
|
||
| jobs: | ||
| disclosure: | ||
| name: AI disclosure declared | ||
| if: github.event.pull_request.user.type != 'Bot' | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Require exactly one disclosure box | ||
| env: | ||
| BODY: ${{ github.event.pull_request.body }} | ||
| run: | | ||
| body=$(perl -0777 -pe 's/<!--.*?-->//gs' <<<"$BODY") | ||
| no_ai=$(grep -ciE '^\s*[-*] \[x\] No AI tooling was used' <<<"$body" || true) | ||
| used_ai=$(grep -ciE '^\s*[-*] \[x\] AI tooling was used' <<<"$body" || true) | ||
|
|
||
| if (( no_ai + used_ai != 1 )); then | ||
| echo "::error::Check exactly one AI disclosure box in the PR description (see .github/PULL_REQUEST_TEMPLATE.md)." | ||
| exit 1 | ||
| fi | ||
|
|
||
| if (( used_ai == 1 )) && ! grep -qiE 'Tool and extent:\s*\S' <<<"$body"; then | ||
| echo "::error::State which AI tool was used and to what extent after 'Tool and extent:'." | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "AI disclosure present." | ||
|
|
||
| attribution: | ||
| name: No unreviewed AI attribution | ||
| if: github.event.pull_request.user.type != 'Bot' | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| LABEL: ai-unreviewed | ||
| steps: | ||
| - name: Scan title, description, commits and branch | ||
| env: | ||
| TITLE: ${{ github.event.pull_request.title }} | ||
| BODY: ${{ github.event.pull_request.body }} | ||
| HEAD_REF: ${{ github.head_ref }} | ||
| AUTHOR: ${{ github.event.pull_request.user.login }} | ||
| COMMENT: | | ||
| This PR's description or commit messages still carry attribution generated by an AI coding tool. Per [CONTRIBUTING.md](https://github.com/solana-foundation/program-examples/blob/main/CONTRIBUTING.md#ai-use), that means the change was opened without its author reading it. | ||
|
|
||
| To proceed: read the full diff, remove the tool attribution from the description and commits, fill in the AI disclosure section, and make sure you can explain every line without an LLM. This check re-runs when you edit the description or push. PRs left in this state are closed. | ||
| run: | | ||
| if gh pr view "$PR_NUMBER" --json labels --jq '.labels[].name' | grep -qxF "$LABEL"; then | ||
| was_labeled=true | ||
| else | ||
| was_labeled=false | ||
| fi | ||
|
|
||
| permission=$(gh api "repos/$GH_REPO/collaborators/$AUTHOR/permission" 2>/dev/null | jq -r '.permission // "none"') | ||
| if [[ "$permission" == "admin" || "$permission" == "write" ]]; then | ||
| if [[ "$was_labeled" == "true" ]]; then | ||
| gh pr edit "$PR_NUMBER" --remove-label "$LABEL" | ||
| fi | ||
| echo "Author has $permission access; skipping." | ||
| exit 0 | ||
| fi | ||
|
|
||
| commits=$(gh pr view "$PR_NUMBER" --json commits --jq '.commits[] | .messageHeadline, .messageBody') | ||
| text=$(printf '%s\n%s\n%s\n' "$TITLE" "$BODY" "$commits") | ||
|
|
||
| patterns='marzipan' | ||
| patterns+='|co-authored-by:.*(claude|copilot|cursor|codex|chatgpt|openai|aider|devin|gemini|windsurf)' | ||
| patterns+='|generated with .*claude code|claude\.ai/code|claude\.com/claude-code' | ||
| patterns+='|noreply@anthropic\.com|noreply@cursor\.com|made with cursor|cursor\.com' | ||
|
|
||
| hits=$(grep -iE "$patterns" <<<"$text" || true) | ||
| if [[ "$HEAD_REF" =~ ^(claude|codex|cursor|copilot)/ ]]; then | ||
| hits+=$'\n'"branch: $HEAD_REF" | ||
| fi | ||
| hits=$(sed '/^$/d' <<<"$hits") | ||
|
|
||
| if [[ -z "$hits" ]]; then | ||
| if [[ "$was_labeled" == "true" ]]; then | ||
| gh pr edit "$PR_NUMBER" --remove-label "$LABEL" | ||
| fi | ||
| echo "No AI tool attribution found." | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "::error::AI tool attribution left in the PR:" | ||
| echo "$hits" | ||
|
|
||
| gh label create "$LABEL" --color D93F0B --force \ | ||
| --description 'PR description or commits carry AI tool attribution the author did not review' | ||
| gh pr edit "$PR_NUMBER" --add-label "$LABEL" | ||
|
|
||
| if [[ "$was_labeled" != "true" ]]; then | ||
| gh pr comment "$PR_NUMBER" --body "$COMMENT" | ||
| fi | ||
| exit 1 | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.