implement -c/--commit-message

This commit is contained in:
Manuel Barkhau 2021-05-13 17:07:31 +00:00 committed by mbarkhau
parent 9b9748a816
commit bf030d4fa0
2 changed files with 68 additions and 16 deletions

View file

@ -6,6 +6,7 @@
# SPDX-License-Identifier: MIT
"""cli module for BumpVer."""
import io
import re
import sys
import typing as typ
import logging
@ -687,9 +688,16 @@ def _update_cfg_from_vcs(cfg: config.Config, fetch: bool) -> config.Config:
),
)
@version_options
@click.option(
"-c",
"--commit-message",
default=None,
metavar="<MESSAGE>",
help="Set commit message.",
)
def update(
dry : bool = False,
allow_dirty: bool = False,
allow_dirty : bool = False,
fetch : bool = True,
verbose : int = 0,
major : bool = False,
@ -699,7 +707,8 @@ def update(
tag_num : bool = False,
pin_date : bool = False,
date : typ.Optional[str] = None,
set_version: typ.Optional[str] = None,
set_version : typ.Optional[str] = None,
commit_message: typ.Optional[str] = None,
) -> None:
"""Update project files with the incremented version string."""
verbose = max(_VERBOSE, verbose)
@ -747,18 +756,25 @@ def update(
if dry or verbose >= 2:
_print_diff(cfg, new_version)
if dry:
return
if commit_message is None:
commit_msg_template = cfg.commit_message
else:
commit_msg_template, _ = re.subn(r"\b(OLD|NEW)\b", r"{\1_VERSION}", commit_message)
commit_message_kwargs = {
'new_version' : new_version,
'old_version' : old_version,
'NEW_VERSION' : new_version,
'OLD_VERSION' : old_version,
'new_version_pep440': version.to_pep440(new_version),
'old_version_pep440': version.to_pep440(old_version),
}
commit_message = cfg.commit_message.format(**commit_message_kwargs)
try_commit_message = commit_msg_template.format(**commit_message_kwargs)
_try_update(cfg, new_version, commit_message, allow_dirty)
if dry:
return
_try_update(cfg, new_version, try_commit_message, allow_dirty)
if __name__ == '__main__':

View file

@ -890,6 +890,42 @@ def test_git_commit_message(runner, caplog):
assert expected in commits[1]
def test_cli_commit_message(runner, caplog):
_add_project_files("README.md", "setup.cfg")
result = runner.invoke(cli.cli, ['init', "-vv"])
assert result.exit_code == 0
_update_config_val(
"setup.cfg",
current_version='"v2019.1001-alpha"',
version_pattern="vYYYY.BUILD[-TAG]",
)
_vcs_init("git", ["README.md", "setup.cfg"])
assert len(caplog.records) > 0
cmd = [
'update',
"-vv",
"--pin-date",
"--tag",
"beta",
"--commit-message",
"my custom message (OLD -> NEW)",
]
result = runner.invoke(cli.cli, cmd)
assert result.exit_code == 0
tags = shell("git", "tag", "--list").decode("utf-8")
assert "v2019.1002-beta" in tags
commits = shell(*shlex.split("git log -l 2")).decode("utf-8").split("\n\n")
expected = "my custom message (v2019.1001-alpha -> v2019.1002-beta)"
assert expected in commits[1]
def test_grep(runner):
_add_project_files("README.md")