ops: reduce comment density in PR #4433
Cut commentary from 104 to 24 lines across the new lint script, CI config, and pre-push hook. Kept only: policy reference, why pattern is loose, why scope is PR commits not history, and non-obvious CI behavior notes. No logic lines changed. Refs #4432
This commit is contained in:
parent
bf8e309b19
commit
5bd68f9b8a
3 changed files with 19 additions and 99 deletions
|
|
@ -1,69 +1,43 @@
|
|||
#!/bin/sh
|
||||
# CI lint: flags Co-Authored-By trailers with Claude/Anthropic attribution in
|
||||
# PR commits. The hive convention in /knowledge/hive-rules.md forbids these
|
||||
# trailers — an attribution line in a prompt is not a control. This gate is.
|
||||
# Flags Co-Authored-By trailers with Claude/Anthropic attribution in PR commits.
|
||||
# The hive convention in /knowledge/hive-rules.md forbids these trailers.
|
||||
#
|
||||
# Emits a CI error annotation per offending commit and exits 1 if any commit
|
||||
# in the PR's range carries a prohibited trailer. Runs as its own CI job and
|
||||
# IS a required check on the forge (branch protection) — a hit blocks merge.
|
||||
# Pattern is loose (case-insensitive, matches `claude`, `anthropic`, or
|
||||
# `noreply@anthropic.com` anywhere after `co-authored-by`) to cover variants
|
||||
# like `Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>`.
|
||||
#
|
||||
# Pattern: case-insensitive `co-authored-by` followed by `claude`, `anthropic`,
|
||||
# or `noreply@anthropic.com` anywhere in the line. Covers variants seen in the
|
||||
# wild: `Co-Authored-By: Claude`, `Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>`.
|
||||
#
|
||||
# Scope: commits in the PR's range (BASE..HEAD), not the entire history — old
|
||||
# commits must not fail the build. In CI, BASE is the target branch
|
||||
# (GITHUB_BASE_REF / github.event.pull_request.base.ref in GH Actions; similar
|
||||
# vars in Forgejo). Falls back to origin/main for local runs.
|
||||
# Scope is the PR's commits (BASE..HEAD), not entire history — old commits
|
||||
# must not fail the build.
|
||||
set -eu
|
||||
|
||||
# Determine base ref: in CI (pull_request event), use the PR's base branch;
|
||||
# locally, default to origin/main. CI env vars: GITHUB_BASE_REF (GitHub
|
||||
# Actions), similar for Forgejo/Gitea (not standardized across runners, so we
|
||||
# check both common patterns).
|
||||
if [ -n "${GITHUB_BASE_REF:-}" ]; then
|
||||
# GitHub Actions / Forgejo Actions pull_request context
|
||||
base="origin/${GITHUB_BASE_REF}"
|
||||
elif [ -n "${CI_COMMIT_REF_NAME:-}" ]; then
|
||||
# GitLab-style variable (some Forgejo setups)
|
||||
base="origin/main"
|
||||
else
|
||||
# Local run or unknown CI — default to origin/main
|
||||
base="origin/main"
|
||||
fi
|
||||
|
||||
# Ensure the base ref exists (in CI, actions/checkout@v3 fetches the PR head
|
||||
# but may not fetch the base branch by default — fetch it if missing).
|
||||
# actions/checkout@v3 fetches the PR head but may not fetch the base branch
|
||||
if ! git rev-parse --verify "$base" >/dev/null 2>&1; then
|
||||
# Extract branch name and fetch it
|
||||
branch="${base#origin/}"
|
||||
git fetch origin "$branch" 2>/dev/null || true
|
||||
# If still missing, fall back to main
|
||||
if ! git rev-parse --verify "$base" >/dev/null 2>&1; then
|
||||
base="origin/main"
|
||||
git fetch origin main 2>/dev/null || base="HEAD~10"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Get all commits in the PR's range. `--reverse` lists oldest first (clearer
|
||||
# for annotation output). `--format=%H` gets the full commit sha.
|
||||
commits="$(git log --reverse --format='%H' "${base}..HEAD" 2>/dev/null || true)"
|
||||
|
||||
if [ -z "$commits" ]; then
|
||||
# No commits in range — either not on a PR branch, or nothing new. Pass.
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Check each commit's full message for the prohibited trailer pattern.
|
||||
# Case-insensitive grep for `co-authored-by` + any of `claude`, `anthropic`,
|
||||
# `noreply@anthropic.com`.
|
||||
hits=""
|
||||
for sha in $commits; do
|
||||
msg="$(git log -1 --format='%B' "$sha")"
|
||||
# Match case-insensitive co-authored-by AND (claude OR anthropic OR noreply@anthropic.com)
|
||||
# Use grep -E with -i for case-insensitive matching
|
||||
if printf '%s\n' "$msg" | grep -qiE 'co-authored-by.*claude|co-authored-by.*anthropic|co-authored-by.*noreply@anthropic\.com'; then
|
||||
# Found a hit — build annotation
|
||||
subject="$(git log -1 --format='%s' "$sha")"
|
||||
hits="${hits}${sha}|${subject}
|
||||
"
|
||||
|
|
|
|||
Loading…
Reference in a new issue