Repository navigation
80 lines (62 loc) · 2.14 KB
/
Copy pathcommit-messages.yml
File metadata and controls
80 lines (62 loc) · 2.14 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
name: Commit Messages
on:
push:
pull_request:
workflow_dispatch:
permissions:
contents: read
jobs:
check-messages:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Refuse AI traces
env:
hash_before: ${{ github.event.before }}
hash_base: ${{ github.event.pull_request.base.sha }}
hash_head: ${{ github.event.pull_request.head.sha || github.sha }}
run: |
# patterns to refuse
pattern_insensitive='claude|anthropic|co-authored-by|generated with|generated by|noreply@|openai|chatgpt|copilot|🤖'
pattern_word='(^|[^[:alnum:]])(AI|LLM)([^[:alnum:]]|$)'
pattern_identity='claude|anthropic'
state_found=0
# commits of this push or pull request
if [ -n "${hash_base}" ]
then
range_commits="${hash_base}..${hash_head}"
elif [ -n "${hash_before}" ] &&
[ "${hash_before}" != "0000000000000000000000000000000000000000" ] &&
[ -n "$(git cat-file -t "${hash_before}" 2> /dev/null)" ]
then
range_commits="${hash_before}..${hash_head}"
else
range_commits="-1 ${hash_head}"
fi
mapfile -t list_commits < <(git rev-list ${range_commits})
# check messages and identities
for hash_commit in "${list_commits[@]}"
do
identity_commit="$(git log -1 --format='%an %ae %cn %ce' "${hash_commit}")"
if [[ ${identity_commit,,} =~ ${pattern_identity} ]]
then
echo "::error::${hash_commit:0:8} has an AI identity: ${identity_commit}"
state_found=1
fi
while IFS= read -r line_message
do
if [[ ${line_message,,} =~ ${pattern_insensitive} ]] ||
[[ ${line_message} =~ ${pattern_word} ]]
then
echo "::error::${hash_commit:0:8} has an AI trace: ${line_message}"
state_found=1
fi
done < <(git log -1 --format='%B' "${hash_commit}")
done
echo "checked ${#list_commits[@]} commits"
if [ "${state_found}" = 1 ]
then
exit 1
fi