Skip to content

Commit 322570b

Browse files
committed
Campaign merge: campaign/pr-review-static-checks/task-005
2 parents 040412b + 6187b88 commit 322570b

1 file changed

Lines changed: 81 additions & 0 deletions

File tree

scripts/check-extraneous-files.sh

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
BASE_BRANCH="master"
5+
6+
usage() {
7+
echo "Usage: $(basename "$0") [--base <branch>] [--help]"
8+
echo ""
9+
echo "Checks for extraneous files that should not be committed to the repository."
10+
echo "Compares new files added against the base branch."
11+
echo ""
12+
echo "Options:"
13+
echo " --base <branch> Base branch to compare against (default: master)"
14+
echo " --help Print this usage message"
15+
echo ""
16+
echo "Blocked patterns:"
17+
echo " *_REPORT.md or *_REFERENCE.md at any level (AI-generated reports)"
18+
echo " Top-level *.sh scripts not in scripts/, gradle/, or .gitlab/ directories"
19+
echo " Files named QUICK_REFERENCE* or CHEATSHEET*"
20+
echo " run-*.sh scripts at any level (ad-hoc test runners)"
21+
exit 0
22+
}
23+
24+
while [[ $# -gt 0 ]]; do
25+
case "$1" in
26+
--base)
27+
BASE_BRANCH="$2"
28+
shift 2
29+
;;
30+
--help)
31+
usage
32+
;;
33+
*)
34+
echo "Unknown option: $1" >&2
35+
usage
36+
;;
37+
esac
38+
done
39+
40+
violations=0
41+
42+
while IFS= read -r file; do
43+
reason=""
44+
45+
# Pattern 1: *_REPORT.md or *_REFERENCE.md at any level
46+
basename_file="$(basename "$file")"
47+
if [[ "$basename_file" == *_REPORT.md || "$basename_file" == *_REFERENCE.md ]]; then
48+
reason="AI-generated report/reference file"
49+
fi
50+
51+
# Pattern 2: Top-level *.sh scripts not in scripts/, gradle/, or .gitlab/
52+
if [[ -z "$reason" && "$file" == *.sh ]]; then
53+
dir="$(dirname "$file")"
54+
if [[ "$dir" == "." ]]; then
55+
reason="Top-level shell script (move to scripts/, gradle/, or .gitlab/)"
56+
fi
57+
fi
58+
59+
# Pattern 3: Files named QUICK_REFERENCE* or CHEATSHEET*
60+
if [[ -z "$reason" ]]; then
61+
if [[ "$basename_file" == QUICK_REFERENCE* || "$basename_file" == CHEATSHEET* ]]; then
62+
reason="Quick reference or cheatsheet file"
63+
fi
64+
fi
65+
66+
# Pattern 4: run-*.sh scripts at any level
67+
if [[ -z "$reason" && "$basename_file" == run-*.sh ]]; then
68+
reason="Ad-hoc test runner script (run-*.sh)"
69+
fi
70+
71+
if [[ -n "$reason" ]]; then
72+
echo "BLOCKED: $file$reason"
73+
violations=$((violations + 1))
74+
fi
75+
done < <(git diff --name-only --diff-filter=A "${BASE_BRANCH}...HEAD" 2>/dev/null || git diff --name-only --diff-filter=A "${BASE_BRANCH}" 2>/dev/null)
76+
77+
if [[ $violations -gt 0 ]]; then
78+
exit 1
79+
fi
80+
81+
exit 0

0 commit comments

Comments
 (0)