Skip to content

Commit

Permalink
common/hooks: Prefill update info in commit msg
Browse files Browse the repository at this point in the history
**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
  • Loading branch information
joebonrichie committed Aug 6, 2024
1 parent 0cec894 commit 481d9de
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions common/Hooks/prepare-commit-msg.py
Original file line number Diff line number Diff line change
@@ -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 = """
Expand All @@ -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 ''
Expand Down

0 comments on commit 481d9de

Please sign in to comment.