diff --git a/templates.py b/templates.py index 185dc13..6286c01 100644 --- a/templates.py +++ b/templates.py @@ -95,6 +95,17 @@ def git_dirty() -> bool: return bool(result.stdout.strip()) +def update_message(answers: Path) -> str: + """Conventional commit for a template update, with the version it moved to.""" + ref = "" + for line in answers.read_text(encoding="utf-8").splitlines(): + if line.startswith("_commit:"): + ref = line.split(":", 1)[1].strip().strip("'\"") + break + scope = answers.stem + return f"chore({scope}): update template to {ref}" if ref else f"chore({scope}): update template" + + def update(args: argparse.Namespace) -> None: answers = sorted(Path(".copier").glob("*.yml")) if args.parts: @@ -108,7 +119,7 @@ def update(args: argparse.Namespace) -> None: skip_answered=not args.ask, defaults=args.defaults, vcs_ref=REF) if git_dirty(): subprocess.run(["git", "add", "-A"], check=True) - subprocess.run(["git", "commit", "-qm", f"Update {file.stem} template"], check=True) + subprocess.run(["git", "commit", "-qm", update_message(file)], check=True) print(f"committed {file.stem} update")