Skip to content

Commit

Permalink
fix: correctly detect major version, for both angular style and basic…
Browse files Browse the repository at this point in the history
… style

- fixed BREAK_REGEX to work on multiline commits
- added unit tests
  • Loading branch information
LoicViennois committed Nov 29, 2019
1 parent eb80522 commit 7385e19
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/git_changelog/style.py
Expand Up @@ -17,7 +17,7 @@ class BasicStyle(CommitStyle):
}

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

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

def is_major(self, commit_message):
return bool(self.BREAK_REGEX.match(commit_message))
return bool(self.BREAK_REGEX.search(commit_message))


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

def parse_commit(self, commit):
subject = self.parse_subject(commit.subject)
Expand Down Expand Up @@ -86,7 +86,7 @@ def is_minor(self, commit_type):
return commit_type == self.TYPES["feat"]

def is_major(self, commit_message):
return bool(self.BREAK_REGEX.match(commit_message))
return bool(self.BREAK_REGEX.search(commit_message))


class AtomStyle(CommitStyle):
Expand Down
26 changes: 24 additions & 2 deletions tests/test_angular_style.py
Expand Up @@ -2,9 +2,31 @@
from git_changelog.style import AngularStyle


def test_angular_style_breaking_change():
subject = "feat: this is a new breaking feature"
body = ["BREAKING CHANGE: there is a breaking feature in this code"]
commit = Commit(hash="aaaaaaa", subject=subject, body=body, author_date="1574340645", committer_date="1574340645")
style = AngularStyle()
commit_dict = style.parse_commit(commit)
assert commit_dict["is_major"]
assert not commit_dict["is_minor"]
assert not commit_dict["is_patch"]


def test_angular_style_breaking_changes():
subject = "feat: this is a new breaking feature"
body = ["BREAKING CHANGES: there is a breaking feature in this code"]
commit = Commit(hash="aaaaaaa", subject=subject, body=body, author_date="1574340645", committer_date="1574340645")
style = AngularStyle()
commit_dict = style.parse_commit(commit)
assert commit_dict["is_major"]
assert not commit_dict["is_minor"]
assert not commit_dict["is_patch"]


def test_angular_style_feat():
subject = "feat: this is a new feature"
commit = Commit("aaaaaaa", subject=subject, author_date="1574340645", committer_date="1574340645",)
commit = Commit(hash="aaaaaaa", subject=subject, author_date="1574340645", committer_date="1574340645")
style = AngularStyle()
commit_dict = style.parse_commit(commit)
assert not commit_dict["is_major"]
Expand All @@ -14,7 +36,7 @@ def test_angular_style_feat():

def test_angular_style_fix():
subject = "fix: this is a bug fix"
commit = Commit("aaaaaaa", subject=subject, author_date="1574340645", committer_date="1574340645",)
commit = Commit(hash="aaaaaaa", subject=subject, author_date="1574340645", committer_date="1574340645")
style = AngularStyle()
commit_dict = style.parse_commit(commit)
assert not commit_dict["is_major"]
Expand Down
44 changes: 44 additions & 0 deletions tests/test_basic_style.py
@@ -0,0 +1,44 @@
from git_changelog.build import Commit
from git_changelog.style import BasicStyle


def test_basic_style_breaking_change():
subject = "Added a new breaking feature"
body = ["BREAKING CHANGE: there is a breaking feature in this code"]
commit = Commit(hash="aaaaaaa", subject=subject, body=body, author_date="1574340645", committer_date="1574340645")
style = BasicStyle()
commit_dict = style.parse_commit(commit)
assert commit_dict["is_major"]
assert not commit_dict["is_minor"]
assert not commit_dict["is_patch"]


def test_basic_style_breaking_changes():
subject = "Added a new breaking feature"
body = ["BREAKING CHANGES: there is a breaking feature in this code"]
commit = Commit(hash="aaaaaaa", subject=subject, body=body, author_date="1574340645", committer_date="1574340645")
style = BasicStyle()
commit_dict = style.parse_commit(commit)
assert commit_dict["is_major"]
assert not commit_dict["is_minor"]
assert not commit_dict["is_patch"]


def test_basic_style_feat():
subject = "Added a new feature"
commit = Commit(hash="aaaaaaa", subject=subject, author_date="1574340645", committer_date="1574340645")
style = BasicStyle()
commit_dict = style.parse_commit(commit)
assert not commit_dict["is_major"]
assert commit_dict["is_minor"]
assert not commit_dict["is_patch"]


def test_basic_style_fix():
subject = "Fixed a bug"
commit = Commit(hash="aaaaaaa", subject=subject, author_date="1574340645", committer_date="1574340645")
style = BasicStyle()
commit_dict = style.parse_commit(commit)
assert not commit_dict["is_major"]
assert not commit_dict["is_minor"]
assert commit_dict["is_patch"]

0 comments on commit 7385e19

Please sign in to comment.