From de4bc7ca7c0654faa36452cc3a9b5601d472f783 Mon Sep 17 00:00:00 2001 From: t4n0 Date: Tue, 19 Jul 2022 21:25:19 +0200 Subject: [PATCH] Also bail if ticket is included in body of commit message --- giticket/giticket.py | 2 +- tests/test_giticket.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/giticket/giticket.py b/giticket/giticket.py index e200038..7b4cde0 100644 --- a/giticket/giticket.py +++ b/giticket/giticket.py @@ -22,7 +22,7 @@ def update_commit_message(filename, regex, mode, format_string): branch = get_branch_name() # Bail if commit message already contains tickets - if re.search(regex, commit_msg): + if any(re.search(regex, content) for content in contents): return tickets = re.findall(regex, branch) diff --git a/tests/test_giticket.py b/tests/test_giticket.py index eecb168..e71a3d1 100644 --- a/tests/test_giticket.py +++ b/tests/test_giticket.py @@ -125,6 +125,23 @@ def test_ci_message_with_nl_regex_match_mode(mock_branch_name, msg, tmpdir): assert path.read().split('\n')[0] == "{first_line} - {ticket}".format(first_line=first_line, ticket="JIRA-239") +@pytest.mark.parametrize('msg', ( + """A descriptive header + +A descriptive body. + +Issue: 2397""", +)) +@mock.patch(TESTING_MODULE + '.get_branch_name') +def test_update_commit_message_no_modification_if_ticket_in_body(mock_branch_name, msg, tmpdir): + mock_branch_name.return_value = "team_name/2397/a_nice_feature" + path = tmpdir.join('file.txt') + path.write(msg) + update_commit_message(six.text_type(path), r'\d{4,}', + 'regex_match', '{commit_msg}\n\nIssue: {ticket}') + assert path.read() == msg + + @mock.patch(TESTING_MODULE + '.subprocess') def test_get_branch_name(mock_subprocess): get_branch_name()