Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customize commit message #4

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ python3 -m pip install .
python3 -m gitflow_pyproject_version_bumper install
```

Install options:
```
--force overwrite hook if it exists
--commit-message-template COMMIT_MESSAGE_TEMPLATE
commit message when updating the version.
Default: Version bumped to {version}
```
`{version}` - placeholder for the new version.

# Usage
Just start a release, as you usually do:
`git flow release start 1.2.3`
Expand Down
23 changes: 21 additions & 2 deletions gitflow_pyproject_version_bumper/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import git


def install(force: bool) -> None:
def install(force: bool, commit_message_template: str) -> None:
"""
Install git post-checkout hook.

Expand All @@ -23,6 +23,17 @@ def install(force: bool) -> None:
)
exit(-1)

version_bumper_section_name = "versionbumper"
with repo.config_writer() as git_config:
if not git_config.has_section(version_bumper_section_name):
git_config.add_section(version_bumper_section_name)

git_config.set(
section=version_bumper_section_name,
option="commitmessagetemplate",
value=commit_message_template,
)

shutil.copyfile(src, dst)
dst.chmod(dst.stat().st_mode | stat.S_IEXEC)

Expand Down Expand Up @@ -55,14 +66,22 @@ def main() -> None:
default=False,
help="overwrite hook if it exists",
)
install_cmd_parser.add_argument(
"--commit-message-template",
dest="commit_message_template",
action="store",
default="Version bumped to {version}",
help="commit message when updating the version. "
"Default: Version bumped to {version}",
)
args, _ = parser.parse_known_args()

if args.subcommand is None:
parser.print_help()
return

if args.subcommand == "install":
install(args.force_install)
install(args.force_install, args.commit_message_template)


if __name__ == "__main__":
Expand Down
10 changes: 7 additions & 3 deletions gitflow_pyproject_version_bumper/post_checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

BRANCH_CHECKOUT_TYPE = "1"

_, _, _, checkout_type = sys.argv
checkout_type = sys.argv[-1]
if checkout_type != BRANCH_CHECKOUT_TYPE:
exit()

Expand All @@ -29,6 +29,11 @@
option="hotfix",
fallback="hotfix/",
)
commit_message_template = git_config.get(
section="versionbumper",
option="commitmessagetemplate",
fallback="Version bumped to {version}",
)

if head.name.startswith(gitflow_release_prefix):
new_version = repo.active_branch.name[len(gitflow_release_prefix) :]
Expand All @@ -48,5 +53,4 @@
tomlkit.dump(pyproject, f)

repo.index.add(str(pyproject_toml_path))
commit_message = f"Version bumped to {new_version}"
repo.index.commit(commit_message)
repo.index.commit(commit_message_template.format(version=new_version))