#!/usr/bin/env python """commit-msg hook body: reject messages that aren't ``: ``. Invoked by ``.githooks/commit-msg`` with the path to the commit message file. Validation logic lives in :mod:`release.commits` so it is unit-tested. """ from __future__ import annotations import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent)) from release.commits import KNOWN_TYPES, validate_commit_message # noqa: E402 def main(argv: list[str]) -> int: if len(argv) < 2: return 0 message = Path(argv[1]).read_text("utf-8") error = validate_commit_message(message) if error is None: return 0 indented = "\n ".join(error.splitlines()) sys.stderr.write( "\n x Commit rejected: invalid commit message.\n\n" f" {indented}\n\n" f" Format : (): \n" f" Types : {', '.join(KNOWN_TYPES)}\n" " Example: feat(da12): add live sensor sparkline\n\n" ) return 1 if __name__ == "__main__": raise SystemExit(main(sys.argv))