Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion commit_check/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
'checks': [
{
'check': 'message',
'regex': r'^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test){1}(\([\w\-\.]+\))?(!)?: ([\w ])+([\s\S]*)|(Merge).*|(fixup!.*)',
'regex': r'^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test){1}(\([\w\-\.]+\))?(!)?: ([\u2600-\u26FF\u2700-\u27BF\U0001F000-\U0001F02F\U0001F0A0-\U0001F0FF\U0001F100-\U0001F1FF\U0001F300-\U0001F5FF\U0001F600-\U0001F64F\U0001F680-\U0001F6FF\U0001F900-\U0001F9FF]\uFE0F? )?([\w ])+([\s\S]*)|(Merge).*|(fixup!.*)',
'error': 'The commit message should be structured as follows:\n\n'
'<type>[optional scope]: <description>\n'
'[optional body]\n'
Expand Down
40 changes: 39 additions & 1 deletion tests/commit_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from commit_check import PASS, FAIL
from commit_check import PASS, FAIL, DEFAULT_CONFIG
from commit_check.commit import check_commit_msg, get_default_commit_msg_file, read_commit_msg, check_commit_signoff

# used by get_commit_info mock
Expand Down Expand Up @@ -49,6 +49,44 @@ def test_check_commit_msg_no_commit_msg_file(mocker):
assert result == 0


def test_check_commit_msg_with_emoji_commit_msg_file_using_defaults(mocker):
mock_get_default_commit_msg_file = mocker.patch(
"commit_check.commit.get_default_commit_msg_file",
return_value=".git/COMMIT_EDITMSG"
)
mock_read_commit_msg = mocker.patch(
"commit_check.commit.read_commit_msg",
return_value="fix: 🐛 sample"
)

checks = [next(c for c in DEFAULT_CONFIG['checks'] if c['check'] == 'message')]

result = check_commit_msg(checks, commit_msg_file="")

mock_get_default_commit_msg_file.assert_called_once()
mock_read_commit_msg.assert_called_once_with(".git/COMMIT_EDITMSG")
assert result == 0


def test_check_commit_msg_with_grapheme_cluster_emoji_commit_msg_file_using_defaults(mocker):
mock_get_default_commit_msg_file = mocker.patch(
"commit_check.commit.get_default_commit_msg_file",
return_value=".git/COMMIT_EDITMSG"
)
mock_read_commit_msg = mocker.patch(
"commit_check.commit.read_commit_msg",
return_value="docs: 📚️ mention commit-check and rulesets" # watch out emoji is U+1F4DA followed by U+FE0F
)

checks = [next(c for c in DEFAULT_CONFIG['checks'] if c['check'] == 'message')]

result = check_commit_msg(checks, commit_msg_file="")

mock_get_default_commit_msg_file.assert_called_once()
mock_read_commit_msg.assert_called_once_with(".git/COMMIT_EDITMSG")
assert result == 0


def test_check_commit_with_empty_checks(mocker):
checks = []
m_re_match = mocker.patch(
Expand Down