-
Notifications
You must be signed in to change notification settings - Fork 0
110 lines (95 loc) · 4.52 KB
/
Copy pathcommit-messages.yml
File metadata and controls
110 lines (95 loc) · 4.52 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
# Copyright 2025 Budapest University of Technology and Economics
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Every commit in this repository is a single subject line with no body and no
# trailers, authored by a real person rather than an AI identity. See
# README.md. This check is what makes that a rule rather than a preference.
name: Commits
on:
pull_request:
workflow_dispatch:
concurrency:
# One run for each workflow, branch and event. A new run cancels the run that
# it makes obsolete, so no job continues for a commit that is already old.
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
check:
name: Message and authorship
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
# Need both endpoints of the PR range to enumerate its commits.
fetch-depth: 0
- name: Check every commit in this pull request
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
set -euo pipefail
fail=0
while read -r sha; do
[ -n "$sha" ] || continue
subject=$(git log -1 --format=%s "$sha")
# Strip trailing blank lines before counting, so a message that just
# ends with a newline is not mistaken for having a body.
lines=$(git log -1 --format=%B "$sha" \
| sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' | wc -l)
if [ "$lines" -gt 1 ]; then
echo "::error::${sha:0:8} has a multi-line message. Subject line only — see README.md."
echo " subject: $subject"
fail=1
fi
if git log -1 --format=%B "$sha" | grep -qiE '^\s*(co-authored-by|claude-session|generated-by|signed-off-by-ai)\s*:'; then
echo "::error::${sha:0:8} carries a trailer. Trailers are not used in this repository."
echo " subject: $subject"
fail=1
fi
if git log -1 --format=%B "$sha" | grep -qiE 'claude|copilot|chatgpt|generated with'; then
echo "::error::${sha:0:8} mentions an AI assistant. Commit messages do not carry AI attribution."
echo " subject: $subject"
fail=1
fi
# Commits are attributed to the person responsible for the change,
# never to an assistant that helped write it.
ident=$(git log -1 --format='%an <%ae> / %cn <%ce>' "$sha")
if printf '%s' "$ident" | grep -qiE 'anthropic\.com|noreply@openai|copilot@|@users\.noreply\.github\.com.*bot'; then
echo "::error::${sha:0:8} is authored or committed by an AI identity: $ident"
echo " subject: $subject"
fail=1
fi
done < <(git rev-list --no-merges "$BASE_SHA..$HEAD_SHA")
if [ "$fail" -ne 0 ]; then
{
echo "## Commit message check failed"
echo
echo "Every commit in this repository is a **single subject line** —"
echo "no body, no trailers, no AI attribution — and is authored by a"
echo "real person. See the Contribute section of README.md."
echo
echo "To fix a branch:"
echo '```bash'
echo 'git rebase -i <base> # reword the offending commits'
echo '# or, to strip every body on the branch at once:'
echo 'git filter-branch -f --msg-filter "head -n 1" <base>..HEAD'
echo '# to fix authorship:'
echo 'git config user.name "Your Name" && git config user.email you@example.com'
echo 'git rebase --exec "git commit --amend --no-edit --reset-author" <base>'
echo '```'
} >> "$GITHUB_STEP_SUMMARY"
exit 1
fi
echo "✅ All commits are a single subject line, authored by a person." >> "$GITHUB_STEP_SUMMARY"