From 481d9defe67bc006b4ee784d580c39f0ab5f56ff Mon Sep 17 00:00:00 2001 From: Joey Riches Date: Tue, 6 Aug 2024 22:40:47 +0100 Subject: [PATCH] common/hooks: Prefill update info in commit msg **Summary** - If the version has been changed in the package.yml as part of the commit then prefill that information in the commit header. e.g. nano: Update to 1.2.3 --- common/Hooks/prepare-commit-msg.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/common/Hooks/prepare-commit-msg.py b/common/Hooks/prepare-commit-msg.py index 4617bb58e454..47b5a1e7ddb7 100755 --- a/common/Hooks/prepare-commit-msg.py +++ b/common/Hooks/prepare-commit-msg.py @@ -1,6 +1,8 @@ #!/usr/bin/env python3 import argparse import os +import subprocess +import yaml scope_help = "# Scope and title, eg: nano: Update to 1.2.3\n" help_msg = """ @@ -21,6 +23,17 @@ def commit_scope(commit_dir: str) -> str: if os.path.exists(os.path.join(commit_dir, 'package.yml')): + + recipe_diff_result = subprocess.run(['git', 'diff', '-U0', '--staged', '--word-diff', os.path.join(commit_dir, 'package.yml')], stdout=subprocess.PIPE) + if "version" in recipe_diff_result.stdout.decode('utf-8'): + with open(os.path.join(commit_dir, 'package.yml')) as recipe: + try: + data = yaml.safe_load(recipe) + version = data['version'] + return os.path.basename(commit_dir) + ': Update to ' + version + except yaml.YAMLError as e: + print(e) + return os.path.basename(commit_dir) + ': ' return ''