mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-05 03:26:53 +00:00
Allow for more control in template variables
Sepearate commit message coming from git for handling in template.
This commit is contained in:
parent
f072bb622f
commit
912f1a5f41
4 changed files with 53 additions and 6 deletions
|
|
@ -47,7 +47,7 @@ def _get_default_template() -> str:
|
|||
|
||||
def get_rendered_template(
|
||||
template_file: str,
|
||||
variables: dict[str, str],
|
||||
variables: dict[str, Sequence[str]],
|
||||
) -> str:
|
||||
with open(template_file) as f:
|
||||
template = Template(f.read())
|
||||
|
|
@ -63,6 +63,8 @@ def update_commit_file(
|
|||
with open(commit_msg_file) as f:
|
||||
data = f.readlines()
|
||||
|
||||
commented = list(filter(lambda line: line.startswith('#'), data))
|
||||
original = list(filter(lambda line: not line.startswith('#'), data))
|
||||
data_as_str = ''.join([item for item in data])
|
||||
# if message already contain ticket number means
|
||||
# it is under git commit --amend or rebase or alike
|
||||
|
|
@ -73,6 +75,8 @@ def update_commit_file(
|
|||
variables = {
|
||||
'ticket': ticket,
|
||||
'content': data_as_str,
|
||||
'commented': commented,
|
||||
'original_msg': original,
|
||||
}
|
||||
|
||||
content = get_rendered_template(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue