From 7d842f9a2be21bb8e6e9bd8deccd42a936566d17 Mon Sep 17 00:00:00 2001 From: Ingo Fruend Date: Thu, 31 Aug 2023 15:09:56 +0200 Subject: [PATCH 1/5] test(parse): Expose issue --- tests/unit/test_commit_parsing.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/unit/test_commit_parsing.py b/tests/unit/test_commit_parsing.py index b8ac861..af311dc 100644 --- a/tests/unit/test_commit_parsing.py +++ b/tests/unit/test_commit_parsing.py @@ -25,3 +25,9 @@ def test_scope_may_include_dash(self): assert p.parse( RawCommit(sha='any sha', title='feat(any-scope): Message', body='') ) == Commit(sha='any sha', type='feat', scope='any-scope', breaking=False) + + def test_no_scope(self): + p = AngularCommitParser() + assert p.parse( + RawCommit(sha='any sha', title='feat: No scope', body='') + ) == Commit(sha='any sha', type='feat', scope=':global:', breaking=False) From 62296b9bef8a2d2780268125b10569e81524dc67 Mon Sep 17 00:00:00 2001 From: Ingo Fruend Date: Thu, 31 Aug 2023 15:47:06 +0200 Subject: [PATCH 2/5] feat(parse): Can handle commits without explicit scope --- src/semv/parse.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/semv/parse.py b/src/semv/parse.py index 2d0297c..e6c7c1b 100644 --- a/src/semv/parse.py +++ b/src/semv/parse.py @@ -13,7 +13,7 @@ def __init__( skip_commit_patterns: Set[str] = set(), ): self.type_and_scope_pattern = re.compile( - r'(?P\w+)\((?P[a-zA-Z-_]+)\): .*' + r'(?P\w+)\(?(?P[a-zA-Z-_]*)\)?: .*' ) self.breaking_pattern = re.compile( r'BREAKING CHANGE: .*', flags=re.DOTALL @@ -42,7 +42,7 @@ def parse(self, commit: RawCommit) -> Optional[Commit]: @staticmethod def _prepare_commit(m: re.Match, sha: str, breaking: bool) -> Commit: type = m.group('type') - scope = m.group('scope') + scope = m.group('scope') or ':global:' return Commit(sha=sha, type=type, scope=scope, breaking=breaking) def should_skip_by_pattern(self, title: str) -> bool: From 289a3386be0c02f515a658ef17d590726ee39ed7 Mon Sep 17 00:00:00 2001 From: Ingo Fruend Date: Thu, 31 Aug 2023 15:47:34 +0200 Subject: [PATCH 3/5] test(unit): Check that we can't fake the no-scope thing --- tests/unit/test_commit_parsing.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/tests/unit/test_commit_parsing.py b/tests/unit/test_commit_parsing.py index af311dc..a832030 100644 --- a/tests/unit/test_commit_parsing.py +++ b/tests/unit/test_commit_parsing.py @@ -1,5 +1,7 @@ +import pytest from semv.interface import RawCommit, Commit -from semv.parse import AngularCommitParser +from semv import errors +from semv.parse import AngularCommitParser, InvalidCommitAction class TestAngularCommitParser: @@ -8,26 +10,42 @@ def test_non_breaking(self): assert p.parse( RawCommit(sha='any sha', title='feat(scope): Message', body='') ) == Commit(sha='any sha', type='feat', scope='scope', breaking=False) + def test_breaking(self): p = AngularCommitParser() assert p.parse( - RawCommit(sha='any sha', title='feat(scope): Message', body='BREAKING CHANGE: bla bla') + RawCommit( + sha='any sha', + title='feat(scope): Message', + body='BREAKING CHANGE: bla bla', + ) ) == Commit(sha='any sha', type='feat', scope='scope', breaking=True) def test_scope_may_include_underscore(self): p = AngularCommitParser() assert p.parse( RawCommit(sha='any sha', title='feat(any_scope): Message', body='') - ) == Commit(sha='any sha', type='feat', scope='any_scope', breaking=False) + ) == Commit( + sha='any sha', type='feat', scope='any_scope', breaking=False + ) def test_scope_may_include_dash(self): p = AngularCommitParser() assert p.parse( RawCommit(sha='any sha', title='feat(any-scope): Message', body='') - ) == Commit(sha='any sha', type='feat', scope='any-scope', breaking=False) + ) == Commit( + sha='any sha', type='feat', scope='any-scope', breaking=False + ) def test_no_scope(self): p = AngularCommitParser() assert p.parse( RawCommit(sha='any sha', title='feat: No scope', body='') - ) == Commit(sha='any sha', type='feat', scope=':global:', breaking=False) + ) == Commit( + sha='any sha', type='feat', scope=':global:', breaking=False + ) + + def test_break_scope_with_no_parens(self): + p = AngularCommitParser(InvalidCommitAction.error) + with pytest.raises(errors.InvalidCommitFormat): + p.parse(RawCommit(sha='any sha', title='feat-notscope:', body='')) From 74c6bbc828296634b5e8dfd896c53163c93b5fdf Mon Sep 17 00:00:00 2001 From: Ingo Fruend Date: Thu, 31 Aug 2023 15:54:18 +0200 Subject: [PATCH 4/5] docs(mkdocs): Note that the scope is no longer mandatory --- docs/commit_parsing.md | 46 ++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/docs/commit_parsing.md b/docs/commit_parsing.md index 83c8926..755b9d2 100644 --- a/docs/commit_parsing.md +++ b/docs/commit_parsing.md @@ -9,32 +9,49 @@ Specifically, every commit message should have the following structure: