-
-
Notifications
You must be signed in to change notification settings - Fork 288
Customize committing and bumping through toml file #72
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
746dd87
feat(cz/cz_customize): implement customizable cz
Lee-W 78aa985
feat(cz/cz_customize): enable bump_pattern bump_map customization
Lee-W 088e24f
feat(cz/cz_customize): implement info to support info and info_path
Lee-W c1f3235
test(cz/cz_customize): Change the value for choices
Lee-W f863eae
docs(cz/cz_customize): description for newly added customization func…
Lee-W e4c93d0
fix(scripts): add back the delelte poetry prefix
Lee-W File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .customize import CustomizeCommitsCz # noqa |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from commitizen import defaults | ||
from commitizen.cz.base import BaseCommitizen | ||
|
||
__all__ = ["CustomizeCommitsCz"] | ||
|
||
|
||
class CustomizeCommitsCz(BaseCommitizen): | ||
bump_pattern = defaults.bump_pattern | ||
bump_map = defaults.bump_map | ||
|
||
def __init__(self, config: dict): | ||
super(CustomizeCommitsCz, self).__init__(config) | ||
self.custom_config = self.config.get("customize") | ||
|
||
custom_bump_pattern = self.custom_config.get("bump_pattern") | ||
if custom_bump_pattern: | ||
self.bump_pattern = custom_bump_pattern | ||
|
||
custom_bump_map = self.custom_config.get("bump_map") | ||
if custom_bump_map: | ||
self.bump_map = custom_bump_map | ||
|
||
def questions(self) -> list: | ||
return self.custom_config.get("questions") | ||
|
||
def message(self, answers: dict) -> str: | ||
message_template = self.custom_config.get("message_template") | ||
return message_template.format(**answers) | ||
|
||
def example(self) -> str: | ||
return self.custom_config.get("example") | ||
|
||
def schema(self) -> str: | ||
return self.custom_config.get("schema") | ||
|
||
def info(self) -> str: | ||
info_path = self.custom_config.get("info_path") | ||
info = self.custom_config.get("info") | ||
if info_path: | ||
with open(info_path, "r") as f: | ||
content = f.read() | ||
return content | ||
elif info: | ||
return info | ||
raise NotImplementedError("Not Implemented yet") |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import pytest | ||
from tomlkit import parse | ||
|
||
from commitizen.cz.customize import CustomizeCommitsCz | ||
from commitizen.config import Config | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def config(): | ||
_conf = Config() | ||
toml_str = """ | ||
[tool.commitizen.customize] | ||
# message_template should follow the python string formatting spec | ||
message_template = "{change_type}: {message}" | ||
example = "feature: this feature eanable customize through config file" | ||
schema = "<type>: <body>" | ||
bump_pattern = "^(break|new|fix|hotfix)" | ||
bump_map = {"break" = "MAJOR", "new" = "MINOR", "fix" = "PATCH", "hotfix" = "PATCH"} | ||
info = "This is a customized cz." | ||
|
||
[[tool.commitizen.customize.questions]] | ||
type = "list" | ||
name = "change_type" | ||
choices = [ | ||
{value = "feature", name = "feature: A new feature."}, | ||
{value = "bug fix", name = "bug fix: A bug fix."} | ||
] | ||
message = "Select the type of change you are committing" | ||
|
||
[[tool.commitizen.customize.questions]] | ||
type = "input" | ||
name = "message" | ||
message = "Body." | ||
""" | ||
_conf.update(parse(toml_str)["tool"]["commitizen"]) | ||
return _conf.config | ||
|
||
|
||
def test_bump_pattern(config): | ||
cz = CustomizeCommitsCz(config) | ||
assert cz.bump_pattern == "^(break|new|fix|hotfix)" | ||
|
||
|
||
def test_bump_map(config): | ||
cz = CustomizeCommitsCz(config) | ||
assert cz.bump_map == { | ||
"break": "MAJOR", | ||
"new": "MINOR", | ||
"fix": "PATCH", | ||
"hotfix": "PATCH", | ||
} | ||
|
||
|
||
def test_questions(config): | ||
cz = CustomizeCommitsCz(config) | ||
questions = cz.questions() | ||
expected_questions = [ | ||
{ | ||
"type": "list", | ||
"name": "change_type", | ||
"choices": [ | ||
{"value": "feature", "name": "feature: A new feature."}, | ||
{"value": "bug fix", "name": "bug fix: A bug fix."}, | ||
], | ||
"message": "Select the type of change you are committing", | ||
}, | ||
{"type": "input", "name": "message", "message": "Body."}, | ||
] | ||
assert list(questions) == expected_questions | ||
|
||
|
||
def test_answer(config): | ||
cz = CustomizeCommitsCz(config) | ||
answers = { | ||
"change_type": "feature", | ||
"message": "this feature eanable customize through config file", | ||
} | ||
message = cz.message(answers) | ||
assert message == "feature: this feature eanable customize through config file" | ||
|
||
|
||
def test_example(config): | ||
cz = CustomizeCommitsCz(config) | ||
assert "feature: this feature eanable customize through config file" in cz.example() | ||
|
||
|
||
def test_schema(config): | ||
cz = CustomizeCommitsCz(config) | ||
assert "<type>: <body>" in cz.schema() | ||
|
||
|
||
def test_info(config): | ||
cz = CustomizeCommitsCz(config) | ||
assert "This is a customized cz." in cz.info() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet!