Skip to content

Commit 22d377a

Browse files
committed
fix: fixed scopes option by making it a flag
Refs: #101, #102
1 parent f51f662 commit 22d377a

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

conventional_pre_commit/hook.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ def main(argv=[]):
2828
action="store_true",
2929
help="Force commit to strictly follow Conventional Commits formatting. Disallows fixup! style commits.",
3030
)
31-
parser.add_argument("scopes", type=str, nargs="*", default=None, help="Optional list of scopes to support")
31+
parser.add_argument(
32+
"--scopes",
33+
type=str,
34+
default=None,
35+
help="Optional list of scopes to support. Scopes should be separated by commas with no spaces (e.g. api,client)",
36+
)
3237

3338
if len(argv) < 1:
3439
argv = sys.argv[1:]
@@ -52,12 +57,16 @@ def main(argv=[]):
5257
"""
5358
)
5459
return RESULT_FAIL
60+
if args.scopes:
61+
scopes = args.scopes.split(",")
62+
else:
63+
scopes = args.scopes
5564

5665
if not args.strict:
5766
if format.has_autosquash_prefix(message):
5867
return RESULT_SUCCESS
5968

60-
if format.is_conventional(message, args.types, args.optional_scope, args.scopes):
69+
if format.is_conventional(message, args.types, args.optional_scope, scopes):
6170
return RESULT_SUCCESS
6271
else:
6372
print(

tests/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,8 @@ def conventional_commit_bad_multi_line_path():
5252
@pytest.fixture
5353
def conventional_commit_multi_line_path():
5454
return get_message_path("conventional_commit_multi_line")
55+
56+
57+
@pytest.fixture
58+
def conventional_commit_with_multiple_scopes_path():
59+
return get_message_path("conventional_commit_with_multiple_scopes")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
feat(api,client): added new endpoint with client support

tests/test_hook.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,16 @@ def test_subprocess_success__conventional_with_scope(cmd, conventional_commit_wi
142142
assert result == RESULT_SUCCESS
143143

144144

145+
def test_subprocess_success__conventional_with_multiple_scopes(cmd, conventional_commit_with_multiple_scopes_path):
146+
result = subprocess.call((cmd, "--scopes", "api,client", conventional_commit_with_multiple_scopes_path))
147+
assert result == RESULT_SUCCESS
148+
149+
150+
def test_subprocess_fail__conventional_with_multiple_scopes(cmd, conventional_commit_with_multiple_scopes_path):
151+
result = subprocess.call((cmd, "--scopes", "api", conventional_commit_with_multiple_scopes_path))
152+
assert result == RESULT_FAIL
153+
154+
145155
def test_subprocess_success__fixup_commit(cmd, fixup_commit_path):
146156
result = subprocess.call((cmd, fixup_commit_path))
147157

0 commit comments

Comments
 (0)