Skip to content
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
7 changes: 4 additions & 3 deletions conventional_pre_commit/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ def r_types(self):
@property
def r_scope(self):
"""Regex str for an optional (scope)."""
escaped_delimiters = list(map(re.escape, [":", ",", "-", "/", "."])) # type: ignore
if self.scopes:
scopes = self._r_or(self.scopes)
escaped_delimiters = list(map(re.escape, [":", ",", "-", "/"])) # type: ignore
delimiters_pattern = self._r_or(escaped_delimiters)
scope_pattern = rf"\(\s*(?:(?i:{scopes}))(?:\s*(?:{delimiters_pattern})\s*(?:(?i:{scopes})))*\s*\)"

Expand All @@ -137,10 +137,11 @@ def r_scope(self):
else:
return scope_pattern

joined_delimiters = "".join(escaped_delimiters)
if self.scope_optional:
return r"(\([\w \/:,-]+\))?"
return rf"(\([\w {joined_delimiters}]+\))?"
else:
return r"(\([\w \/:,-]+\))"
return rf"(\([\w {joined_delimiters}]+\))"

@property
def r_delim(self):
Expand Down
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ def conventional_utf8_commit_path():
return get_message_path("conventional_commit_utf-8")


@pytest.fixture
def conventional_commit_with_dots_path():
return get_message_path("conventional_commit_with_dots")


@pytest.fixture
def conventional_gbk_commit_path():
return get_message_path("conventional_commit_gbk")
Expand Down
1 change: 1 addition & 0 deletions tests/messages/conventional_commit_with_dots
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
feat(customer.registration): adds support for oauth2
13 changes: 13 additions & 0 deletions tests/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ def test_r_scope__special_chars(conventional_commit_scope_required):
assert regex.match("(some thing)")
assert regex.match("(some:thing)")
assert regex.match("(some,thing)")
assert regex.match("(some.thing)")


def test_r_scope__scopes(conventional_commit_scope_required):
Expand All @@ -455,6 +456,7 @@ def test_r_scope__scopes(conventional_commit_scope_required):
assert regex.match("(api: client)")
assert regex.match("(api/client)")
assert regex.match("(api-client)")
assert regex.match("(api.client)")
assert not regex.match("(test)")
assert not regex.match("(api; client)")

Expand All @@ -469,6 +471,7 @@ def test_r_scope__scopes_uppercase(conventional_commit_scope_required):
assert regex.match("(API: CLIENT)")
assert regex.match("(API/CLIENT)")
assert regex.match("(API-CLIENT)")
assert regex.match("(API.CLIENT)")
assert not regex.match("(TEST)")
assert not regex.match("(API; CLIENT)")

Expand Down Expand Up @@ -557,6 +560,16 @@ def test_match_multiline(conventional_commit):
assert match.group("body").strip() == "body copy"


def test_match_dots(conventional_commit):
match = conventional_commit.match("""feat(foo.bar): hello world""")
assert isinstance(match, re.Match)
assert match.group("type") == "feat"
assert match.group("scope") == "(foo.bar)"
assert match.group("delim") == ":"
assert match.group("subject").strip() == "hello world"
assert match.group("body").strip() == ""


def test_match_invalid_type(conventional_commit):
match = conventional_commit.match(
"""invalid(scope): subject line
Expand Down
6 changes: 6 additions & 0 deletions tests/test_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ def test_main_success__conventional_utf8(conventional_utf8_commit_path):
assert result == RESULT_SUCCESS


def test_main_success__conventional_commit_with_dots_path(conventional_commit_with_dots_path):
result = main([conventional_commit_with_dots_path])

assert result == RESULT_SUCCESS


def test_main_fail__conventional_gbk(conventional_gbk_commit_path):
result = main([conventional_gbk_commit_path])

Expand Down
Loading