Skip to content

Commit 7385e19

Browse files
committed
fix: correctly detect major version, for both angular style and basic style
- fixed BREAK_REGEX to work on multiline commits - added unit tests
1 parent eb80522 commit 7385e19

3 files changed

Lines changed: 72 additions & 6 deletions

File tree

src/git_changelog/style.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class BasicStyle(CommitStyle):
1717
}
1818

1919
TYPE_REGEX = re.compile(r"^(?P<type>(%s))" % "|".join(TYPES.keys()), re.I)
20-
BREAK_REGEX = re.compile(r"^break(s|ing changes)?[ :].+$", re.I)
20+
BREAK_REGEX = re.compile(r"^break(s|ing changes?)?[ :].+$", re.I | re.MULTILINE)
2121

2222
def parse_commit(self, commit):
2323
commit_type = self.parse_type(commit.subject)
@@ -38,7 +38,7 @@ def is_minor(self, commit_type):
3838
return commit_type == self.TYPES["add"]
3939

4040
def is_major(self, commit_message):
41-
return bool(self.BREAK_REGEX.match(commit_message))
41+
return bool(self.BREAK_REGEX.search(commit_message))
4242

4343

4444
class AngularStyle(CommitStyle):
@@ -56,7 +56,7 @@ class AngularStyle(CommitStyle):
5656
# 'chore': '',
5757
}
5858
SUBJECT_REGEX = re.compile(r"^(?P<type>(%s))(?:\((?P<scope>.+)\))?: (?P<subject>.+)$" % ("|".join(TYPES.keys())))
59-
BREAK_REGEX = re.compile(r"^break(s|ing changes)?[ :].+$", re.I)
59+
BREAK_REGEX = re.compile(r"^break(s|ing changes?)?[ :].+$", re.I | re.MULTILINE)
6060

6161
def parse_commit(self, commit):
6262
subject = self.parse_subject(commit.subject)
@@ -86,7 +86,7 @@ def is_minor(self, commit_type):
8686
return commit_type == self.TYPES["feat"]
8787

8888
def is_major(self, commit_message):
89-
return bool(self.BREAK_REGEX.match(commit_message))
89+
return bool(self.BREAK_REGEX.search(commit_message))
9090

9191

9292
class AtomStyle(CommitStyle):

tests/test_angular_style.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,31 @@
22
from git_changelog.style import AngularStyle
33

44

5+
def test_angular_style_breaking_change():
6+
subject = "feat: this is a new breaking feature"
7+
body = ["BREAKING CHANGE: there is a breaking feature in this code"]
8+
commit = Commit(hash="aaaaaaa", subject=subject, body=body, author_date="1574340645", committer_date="1574340645")
9+
style = AngularStyle()
10+
commit_dict = style.parse_commit(commit)
11+
assert commit_dict["is_major"]
12+
assert not commit_dict["is_minor"]
13+
assert not commit_dict["is_patch"]
14+
15+
16+
def test_angular_style_breaking_changes():
17+
subject = "feat: this is a new breaking feature"
18+
body = ["BREAKING CHANGES: there is a breaking feature in this code"]
19+
commit = Commit(hash="aaaaaaa", subject=subject, body=body, author_date="1574340645", committer_date="1574340645")
20+
style = AngularStyle()
21+
commit_dict = style.parse_commit(commit)
22+
assert commit_dict["is_major"]
23+
assert not commit_dict["is_minor"]
24+
assert not commit_dict["is_patch"]
25+
26+
527
def test_angular_style_feat():
628
subject = "feat: this is a new feature"
7-
commit = Commit("aaaaaaa", subject=subject, author_date="1574340645", committer_date="1574340645",)
29+
commit = Commit(hash="aaaaaaa", subject=subject, author_date="1574340645", committer_date="1574340645")
830
style = AngularStyle()
931
commit_dict = style.parse_commit(commit)
1032
assert not commit_dict["is_major"]
@@ -14,7 +36,7 @@ def test_angular_style_feat():
1436

1537
def test_angular_style_fix():
1638
subject = "fix: this is a bug fix"
17-
commit = Commit("aaaaaaa", subject=subject, author_date="1574340645", committer_date="1574340645",)
39+
commit = Commit(hash="aaaaaaa", subject=subject, author_date="1574340645", committer_date="1574340645")
1840
style = AngularStyle()
1941
commit_dict = style.parse_commit(commit)
2042
assert not commit_dict["is_major"]

tests/test_basic_style.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from git_changelog.build import Commit
2+
from git_changelog.style import BasicStyle
3+
4+
5+
def test_basic_style_breaking_change():
6+
subject = "Added a new breaking feature"
7+
body = ["BREAKING CHANGE: there is a breaking feature in this code"]
8+
commit = Commit(hash="aaaaaaa", subject=subject, body=body, author_date="1574340645", committer_date="1574340645")
9+
style = BasicStyle()
10+
commit_dict = style.parse_commit(commit)
11+
assert commit_dict["is_major"]
12+
assert not commit_dict["is_minor"]
13+
assert not commit_dict["is_patch"]
14+
15+
16+
def test_basic_style_breaking_changes():
17+
subject = "Added a new breaking feature"
18+
body = ["BREAKING CHANGES: there is a breaking feature in this code"]
19+
commit = Commit(hash="aaaaaaa", subject=subject, body=body, author_date="1574340645", committer_date="1574340645")
20+
style = BasicStyle()
21+
commit_dict = style.parse_commit(commit)
22+
assert commit_dict["is_major"]
23+
assert not commit_dict["is_minor"]
24+
assert not commit_dict["is_patch"]
25+
26+
27+
def test_basic_style_feat():
28+
subject = "Added a new feature"
29+
commit = Commit(hash="aaaaaaa", subject=subject, author_date="1574340645", committer_date="1574340645")
30+
style = BasicStyle()
31+
commit_dict = style.parse_commit(commit)
32+
assert not commit_dict["is_major"]
33+
assert commit_dict["is_minor"]
34+
assert not commit_dict["is_patch"]
35+
36+
37+
def test_basic_style_fix():
38+
subject = "Fixed a bug"
39+
commit = Commit(hash="aaaaaaa", subject=subject, author_date="1574340645", committer_date="1574340645")
40+
style = BasicStyle()
41+
commit_dict = style.parse_commit(commit)
42+
assert not commit_dict["is_major"]
43+
assert not commit_dict["is_minor"]
44+
assert commit_dict["is_patch"]

0 commit comments

Comments
 (0)