Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/workflows/block-ai-commits.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Block AI Commits

on:
pull_request:
types: [opened, reopened, synchronize]

concurrency:
group: block-ai-commits-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
check-ai-authorship:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
steps:
- name: Checkout repository
uses: actions/checkout@v6
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
with:
fetch-depth: 0

- name: Check commits for AI authorship
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
set -euo pipefail

# Exact AI-tool identities against commit author/committer emails and against Co-authored-by trailers.
signatures=(
'cursoragent@cursor\.com' # Cursor
'cursoragent@users\.noreply\.github\.com' # Cursor
'noreply@anthropic\.com' # Claude Code
'claude-code@anthropic\.com' # Claude Code
'noreply@openai\.com' # OpenAI Codex / ChatGPT Codex
'codex@openai\.com' # OpenAI Codex / ChatGPT Codex
'copilot@github\.com' # GitHub Copilot
)
pattern="$(IFS='|'; echo "${signatures[*]}")"

if git log --no-merges \
--format='%h %ae %ce %(trailers:key=Co-authored-by,valueonly,unfold)' \
"${BASE_SHA}..${HEAD_SHA}" | grep -iE "$pattern"; then
Comment on lines +42 to +44

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 suggestion (security): Avoid leaking matching email addresses in logs by using grep -q

The current grep -iE "$pattern" prints matched lines, including abbreviated commit hashes and author/committer emails, into workflow logs, which is a privacy concern. Use grep -qiE "$pattern" (or add -q) so the check still blocks offending commits but only the error message is logged, not the matched line content.

Suggested change
if git log --no-merges \
--format='%h %ae %ce %(trailers:key=Co-authored-by,valueonly,unfold)' \
"${BASE_SHA}..${HEAD_SHA}" | grep -iE "$pattern"; then
if git log --no-merges \
--format='%h %ae %ce %(trailers:key=Co-authored-by,valueonly,unfold)' \
"${BASE_SHA}..${HEAD_SHA}" | grep -qiE "$pattern"; then

echo "::error::This pull request contains commits authored or co-authored by AI tools."
exit 1
fi

echo "No AI-authored or AI-co-authored commits found."
Loading