Updated regex to check single line and added test case

This commit is contained in:
Layla 2020-06-16 12:01:11 -04:00
parent 485dc7bf95
commit b8af08b40a
No known key found for this signature in database
GPG Key ID: A494D9357BA1BE31
2 changed files with 8 additions and 1 deletions

View File

@ -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):

View File

@ -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 <test@nodomain.rightbrainnetworks.com>\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)