Skip to content

Commit

Permalink
Merge pull request #23 from t4n0/bail_if_ticket_in_body_of_commit_mes…
Browse files Browse the repository at this point in the history
…sage

Also bail if ticket is included in body of commit message
  • Loading branch information
milind-shakya-sp authored Aug 26, 2022
2 parents d4a4c3b + de4bc7c commit d1a1d97
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion giticket/giticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions tests/test_giticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit d1a1d97

Please sign in to comment.