Skip to content

Commit

Permalink
Merge pull request #354 from commitizen-tools/fix-git-commit-parsing
Browse files Browse the repository at this point in the history
fix(git): fix get_commits deliminator
  • Loading branch information
woile authored Feb 24, 2021
2 parents d098416 + 2756e91 commit f6eaa8e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion commitizen/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def get_commits(
return []

git_commits = []
for rev_and_commit in c.out.split(f"\n{delimiter}\n"):
for rev_and_commit in c.out.split(f"{delimiter}\n"):
if not rev_and_commit:
continue
rev, title, author, author_email, *body_list = rev_and_commit.split("\n")
Expand Down
37 changes: 37 additions & 0 deletions tests/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,43 @@ def test_get_commits_without_email(mocker):
assert commits[1].title == "feat(users): add username"


def test_get_commits_without_breakline_in_each_commit(mocker):
raw_commit = (
"ae9ba6fc5526cf478f52ef901418d85505109744\n"
"bump: version 2.13.0 → 2.14.0\n"
"GitHub Action\n"
"action@github.com\n"
"----------commit-delimiter----------\n"
"ff2f56ca844de72a9d59590831087bf5a97bac84\n"
"Merge pull request #332 from cliles/feature/271-redux\n"
"User\n"
"user@email.com\n"
"Feature/271 redux----------commit-delimiter----------\n"
"20a54bf1b82cd7b573351db4d1e8814dd0be205d\n"
"feat(#271): enable creation of annotated tags when bumping\n"
"User 2\n"
"user@email.edu\n"
"----------commit-delimiter----------\n"
)
mocker.patch("commitizen.cmd.run", return_value=FakeCommand(out=raw_commit))

commits = git.get_commits()

assert commits[0].author == "GitHub Action"
assert commits[1].author == "User"
assert commits[2].author == "User 2"

assert commits[0].author_email == "action@github.com"
assert commits[1].author_email == "user@email.com"
assert commits[2].author_email == "user@email.edu"

assert commits[0].title == "bump: version 2.13.0 → 2.14.0"
assert commits[1].title == "Merge pull request #332 from cliles/feature/271-redux"
assert (
commits[2].title == "feat(#271): enable creation of annotated tags when bumping"
)


def test_get_tag_names_has_correct_arrow_annotation():
arrow_annotation = inspect.getfullargspec(git.get_tag_names).annotations["return"]

Expand Down

0 comments on commit f6eaa8e

Please sign in to comment.