From b8af08b40a41df913eea16e03f6cbd02690efe62 Mon Sep 17 00:00:00 2001 From: Joseph Manley Date: Tue, 16 Jun 2020 12:01:11 -0400 Subject: [PATCH] Updated regex to check single line and added test case --- semver/__init__.py | 2 +- semver/tests.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/semver/__init__.py b/semver/__init__.py index 5a7077e..0e6e4fc 100644 --- a/semver/__init__.py +++ b/semver/__init__.py @@ -19,7 +19,7 @@ NOT_MAIN_BRANCH = Exception('Not merging into a main branch') NO_GIT_FLOW = Exception('No git flow branch found') # Important regex -GET_COMMIT_MESSAGE = re.compile(r"Merge (branch|pull request) '?([^']+)'? (into|from) (?:'(.+)'|[^\/]+\/(.+))") +GET_COMMIT_MESSAGE = re.compile(r"Merge (branch|pull request) '?([^']+)'? (into|from) (?:'(.+)'|[^\/]+\/([^\n\\]+))") class SemVer(object): diff --git a/semver/tests.py b/semver/tests.py index 382383c..bd08fd4 100644 --- a/semver/tests.py +++ b/semver/tests.py @@ -139,6 +139,13 @@ class TestGetCommitMessageRegex(unittest.TestCase): self.assertEqual(matches.group(2), "branch") else: self.assertTrue(False) + def test_branch_in_message(self): + matches = GET_COMMIT_MESSAGE.search(str(b'commit examplehash\nMerge: example\nAuthor: Test \nDate: Mon Jun 15 18:15:22 2020 -0400\n\n Merge pull request #45 from user/branch\n \n user/branch\n')) + if matches: + self.assertEqual(matches.group(4), None) + self.assertEqual(matches.group(5), "branch") + else: + self.assertTrue(False) def test_non_merge_message(self): matches = GET_COMMIT_MESSAGE.search("Example unrelated commit message that should get 0 matches") self.assertEqual(matches, None)