From 66a223d8bfcc82de6ff02b17c0b4d4a4350a7c10 Mon Sep 17 00:00:00 2001 From: Joey Riches Date: Sat, 10 Aug 2024 15:34:10 +0100 Subject: [PATCH] common/Hooks: Pre-fill update info in commit msg - e.g. nano: Update to 1.2.3 --- common/Hooks/prepare-commit-msg.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/common/Hooks/prepare-commit-msg.py b/common/Hooks/prepare-commit-msg.py index 4617bb58e45..d5feb9e7449 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,15 @@ 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', + 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: + version = yaml.safe_load(recipe)['version'] + return os.path.basename(commit_dir) + ': Update to ' + str(version) + return os.path.basename(commit_dir) + ': ' return ''