conventional-pre-commit 2.2.0__tar.gz → 2.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {conventional_pre_commit-2.2.0 → conventional_pre_commit-2.3.0}/PKG-INFO +1 -1
- {conventional_pre_commit-2.2.0 → conventional_pre_commit-2.3.0}/conventional_pre_commit/format.py +7 -4
- {conventional_pre_commit-2.2.0 → conventional_pre_commit-2.3.0}/conventional_pre_commit/hook.py +5 -2
- {conventional_pre_commit-2.2.0 → conventional_pre_commit-2.3.0}/conventional_pre_commit.egg-info/PKG-INFO +1 -1
- {conventional_pre_commit-2.2.0 → conventional_pre_commit-2.3.0}/pyproject.toml +1 -1
- {conventional_pre_commit-2.2.0 → conventional_pre_commit-2.3.0}/tests/test_format.py +20 -1
- {conventional_pre_commit-2.2.0 → conventional_pre_commit-2.3.0}/tests/test_hook.py +12 -0
- {conventional_pre_commit-2.2.0 → conventional_pre_commit-2.3.0}/LICENSE +0 -0
- {conventional_pre_commit-2.2.0 → conventional_pre_commit-2.3.0}/README.md +0 -0
- {conventional_pre_commit-2.2.0 → conventional_pre_commit-2.3.0}/conventional_pre_commit/__init__.py +0 -0
- {conventional_pre_commit-2.2.0 → conventional_pre_commit-2.3.0}/conventional_pre_commit.egg-info/SOURCES.txt +0 -0
- {conventional_pre_commit-2.2.0 → conventional_pre_commit-2.3.0}/conventional_pre_commit.egg-info/dependency_links.txt +0 -0
- {conventional_pre_commit-2.2.0 → conventional_pre_commit-2.3.0}/conventional_pre_commit.egg-info/entry_points.txt +0 -0
- {conventional_pre_commit-2.2.0 → conventional_pre_commit-2.3.0}/conventional_pre_commit.egg-info/requires.txt +0 -0
- {conventional_pre_commit-2.2.0 → conventional_pre_commit-2.3.0}/conventional_pre_commit.egg-info/top_level.txt +0 -0
- {conventional_pre_commit-2.2.0 → conventional_pre_commit-2.3.0}/setup.cfg +0 -0
{conventional_pre_commit-2.2.0 → conventional_pre_commit-2.3.0}/conventional_pre_commit/format.py
RENAMED
|
@@ -21,9 +21,12 @@ def r_types(types):
|
|
|
21
21
|
return "|".join(types)
|
|
22
22
|
|
|
23
23
|
|
|
24
|
-
def r_scope():
|
|
24
|
+
def r_scope(optional=True):
|
|
25
25
|
"""Regex str for an optional (scope)."""
|
|
26
|
-
|
|
26
|
+
if optional:
|
|
27
|
+
return r"(\([\w \/:-]+\))?"
|
|
28
|
+
else:
|
|
29
|
+
return r"(\([\w \/:-]+\))"
|
|
27
30
|
|
|
28
31
|
|
|
29
32
|
def r_delim():
|
|
@@ -43,7 +46,7 @@ def conventional_types(types=[]):
|
|
|
43
46
|
return types
|
|
44
47
|
|
|
45
48
|
|
|
46
|
-
def is_conventional(input, types=DEFAULT_TYPES):
|
|
49
|
+
def is_conventional(input, types=DEFAULT_TYPES, optional_scope=True):
|
|
47
50
|
"""
|
|
48
51
|
Returns True if input matches Conventional Commits formatting
|
|
49
52
|
https://www.conventionalcommits.org
|
|
@@ -51,7 +54,7 @@ def is_conventional(input, types=DEFAULT_TYPES):
|
|
|
51
54
|
Optionally provide a list of additional custom types.
|
|
52
55
|
"""
|
|
53
56
|
types = conventional_types(types)
|
|
54
|
-
pattern = f"^({r_types(types)}){r_scope()}{r_delim()}{r_subject()}$"
|
|
57
|
+
pattern = f"^({r_types(types)}){r_scope(optional_scope)}{r_delim()}{r_subject()}$"
|
|
55
58
|
regex = re.compile(pattern, re.DOTALL)
|
|
56
59
|
|
|
57
60
|
return bool(regex.match(input))
|
{conventional_pre_commit-2.2.0 → conventional_pre_commit-2.3.0}/conventional_pre_commit/hook.py
RENAMED
|
@@ -20,6 +20,9 @@ def main(argv=[]):
|
|
|
20
20
|
)
|
|
21
21
|
parser.add_argument("types", type=str, nargs="*", default=format.DEFAULT_TYPES, help="Optional list of types to support")
|
|
22
22
|
parser.add_argument("input", type=str, help="A file containing a git commit message")
|
|
23
|
+
parser.add_argument(
|
|
24
|
+
"--force-scope", action="store_false", default=True, dest="optional_scope", help="Force commit to have scope defined."
|
|
25
|
+
)
|
|
23
26
|
|
|
24
27
|
if len(argv) < 1:
|
|
25
28
|
argv = sys.argv[1:]
|
|
@@ -44,7 +47,7 @@ See {Colors.LBLUE}https://git-scm.com/docs/git-commit/#_discussion{Colors.RESTOR
|
|
|
44
47
|
)
|
|
45
48
|
return RESULT_FAIL
|
|
46
49
|
|
|
47
|
-
if format.is_conventional(message, args.types):
|
|
50
|
+
if format.is_conventional(message, args.types, args.optional_scope):
|
|
48
51
|
return RESULT_SUCCESS
|
|
49
52
|
else:
|
|
50
53
|
print(
|
|
@@ -66,7 +69,7 @@ See {Colors.LBLUE}https://git-scm.com/docs/git-commit/#_discussion{Colors.RESTOR
|
|
|
66
69
|
|
|
67
70
|
fix: remove infinite loop
|
|
68
71
|
|
|
69
|
-
{Colors.YELLOW}
|
|
72
|
+
{Colors.YELLOW}Example commit with scope in parentheses after the type for more context:{Colors.RESTORE}
|
|
70
73
|
|
|
71
74
|
fix(account): remove infinite loop"""
|
|
72
75
|
)
|
|
@@ -4,7 +4,6 @@ import pytest
|
|
|
4
4
|
|
|
5
5
|
from conventional_pre_commit import format
|
|
6
6
|
|
|
7
|
-
|
|
8
7
|
CUSTOM_TYPES = ["one", "two"]
|
|
9
8
|
|
|
10
9
|
|
|
@@ -23,6 +22,14 @@ def test_r_scope__optional():
|
|
|
23
22
|
assert regex.match("")
|
|
24
23
|
|
|
25
24
|
|
|
25
|
+
def test_r_scope__not_optional():
|
|
26
|
+
result = format.r_scope(optional=False)
|
|
27
|
+
regex = re.compile(result)
|
|
28
|
+
|
|
29
|
+
# Assert not optional anymore
|
|
30
|
+
assert not regex.match("")
|
|
31
|
+
|
|
32
|
+
|
|
26
33
|
def test_r_scope__parenthesis_required():
|
|
27
34
|
result = format.r_scope()
|
|
28
35
|
regex = re.compile(result)
|
|
@@ -187,6 +194,18 @@ def test_is_conventional__scope_space():
|
|
|
187
194
|
assert not format.is_conventional(input)
|
|
188
195
|
|
|
189
196
|
|
|
197
|
+
def test_is_conventional__scope_not_optional():
|
|
198
|
+
input = "feat: message"
|
|
199
|
+
|
|
200
|
+
assert not format.is_conventional(input, optional_scope=False)
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def test_is_conventional__scope_not_optional_empty_parenthesis():
|
|
204
|
+
input = "feat(): message"
|
|
205
|
+
|
|
206
|
+
assert not format.is_conventional(input, optional_scope=False)
|
|
207
|
+
|
|
208
|
+
|
|
190
209
|
def test_is_conventional__missing_delimiter():
|
|
191
210
|
input = "feat message"
|
|
192
211
|
|
|
@@ -92,3 +92,15 @@ def test_main_fail__conventional_gbk(conventional_gbk_commit_path):
|
|
|
92
92
|
result = main([conventional_gbk_commit_path])
|
|
93
93
|
|
|
94
94
|
assert result == RESULT_FAIL
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def test_main_fail__conventional_with_scope(cmd, conventional_commit_path):
|
|
98
|
+
result = subprocess.call((cmd, "--force-scope", conventional_commit_path))
|
|
99
|
+
|
|
100
|
+
assert result == RESULT_FAIL
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def test_main_success__conventional_with_scope(cmd, conventional_commit_with_scope_path):
|
|
104
|
+
result = subprocess.call((cmd, "--force-scope", conventional_commit_with_scope_path))
|
|
105
|
+
|
|
106
|
+
assert result == RESULT_SUCCESS
|
|
File without changes
|
|
File without changes
|
{conventional_pre_commit-2.2.0 → conventional_pre_commit-2.3.0}/conventional_pre_commit/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|