-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
112 lines (102 loc) · 3.94 KB
/
Copy pathaction.yml
File metadata and controls
112 lines (102 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# SPDX-FileCopyrightText: 2026 German Federal Office for Information Security (BSI) <https://www.bsi.bund.de>
# Software-Engineering: 2026 Intevation GmbH <https://intevation.de>
#
# SPDX-License-Identifier: Apache-2.0
name: 'AI Contribution Detection'
description: 'A GitHub Action checking if a contribution was made with AI'
author: 'CSAF Tools Development Community'
inputs:
fail-on-detection:
description: 'Exit with a non-zero status code when LLM co-authorship is detected'
required: false
default: 'true'
comment-on-detection:
description: Post a PR comment when LLM co-authorship is detected
required: false
default: 'false'
runs:
using: composite
steps:
- uses: actions/checkout@v6
with: # fetch complete history, not just the last commit
fetch-depth: 0
- name: Check commits for LLM co-authors
id: llm-check
shell: bash
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
FAIL_ON_DETECTION: ${{ inputs.fail-on-detection }}
COMMENT_ON_DETECTION: ${{ inputs.comment-on-detection }}
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
run: |
# LLM tool co-author patterns
# Examples:
# Co-authored-by: GitHub Copilot <copilot@github.com>
# Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
# Co-authored-by: Claude <claude@users.noreply.github.com>
LLM_COAUTHOR_PATTERNS=(
'co-authored-by:.*(github-)?copilot'
'co-authored-by:.*claude'
'co-authored-by:.*chatgpt'
'co-authored-by:.*gemini'
'co-authored-by:.*cursor'
'co-authored-by:.*tabnine'
'co-authored-by:.*codeium'
'co-authored-by:.*amazon q'
'co-authored-by:.*continue'
)
LLM_AUTHOR_PATTERNS=(
'github-copilot\[bot\]'
'copilot-swe-agent'
'devin-ai-integration\[bot\]'
'sweep-ai\[bot\]'
'coderabbit-ai\[bot\]'
'autofix-ci\[bot\]'
'cursor-ai'
'claude@anthropic\.com'
)
FOUND_COMMITS=""
FOUND_ANY=false
while IFS= read -r commit; do
# Check commit messages
msg=$(git show -s --format="%B" "$commit")
author=$(git show -s --format="%an <%ae>" "$commit")
subject=$(git show -s --format="%s" "$commit")
for coauthor_pattern in "${LLM_COAUTHOR_PATTERNS[@]}"; do
if echo "$msg" | grep -iqE "$coauthor_pattern"; then
short=$(git show -s --format="%h" "$commit")
FOUND_COMMITS="${FOUND_COMMITS}\n- \`${short}\` ${subject} (co-author matched: \`${coauthor_pattern}\`)"
FOUND_ANY=true
break
fi
done
# Check commit authors
author_pattern=$(IFS='|'; echo "${LLM_AUTHOR_PATTERNS[*]}")
if echo "$author" | grep -iqE "$author_pattern"; then
short=$(git show -s --format="%h" "$commit")
FOUND_COMMITS="${FOUND_COMMITS}\n- \`${short}\` ${subject} (author matched: \`${author}\`)"
FOUND_ANY=true
fi
done < <(git log --format="%H" "${BASE_SHA}..${HEAD_SHA}")
if $FOUND_ANY; then
REPORT="$(
echo "### LLM co-authorship detected"
echo ""
echo "One or more commits appear to have been (co-)authored by an LLM tool:"
echo ""
echo -e "$FOUND_COMMITS"
)"
echo "$REPORT" >&2
echo "$REPORT" >> "$GITHUB_STEP_SUMMARY"
if [[ "$COMMENT_ON_DETECTION" == "true" ]]; then
gh api "repos/${REPO}/issues/${PR_NUMBER}/comments" \
--method POST \
--field body="$REPORT"
fi
if [[ "$FAIL_ON_DETECTION" == "true" ]]; then
exit 1
fi
fi