-
-
Notifications
You must be signed in to change notification settings - Fork 300
feat: add config option for line length warning #1574
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
base: v4-9-0-test
Are you sure you want to change the base?
Changes from 2 commits
6828582
c300b70
c162290
999f298
0c4085e
af6aa62
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
from commitizen import factory, git, out | ||
from commitizen.config import BaseConfig | ||
from commitizen.exceptions import ( | ||
CommitMessageLengthExceededError, | ||
InvalidCommandArgumentError, | ||
InvalidCommitMessageError, | ||
NoCommitsFoundError, | ||
|
@@ -40,7 +41,13 @@ def __init__(self, config: BaseConfig, arguments: CheckArgs, *args: object) -> N | |
self.allow_abort = bool( | ||
arguments.get("allow_abort", config.settings["allow_abort"]) | ||
) | ||
self.max_msg_length = arguments.get("message_length_limit", 0) | ||
|
||
# Use command line argument if provided, otherwise use config setting | ||
cmd_length_limit = arguments.get("message_length_limit") | ||
if cmd_length_limit is None: | ||
self.max_msg_length = config.settings.get("message_length_limit", 0) | ||
else: | ||
self.max_msg_length = cmd_length_limit | ||
|
||
# we need to distinguish between None and [], which is a valid value | ||
allowed_prefixes = arguments.get("allowed_prefixes") | ||
|
@@ -154,6 +161,11 @@ def _validate_commit_message( | |
if self.max_msg_length: | ||
msg_len = len(commit_msg.partition("\n")[0].strip()) | ||
if msg_len > self.max_msg_length: | ||
return False | ||
raise CommitMessageLengthExceededError( | ||
f"commit validation: failed!\n" | ||
f"commit message length exceeds the limit.\n" | ||
f'commit "": "{commit_msg}"\n' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess you forgot to put something like commit hash here in the error message There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You’re right. I referenced the error handling for invalid messages and forgot to add the commit hash. I’ll make the correction. |
||
f"message length limit: {self.max_msg_length} (actual: {msg_len})" | ||
) | ||
|
||
return bool(pattern.match(commit_msg)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,7 @@ class Settings(TypedDict, total=False): | |
ignored_tag_formats: Sequence[str] | ||
legacy_tag_formats: Sequence[str] | ||
major_version_zero: bool | ||
message_length_limit: int | ||
name: str | ||
post_bump_hooks: list[str] | None | ||
pre_bump_hooks: list[str] | None | ||
|
@@ -108,6 +109,7 @@ class Settings(TypedDict, total=False): | |
"always_signoff": False, | ||
"template": None, # default provided by plugin | ||
"extras": {}, | ||
"message_length_limit": 0, # 0 for no limit | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why don't we just use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Initially, I set it to 0 simply because I thought commit messages wouldn't have a 0-character scenario, but your suggestion of using None is more clear. I've made this change accordingly. |
||
} | ||
|
||
MAJOR = "MAJOR" | ||
|
Uh oh!
There was an error while loading. Please reload this page.