default_install_hook_types: [pre-commit, commit-msg]
repos:
- repo: local
hooks:
- id: no-internal-references
name: No internal references in docs
language: pygrep
entry: '\b(?i:LAB)-[0-9]+|op://|\.ts\.net|(?i:\bk3s[\s_-]+(?:cluster|node|host)s?\b)|dev\.cachekit\.io|\bStage [0-9]|\bAC-[0-9]|github\.com/cachekit(?![\w-])'
files: ^((packages|crates)/[^/]+/)?README[^/]*$|^docs/
types: [text]
stages: [pre-commit]
- id: no-internal-references-commit-msg
name: No internal references in commit message
language: python
entry: python -c
args:
- |
import re, sys
P = re.compile(r"\b(?i:LAB)-[0-9]+|op://|\.ts\.net|(?i:\bk3s[\s_-]+(?:cluster|node|host)s?\b)|dev\.cachekit\.io|\bStage [0-9]|\bAC-[0-9]|github\.com/cachekit(?![\w-])")
KIND = r"(?:branch|branches|remote-tracking branch|remote-tracking branches|tag|tags|commit|commits)"
GIT_SUBJECT = re.compile(rf"Merge {KIND} '[^']*'(?:(?:, |; | and ){KIND}? ?'[^']*')*(?: of \S+)?(?: into \S+)?|(?:Revert|Reapply) \".*\"")
try:
with open(sys.argv[1], encoding="utf-8", errors="replace") as f:
text = f.read()
except OSError as e:
sys.exit(f"{sys.argv[1]}: cannot read the commit message: {e}")
text = text.split("# ------------------------ >8 ------------------------")[0]
lines = [line for line in text.splitlines() if line.strip() and not re.match(r"#(?:[ \t]|$)", line)]
if lines and GIT_SUBJECT.fullmatch(lines[0]):
lines = lines[1:]
bad = [line for line in lines if P.search(line)]
for line in bad:
print(f"{sys.argv[1]}: {line}")
sys.exit(1 if bad else 0)
stages: [commit-msg]