git-commit-msg-ai 1.3.0__tar.gz → 1.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {git_commit_msg_ai-1.3.0 → git_commit_msg_ai-1.4.0}/PKG-INFO +4 -4
- {git_commit_msg_ai-1.3.0 → git_commit_msg_ai-1.4.0}/README.md +2 -2
- {git_commit_msg_ai-1.3.0 → git_commit_msg_ai-1.4.0}/git_commit_msg_ai/editor.py +10 -1
- {git_commit_msg_ai-1.3.0 → git_commit_msg_ai-1.4.0}/git_commit_msg_ai/git_ops.py +1 -1
- {git_commit_msg_ai-1.3.0 → git_commit_msg_ai-1.4.0}/git_commit_msg_ai.egg-info/PKG-INFO +4 -4
- {git_commit_msg_ai-1.3.0 → git_commit_msg_ai-1.4.0}/pyproject.toml +4 -4
- {git_commit_msg_ai-1.3.0 → git_commit_msg_ai-1.4.0}/tests/test_ai_client.py +6 -6
- {git_commit_msg_ai-1.3.0 → git_commit_msg_ai-1.4.0}/tests/test_cli.py +19 -16
- git_commit_msg_ai-1.4.0/tests/test_editor.py +130 -0
- {git_commit_msg_ai-1.3.0 → git_commit_msg_ai-1.4.0}/tests/test_exceptions.py +6 -6
- {git_commit_msg_ai-1.3.0 → git_commit_msg_ai-1.4.0}/tests/test_git_ops.py +8 -8
- git_commit_msg_ai-1.3.0/tests/test_editor.py +0 -96
- {git_commit_msg_ai-1.3.0 → git_commit_msg_ai-1.4.0}/git_commit_msg_ai/__init__.py +0 -0
- {git_commit_msg_ai-1.3.0 → git_commit_msg_ai-1.4.0}/git_commit_msg_ai/ai_client.py +0 -0
- {git_commit_msg_ai-1.3.0 → git_commit_msg_ai-1.4.0}/git_commit_msg_ai/cli.py +0 -0
- {git_commit_msg_ai-1.3.0 → git_commit_msg_ai-1.4.0}/git_commit_msg_ai/exceptions.py +0 -0
- {git_commit_msg_ai-1.3.0 → git_commit_msg_ai-1.4.0}/git_commit_msg_ai.egg-info/SOURCES.txt +0 -0
- {git_commit_msg_ai-1.3.0 → git_commit_msg_ai-1.4.0}/git_commit_msg_ai.egg-info/dependency_links.txt +0 -0
- {git_commit_msg_ai-1.3.0 → git_commit_msg_ai-1.4.0}/git_commit_msg_ai.egg-info/entry_points.txt +0 -0
- {git_commit_msg_ai-1.3.0 → git_commit_msg_ai-1.4.0}/git_commit_msg_ai.egg-info/requires.txt +0 -0
- {git_commit_msg_ai-1.3.0 → git_commit_msg_ai-1.4.0}/git_commit_msg_ai.egg-info/top_level.txt +0 -0
- {git_commit_msg_ai-1.3.0 → git_commit_msg_ai-1.4.0}/setup.cfg +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: git-commit-msg-ai
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.4.0
|
|
4
4
|
Summary: AI-powered git commit message generator following Conventional Commits
|
|
5
5
|
License-Expression: MIT
|
|
6
|
-
Requires-Python: >=3.
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
7
|
Description-Content-Type: text/markdown
|
|
8
8
|
Requires-Dist: anthropic
|
|
9
9
|
Provides-Extra: dev
|
|
@@ -18,7 +18,7 @@ AI-powered git commit message generator that follows the [Conventional Commits](
|
|
|
18
18
|
|
|
19
19
|
## Prerequisites
|
|
20
20
|
|
|
21
|
-
- Python 3.
|
|
21
|
+
- Python 3.10+
|
|
22
22
|
- An Anthropic API key set as an environment variable:
|
|
23
23
|
|
|
24
24
|
```sh
|
|
@@ -54,7 +54,7 @@ The tool will:
|
|
|
54
54
|
```
|
|
55
55
|
|
|
56
56
|
- **a** — commits immediately with the generated message
|
|
57
|
-
- **e** — opens the message in your `$EDITOR
|
|
57
|
+
- **e** — opens the message in your `$EDITOR` (defaults to `notepad` on Windows, `vi` on Linux/macOS), lets you modify it, then commits
|
|
58
58
|
- **r** — exits without committing
|
|
59
59
|
|
|
60
60
|
## Commit message format
|
|
@@ -4,7 +4,7 @@ AI-powered git commit message generator that follows the [Conventional Commits](
|
|
|
4
4
|
|
|
5
5
|
## Prerequisites
|
|
6
6
|
|
|
7
|
-
- Python 3.
|
|
7
|
+
- Python 3.10+
|
|
8
8
|
- An Anthropic API key set as an environment variable:
|
|
9
9
|
|
|
10
10
|
```sh
|
|
@@ -40,7 +40,7 @@ The tool will:
|
|
|
40
40
|
```
|
|
41
41
|
|
|
42
42
|
- **a** — commits immediately with the generated message
|
|
43
|
-
- **e** — opens the message in your `$EDITOR
|
|
43
|
+
- **e** — opens the message in your `$EDITOR` (defaults to `notepad` on Windows, `vi` on Linux/macOS), lets you modify it, then commits
|
|
44
44
|
- **r** — exits without committing
|
|
45
45
|
|
|
46
46
|
## Commit message format
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import os
|
|
2
|
+
import platform
|
|
2
3
|
import subprocess
|
|
3
4
|
import tempfile
|
|
4
5
|
|
|
5
6
|
from git_commit_msg_ai.exceptions import EditorError
|
|
6
7
|
|
|
7
8
|
|
|
9
|
+
def get_default_editor() -> str:
|
|
10
|
+
current_platform = platform.system()
|
|
11
|
+
is_windows = current_platform == 'Windows'
|
|
12
|
+
|
|
13
|
+
return 'notepad' if is_windows else 'vi'
|
|
14
|
+
|
|
15
|
+
|
|
8
16
|
def open_in_editor(initial_text: str) -> str:
|
|
9
17
|
try:
|
|
10
18
|
with tempfile.NamedTemporaryFile(suffix='.txt', mode='w', delete=False) as temp_file:
|
|
@@ -13,7 +21,8 @@ def open_in_editor(initial_text: str) -> str:
|
|
|
13
21
|
except OSError:
|
|
14
22
|
raise EditorError('Could not create a temporary file.')
|
|
15
23
|
|
|
16
|
-
|
|
24
|
+
platform_default_editor = get_default_editor()
|
|
25
|
+
editor_command = os.environ.get('EDITOR', platform_default_editor)
|
|
17
26
|
|
|
18
27
|
try:
|
|
19
28
|
try:
|
|
@@ -5,7 +5,7 @@ from git_commit_msg_ai.exceptions import GitError
|
|
|
5
5
|
|
|
6
6
|
def get_staged_diff() -> str:
|
|
7
7
|
try:
|
|
8
|
-
staged_diff = subprocess.check_output(['git', 'diff', '--cached']).decode()
|
|
8
|
+
staged_diff = subprocess.check_output(['git', 'diff', '--cached']).decode('utf-8')
|
|
9
9
|
except FileNotFoundError:
|
|
10
10
|
raise GitError('git is not installed or not on PATH.')
|
|
11
11
|
except subprocess.CalledProcessError:
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: git-commit-msg-ai
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.4.0
|
|
4
4
|
Summary: AI-powered git commit message generator following Conventional Commits
|
|
5
5
|
License-Expression: MIT
|
|
6
|
-
Requires-Python: >=3.
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
7
|
Description-Content-Type: text/markdown
|
|
8
8
|
Requires-Dist: anthropic
|
|
9
9
|
Provides-Extra: dev
|
|
@@ -18,7 +18,7 @@ AI-powered git commit message generator that follows the [Conventional Commits](
|
|
|
18
18
|
|
|
19
19
|
## Prerequisites
|
|
20
20
|
|
|
21
|
-
- Python 3.
|
|
21
|
+
- Python 3.10+
|
|
22
22
|
- An Anthropic API key set as an environment variable:
|
|
23
23
|
|
|
24
24
|
```sh
|
|
@@ -54,7 +54,7 @@ The tool will:
|
|
|
54
54
|
```
|
|
55
55
|
|
|
56
56
|
- **a** — commits immediately with the generated message
|
|
57
|
-
- **e** — opens the message in your `$EDITOR
|
|
57
|
+
- **e** — opens the message in your `$EDITOR` (defaults to `notepad` on Windows, `vi` on Linux/macOS), lets you modify it, then commits
|
|
58
58
|
- **r** — exits without committing
|
|
59
59
|
|
|
60
60
|
## Commit message format
|
|
@@ -4,11 +4,11 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "git-commit-msg-ai"
|
|
7
|
-
version = "1.
|
|
7
|
+
version = "1.4.0"
|
|
8
8
|
description = "AI-powered git commit message generator following Conventional Commits"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "MIT"
|
|
11
|
-
requires-python = ">=3.
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
12
|
dependencies = ["anthropic"]
|
|
13
13
|
|
|
14
14
|
[project.scripts]
|
|
@@ -18,14 +18,14 @@ git-commit-msg-ai = "git_commit_msg_ai.cli:main"
|
|
|
18
18
|
dev = ["mypy", "ruff", "pytest", "pytest-cov"]
|
|
19
19
|
|
|
20
20
|
[tool.ruff]
|
|
21
|
-
target-version = "
|
|
21
|
+
target-version = "py310"
|
|
22
22
|
line-length = 320
|
|
23
23
|
|
|
24
24
|
[tool.ruff.lint]
|
|
25
25
|
select = ["E", "F", "I"]
|
|
26
26
|
|
|
27
27
|
[tool.mypy]
|
|
28
|
-
python_version = "3.
|
|
28
|
+
python_version = "3.10"
|
|
29
29
|
strict = true
|
|
30
30
|
|
|
31
31
|
[tool.pytest.ini_options]
|
|
@@ -17,7 +17,7 @@ def _make_api_response(text: str) -> MagicMock:
|
|
|
17
17
|
return mock_response
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
def _make_status_error(exception_class: type, status_code: int) -> anthropic.APIStatusError:
|
|
20
|
+
def _make_status_error(exception_class: type[anthropic.APIStatusError], status_code: int) -> anthropic.APIStatusError:
|
|
21
21
|
mock_response = MagicMock()
|
|
22
22
|
mock_response.status_code = status_code
|
|
23
23
|
|
|
@@ -25,7 +25,7 @@ def _make_status_error(exception_class: type, status_code: int) -> anthropic.API
|
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
class TestGenerateCommitMessage:
|
|
28
|
-
def test_returns_stripped_commit_message(self):
|
|
28
|
+
def test_returns_stripped_commit_message(self) -> None:
|
|
29
29
|
with patch('git_commit_msg_ai.ai_client.anthropic.Anthropic') as mock_anthropic_class:
|
|
30
30
|
mock_client = MagicMock()
|
|
31
31
|
mock_client.messages.create.return_value = _make_api_response(' feat: add feature ')
|
|
@@ -35,7 +35,7 @@ class TestGenerateCommitMessage:
|
|
|
35
35
|
|
|
36
36
|
assert result == 'feat: add feature'
|
|
37
37
|
|
|
38
|
-
def test_raises_ai_error_on_authentication_error(self):
|
|
38
|
+
def test_raises_ai_error_on_authentication_error(self) -> None:
|
|
39
39
|
with patch('git_commit_msg_ai.ai_client.anthropic.Anthropic') as mock_anthropic_class:
|
|
40
40
|
mock_client = MagicMock()
|
|
41
41
|
mock_client.messages.create.side_effect = _make_status_error(anthropic.AuthenticationError, 401)
|
|
@@ -44,7 +44,7 @@ class TestGenerateCommitMessage:
|
|
|
44
44
|
with pytest.raises(AIError, match='ANTHROPIC_API_KEY'):
|
|
45
45
|
generate_commit_message('diff content')
|
|
46
46
|
|
|
47
|
-
def test_raises_ai_error_on_rate_limit_error(self):
|
|
47
|
+
def test_raises_ai_error_on_rate_limit_error(self) -> None:
|
|
48
48
|
with patch('git_commit_msg_ai.ai_client.anthropic.Anthropic') as mock_anthropic_class:
|
|
49
49
|
mock_client = MagicMock()
|
|
50
50
|
mock_client.messages.create.side_effect = _make_status_error(anthropic.RateLimitError, 429)
|
|
@@ -53,7 +53,7 @@ class TestGenerateCommitMessage:
|
|
|
53
53
|
with pytest.raises(AIError, match='rate limit'):
|
|
54
54
|
generate_commit_message('diff content')
|
|
55
55
|
|
|
56
|
-
def test_raises_ai_error_on_api_connection_error(self):
|
|
56
|
+
def test_raises_ai_error_on_api_connection_error(self) -> None:
|
|
57
57
|
mock_request = MagicMock()
|
|
58
58
|
|
|
59
59
|
with patch('git_commit_msg_ai.ai_client.anthropic.Anthropic') as mock_anthropic_class:
|
|
@@ -64,7 +64,7 @@ class TestGenerateCommitMessage:
|
|
|
64
64
|
with pytest.raises(AIError, match='network'):
|
|
65
65
|
generate_commit_message('diff content')
|
|
66
66
|
|
|
67
|
-
def test_raises_ai_error_on_api_status_error_with_status_code(self):
|
|
67
|
+
def test_raises_ai_error_on_api_status_error_with_status_code(self) -> None:
|
|
68
68
|
with patch('git_commit_msg_ai.ai_client.anthropic.Anthropic') as mock_anthropic_class:
|
|
69
69
|
mock_client = MagicMock()
|
|
70
70
|
mock_client.messages.create.side_effect = _make_status_error(anthropic.APIStatusError, 500)
|
|
@@ -5,9 +5,12 @@ import pytest
|
|
|
5
5
|
from git_commit_msg_ai.cli import main
|
|
6
6
|
from git_commit_msg_ai.exceptions import AIError, GitError
|
|
7
7
|
|
|
8
|
+
COMMIT_MESSAGE = 'feat: add feature'
|
|
9
|
+
EDITED_COMMIT_MESSAGE = 'edited commit message'
|
|
10
|
+
|
|
8
11
|
|
|
9
12
|
class TestMain:
|
|
10
|
-
def _run_with_input(self, user_input: str, commit_message: str =
|
|
13
|
+
def _run_with_input(self, user_input: str, commit_message: str = COMMIT_MESSAGE) -> tuple[MagicMock, MagicMock, MagicMock]:
|
|
11
14
|
mock_git_ops = MagicMock()
|
|
12
15
|
mock_git_ops.get_staged_diff.return_value = 'diff content'
|
|
13
16
|
|
|
@@ -15,7 +18,7 @@ class TestMain:
|
|
|
15
18
|
mock_ai_client.generate_commit_message.return_value = commit_message
|
|
16
19
|
|
|
17
20
|
mock_editor = MagicMock()
|
|
18
|
-
mock_editor.open_in_editor.return_value =
|
|
21
|
+
mock_editor.open_in_editor.return_value = EDITED_COMMIT_MESSAGE
|
|
19
22
|
|
|
20
23
|
with patch('git_commit_msg_ai.cli.git_ops', mock_git_ops):
|
|
21
24
|
with patch('git_commit_msg_ai.cli.ai_client', mock_ai_client):
|
|
@@ -25,23 +28,23 @@ class TestMain:
|
|
|
25
28
|
|
|
26
29
|
return mock_git_ops, mock_ai_client, mock_editor
|
|
27
30
|
|
|
28
|
-
def test_accept_calls_commit_with_generated_message(self):
|
|
29
|
-
mock_git_ops, _, _ = self._run_with_input('a',
|
|
31
|
+
def test_accept_calls_commit_with_generated_message(self) -> None:
|
|
32
|
+
mock_git_ops, _, _ = self._run_with_input('a', COMMIT_MESSAGE)
|
|
30
33
|
|
|
31
|
-
mock_git_ops.commit.assert_called_once_with(
|
|
34
|
+
mock_git_ops.commit.assert_called_once_with(COMMIT_MESSAGE)
|
|
32
35
|
|
|
33
|
-
def test_edit_opens_editor_then_commits_edited_message(self):
|
|
34
|
-
mock_git_ops, _, mock_editor = self._run_with_input('e',
|
|
36
|
+
def test_edit_opens_editor_then_commits_edited_message(self) -> None:
|
|
37
|
+
mock_git_ops, _, mock_editor = self._run_with_input('e', COMMIT_MESSAGE)
|
|
35
38
|
|
|
36
|
-
mock_editor.open_in_editor.assert_called_once_with(
|
|
37
|
-
mock_git_ops.commit.assert_called_once_with(
|
|
39
|
+
mock_editor.open_in_editor.assert_called_once_with(COMMIT_MESSAGE)
|
|
40
|
+
mock_git_ops.commit.assert_called_once_with(EDITED_COMMIT_MESSAGE)
|
|
38
41
|
|
|
39
|
-
def test_reject_does_not_commit(self):
|
|
42
|
+
def test_reject_does_not_commit(self) -> None:
|
|
40
43
|
mock_git_ops, _, _ = self._run_with_input('r')
|
|
41
44
|
|
|
42
45
|
mock_git_ops.commit.assert_not_called()
|
|
43
46
|
|
|
44
|
-
def test_invalid_input_exits_with_code_1(self):
|
|
47
|
+
def test_invalid_input_exits_with_code_1(self) -> None:
|
|
45
48
|
mock_git_ops = MagicMock()
|
|
46
49
|
mock_git_ops.get_staged_diff.return_value = 'diff content'
|
|
47
50
|
|
|
@@ -57,7 +60,7 @@ class TestMain:
|
|
|
57
60
|
|
|
58
61
|
assert exc_info.value.code == 1
|
|
59
62
|
|
|
60
|
-
def test_git_error_from_get_staged_diff_exits_with_message(self, capsys: pytest.CaptureFixture[str]):
|
|
63
|
+
def test_git_error_from_get_staged_diff_exits_with_message(self, capsys: pytest.CaptureFixture[str]) -> None:
|
|
61
64
|
mock_git_ops = MagicMock()
|
|
62
65
|
mock_git_ops.get_staged_diff.side_effect = GitError('staged error')
|
|
63
66
|
|
|
@@ -68,7 +71,7 @@ class TestMain:
|
|
|
68
71
|
assert exc_info.value.code == 1
|
|
69
72
|
assert 'staged error' in capsys.readouterr().out
|
|
70
73
|
|
|
71
|
-
def test_ai_error_from_generate_commit_message_exits_with_message(self, capsys: pytest.CaptureFixture[str]):
|
|
74
|
+
def test_ai_error_from_generate_commit_message_exits_with_message(self, capsys: pytest.CaptureFixture[str]) -> None:
|
|
72
75
|
mock_git_ops = MagicMock()
|
|
73
76
|
mock_git_ops.get_staged_diff.return_value = 'diff content'
|
|
74
77
|
|
|
@@ -83,7 +86,7 @@ class TestMain:
|
|
|
83
86
|
assert exc_info.value.code == 1
|
|
84
87
|
assert 'ai error' in capsys.readouterr().out
|
|
85
88
|
|
|
86
|
-
def test_git_error_from_commit_exits_with_message(self, capsys: pytest.CaptureFixture[str]):
|
|
89
|
+
def test_git_error_from_commit_exits_with_message(self, capsys: pytest.CaptureFixture[str]) -> None:
|
|
87
90
|
mock_git_ops = MagicMock()
|
|
88
91
|
mock_git_ops.get_staged_diff.return_value = 'diff content'
|
|
89
92
|
mock_git_ops.commit.side_effect = GitError('commit error')
|
|
@@ -101,7 +104,7 @@ class TestMain:
|
|
|
101
104
|
assert exc_info.value.code == 1
|
|
102
105
|
assert 'commit error' in capsys.readouterr().out
|
|
103
106
|
|
|
104
|
-
def test_keyboard_interrupt_exits_with_aborted_message(self, capsys: pytest.CaptureFixture[str]):
|
|
107
|
+
def test_keyboard_interrupt_exits_with_aborted_message(self, capsys: pytest.CaptureFixture[str]) -> None:
|
|
105
108
|
mock_git_ops = MagicMock()
|
|
106
109
|
mock_git_ops.get_staged_diff.return_value = 'diff content'
|
|
107
110
|
|
|
@@ -118,7 +121,7 @@ class TestMain:
|
|
|
118
121
|
assert exc_info.value.code == 1
|
|
119
122
|
assert 'Aborted.' in capsys.readouterr().out
|
|
120
123
|
|
|
121
|
-
def test_eof_error_exits_with_aborted_message(self, capsys: pytest.CaptureFixture[str]):
|
|
124
|
+
def test_eof_error_exits_with_aborted_message(self, capsys: pytest.CaptureFixture[str]) -> None:
|
|
122
125
|
mock_git_ops = MagicMock()
|
|
123
126
|
mock_git_ops.get_staged_diff.return_value = 'diff content'
|
|
124
127
|
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import subprocess
|
|
3
|
+
import tempfile
|
|
4
|
+
from contextlib import ExitStack
|
|
5
|
+
from unittest.mock import MagicMock, patch
|
|
6
|
+
|
|
7
|
+
import pytest
|
|
8
|
+
|
|
9
|
+
from git_commit_msg_ai.editor import get_default_editor, open_in_editor
|
|
10
|
+
from git_commit_msg_ai.exceptions import EditorError
|
|
11
|
+
|
|
12
|
+
TEMP_FILE_PATH = os.path.join(tempfile.gettempdir(), 'tmpfile.txt')
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _make_named_temporary_file_mock() -> MagicMock:
|
|
16
|
+
mock_temp_file = MagicMock()
|
|
17
|
+
mock_temp_file.name = TEMP_FILE_PATH
|
|
18
|
+
mock_temp_file.__enter__ = MagicMock(return_value=mock_temp_file)
|
|
19
|
+
mock_temp_file.__exit__ = MagicMock(return_value=False)
|
|
20
|
+
|
|
21
|
+
return mock_temp_file
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _make_open_mock(text: str) -> MagicMock:
|
|
25
|
+
mock_file = MagicMock()
|
|
26
|
+
mock_file.read.return_value = text
|
|
27
|
+
mock_file.__enter__ = MagicMock(return_value=mock_file)
|
|
28
|
+
mock_file.__exit__ = MagicMock(return_value=False)
|
|
29
|
+
|
|
30
|
+
return mock_file
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class TestOpenInEditor:
|
|
34
|
+
def test_returns_stripped_edited_text(self) -> None:
|
|
35
|
+
with ExitStack() as stack:
|
|
36
|
+
stack.enter_context(patch('git_commit_msg_ai.editor.tempfile.NamedTemporaryFile', return_value=_make_named_temporary_file_mock()))
|
|
37
|
+
stack.enter_context(patch('git_commit_msg_ai.editor.subprocess.run'))
|
|
38
|
+
stack.enter_context(patch('git_commit_msg_ai.editor.open', return_value=_make_open_mock(' edited text ')))
|
|
39
|
+
stack.enter_context(patch('git_commit_msg_ai.editor.os.unlink'))
|
|
40
|
+
|
|
41
|
+
result = open_in_editor('initial text')
|
|
42
|
+
|
|
43
|
+
assert result == 'edited text'
|
|
44
|
+
|
|
45
|
+
def test_uses_editor_env_var(self) -> None:
|
|
46
|
+
with ExitStack() as stack:
|
|
47
|
+
stack.enter_context(patch('git_commit_msg_ai.editor.tempfile.NamedTemporaryFile', return_value=_make_named_temporary_file_mock()))
|
|
48
|
+
mock_run = stack.enter_context(patch('git_commit_msg_ai.editor.subprocess.run'))
|
|
49
|
+
stack.enter_context(patch('git_commit_msg_ai.editor.open', return_value=_make_open_mock('text')))
|
|
50
|
+
stack.enter_context(patch('git_commit_msg_ai.editor.os.unlink'))
|
|
51
|
+
stack.enter_context(patch('git_commit_msg_ai.editor.os.environ.get', return_value='vim'))
|
|
52
|
+
|
|
53
|
+
open_in_editor('initial text')
|
|
54
|
+
|
|
55
|
+
mock_run.assert_called_once_with(['vim', TEMP_FILE_PATH], check=True)
|
|
56
|
+
|
|
57
|
+
def test_falls_back_to_platform_default_when_editor_not_set(self) -> None:
|
|
58
|
+
sentinel_editor = 'test-sentinel-editor'
|
|
59
|
+
|
|
60
|
+
with ExitStack() as stack:
|
|
61
|
+
stack.enter_context(patch('git_commit_msg_ai.editor.tempfile.NamedTemporaryFile', return_value=_make_named_temporary_file_mock()))
|
|
62
|
+
mock_run = stack.enter_context(patch('git_commit_msg_ai.editor.subprocess.run'))
|
|
63
|
+
stack.enter_context(patch('git_commit_msg_ai.editor.open', return_value=_make_open_mock('text')))
|
|
64
|
+
stack.enter_context(patch('git_commit_msg_ai.editor.os.unlink'))
|
|
65
|
+
stack.enter_context(patch('git_commit_msg_ai.editor.get_default_editor', return_value=sentinel_editor))
|
|
66
|
+
stack.enter_context(patch.dict('os.environ', {}, clear=True))
|
|
67
|
+
|
|
68
|
+
open_in_editor('initial text')
|
|
69
|
+
|
|
70
|
+
mock_run.assert_called_once_with([sentinel_editor, TEMP_FILE_PATH], check=True)
|
|
71
|
+
|
|
72
|
+
def test_raises_editor_error_on_temp_file_creation_failure(self) -> None:
|
|
73
|
+
with ExitStack() as stack:
|
|
74
|
+
stack.enter_context(patch('git_commit_msg_ai.editor.tempfile.NamedTemporaryFile', side_effect=OSError))
|
|
75
|
+
mock_unlink = stack.enter_context(patch('git_commit_msg_ai.editor.os.unlink'))
|
|
76
|
+
|
|
77
|
+
with pytest.raises(EditorError, match='temporary file'):
|
|
78
|
+
open_in_editor('initial text')
|
|
79
|
+
|
|
80
|
+
mock_unlink.assert_not_called()
|
|
81
|
+
|
|
82
|
+
def test_raises_editor_error_when_editor_not_found(self) -> None:
|
|
83
|
+
with ExitStack() as stack:
|
|
84
|
+
stack.enter_context(patch('git_commit_msg_ai.editor.tempfile.NamedTemporaryFile', return_value=_make_named_temporary_file_mock()))
|
|
85
|
+
stack.enter_context(patch('git_commit_msg_ai.editor.subprocess.run', side_effect=FileNotFoundError))
|
|
86
|
+
mock_unlink = stack.enter_context(patch('git_commit_msg_ai.editor.os.unlink'))
|
|
87
|
+
stack.enter_context(patch('git_commit_msg_ai.editor.os.environ.get', return_value='vim'))
|
|
88
|
+
|
|
89
|
+
with pytest.raises(EditorError, match='was not found'):
|
|
90
|
+
open_in_editor('initial text')
|
|
91
|
+
|
|
92
|
+
mock_unlink.assert_called_once_with(TEMP_FILE_PATH)
|
|
93
|
+
|
|
94
|
+
def test_raises_editor_error_when_editor_exits_with_error(self) -> None:
|
|
95
|
+
with ExitStack() as stack:
|
|
96
|
+
stack.enter_context(patch('git_commit_msg_ai.editor.tempfile.NamedTemporaryFile', return_value=_make_named_temporary_file_mock()))
|
|
97
|
+
stack.enter_context(patch('git_commit_msg_ai.editor.subprocess.run', side_effect=subprocess.CalledProcessError(1, 'vim')))
|
|
98
|
+
mock_unlink = stack.enter_context(patch('git_commit_msg_ai.editor.os.unlink'))
|
|
99
|
+
stack.enter_context(patch('git_commit_msg_ai.editor.os.environ.get', return_value='vim'))
|
|
100
|
+
|
|
101
|
+
with pytest.raises(EditorError, match='exited with an error'):
|
|
102
|
+
open_in_editor('initial text')
|
|
103
|
+
|
|
104
|
+
mock_unlink.assert_called_once_with(TEMP_FILE_PATH)
|
|
105
|
+
|
|
106
|
+
def test_raises_editor_error_when_file_read_fails(self) -> None:
|
|
107
|
+
with ExitStack() as stack:
|
|
108
|
+
stack.enter_context(patch('git_commit_msg_ai.editor.tempfile.NamedTemporaryFile', return_value=_make_named_temporary_file_mock()))
|
|
109
|
+
stack.enter_context(patch('git_commit_msg_ai.editor.subprocess.run'))
|
|
110
|
+
stack.enter_context(patch('git_commit_msg_ai.editor.open', side_effect=OSError))
|
|
111
|
+
mock_unlink = stack.enter_context(patch('git_commit_msg_ai.editor.os.unlink'))
|
|
112
|
+
|
|
113
|
+
with pytest.raises(EditorError, match='Could not read'):
|
|
114
|
+
open_in_editor('initial text')
|
|
115
|
+
|
|
116
|
+
mock_unlink.assert_called_once_with(TEMP_FILE_PATH)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
class TestGetDefaultEditor:
|
|
120
|
+
def test_returns_notepad_on_windows(self) -> None:
|
|
121
|
+
with patch('git_commit_msg_ai.editor.platform.system', return_value='Windows'):
|
|
122
|
+
result = get_default_editor()
|
|
123
|
+
|
|
124
|
+
assert result == 'notepad'
|
|
125
|
+
|
|
126
|
+
def test_returns_vi_on_non_windows(self) -> None:
|
|
127
|
+
with patch('git_commit_msg_ai.editor.platform.system', return_value='Linux'):
|
|
128
|
+
result = get_default_editor()
|
|
129
|
+
|
|
130
|
+
assert result == 'vi'
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
from git_commit_msg_ai.exceptions import AIError, EditorError, GitCommitAIError, GitError
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
def test_git_error_is_subclass_of_base():
|
|
4
|
+
def test_git_error_is_subclass_of_base() -> None:
|
|
5
5
|
assert issubclass(GitError, GitCommitAIError)
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
def test_ai_error_is_subclass_of_base():
|
|
8
|
+
def test_ai_error_is_subclass_of_base() -> None:
|
|
9
9
|
assert issubclass(AIError, GitCommitAIError)
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
def test_editor_error_is_subclass_of_base():
|
|
12
|
+
def test_editor_error_is_subclass_of_base() -> None:
|
|
13
13
|
assert issubclass(EditorError, GitCommitAIError)
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
def test_git_error_carries_message():
|
|
16
|
+
def test_git_error_carries_message() -> None:
|
|
17
17
|
assert str(GitError('git failed')) == 'git failed'
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
def test_ai_error_carries_message():
|
|
20
|
+
def test_ai_error_carries_message() -> None:
|
|
21
21
|
assert str(AIError('api failed')) == 'api failed'
|
|
22
22
|
|
|
23
23
|
|
|
24
|
-
def test_editor_error_carries_message():
|
|
24
|
+
def test_editor_error_carries_message() -> None:
|
|
25
25
|
assert str(EditorError('editor failed')) == 'editor failed'
|
|
@@ -8,7 +8,7 @@ from git_commit_msg_ai.git_ops import commit, get_staged_diff
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
class TestGetStagedDiff:
|
|
11
|
-
def test_returns_decoded_diff(self):
|
|
11
|
+
def test_returns_decoded_diff(self) -> None:
|
|
12
12
|
with patch('git_commit_msg_ai.git_ops.subprocess.check_output') as mock_check_output:
|
|
13
13
|
mock_check_output.return_value = b'diff content'
|
|
14
14
|
|
|
@@ -16,21 +16,21 @@ class TestGetStagedDiff:
|
|
|
16
16
|
|
|
17
17
|
assert result == 'diff content'
|
|
18
18
|
|
|
19
|
-
def test_raises_git_error_when_git_not_found(self):
|
|
19
|
+
def test_raises_git_error_when_git_not_found(self) -> None:
|
|
20
20
|
with patch('git_commit_msg_ai.git_ops.subprocess.check_output') as mock_check_output:
|
|
21
21
|
mock_check_output.side_effect = FileNotFoundError
|
|
22
22
|
|
|
23
23
|
with pytest.raises(GitError, match='not installed'):
|
|
24
24
|
get_staged_diff()
|
|
25
25
|
|
|
26
|
-
def test_raises_git_error_on_called_process_error(self):
|
|
26
|
+
def test_raises_git_error_on_called_process_error(self) -> None:
|
|
27
27
|
with patch('git_commit_msg_ai.git_ops.subprocess.check_output') as mock_check_output:
|
|
28
28
|
mock_check_output.side_effect = subprocess.CalledProcessError(1, 'git')
|
|
29
29
|
|
|
30
30
|
with pytest.raises(GitError, match='git repository'):
|
|
31
31
|
get_staged_diff()
|
|
32
32
|
|
|
33
|
-
def test_raises_git_error_on_unicode_decode_error(self):
|
|
33
|
+
def test_raises_git_error_on_unicode_decode_error(self) -> None:
|
|
34
34
|
mock_bytes = MagicMock()
|
|
35
35
|
mock_bytes.decode.side_effect = UnicodeDecodeError('utf-8', b'', 0, 1, 'reason')
|
|
36
36
|
|
|
@@ -40,7 +40,7 @@ class TestGetStagedDiff:
|
|
|
40
40
|
with pytest.raises(GitError, match='UTF-8'):
|
|
41
41
|
get_staged_diff()
|
|
42
42
|
|
|
43
|
-
def test_raises_git_error_when_diff_is_empty(self):
|
|
43
|
+
def test_raises_git_error_when_diff_is_empty(self) -> None:
|
|
44
44
|
with patch('git_commit_msg_ai.git_ops.subprocess.check_output') as mock_check_output:
|
|
45
45
|
mock_check_output.return_value = b''
|
|
46
46
|
|
|
@@ -49,20 +49,20 @@ class TestGetStagedDiff:
|
|
|
49
49
|
|
|
50
50
|
|
|
51
51
|
class TestCommit:
|
|
52
|
-
def test_calls_subprocess_run_with_correct_args(self):
|
|
52
|
+
def test_calls_subprocess_run_with_correct_args(self) -> None:
|
|
53
53
|
with patch('git_commit_msg_ai.git_ops.subprocess.run') as mock_run:
|
|
54
54
|
commit('my message')
|
|
55
55
|
|
|
56
56
|
mock_run.assert_called_once_with(['git', 'commit', '-m', 'my message'], check=True)
|
|
57
57
|
|
|
58
|
-
def test_raises_git_error_when_git_not_found(self):
|
|
58
|
+
def test_raises_git_error_when_git_not_found(self) -> None:
|
|
59
59
|
with patch('git_commit_msg_ai.git_ops.subprocess.run') as mock_run:
|
|
60
60
|
mock_run.side_effect = FileNotFoundError
|
|
61
61
|
|
|
62
62
|
with pytest.raises(GitError, match='not installed'):
|
|
63
63
|
commit('my message')
|
|
64
64
|
|
|
65
|
-
def test_raises_git_error_on_called_process_error(self):
|
|
65
|
+
def test_raises_git_error_on_called_process_error(self) -> None:
|
|
66
66
|
with patch('git_commit_msg_ai.git_ops.subprocess.run') as mock_run:
|
|
67
67
|
mock_run.side_effect = subprocess.CalledProcessError(1, 'git')
|
|
68
68
|
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import subprocess
|
|
2
|
-
from unittest.mock import MagicMock, patch
|
|
3
|
-
|
|
4
|
-
import pytest
|
|
5
|
-
|
|
6
|
-
from git_commit_msg_ai.editor import open_in_editor
|
|
7
|
-
from git_commit_msg_ai.exceptions import EditorError
|
|
8
|
-
|
|
9
|
-
TEMP_FILE_PATH = '/tmp/tmpfile.txt'
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def _make_named_temporary_file_mock() -> MagicMock:
|
|
13
|
-
mock_temp_file = MagicMock()
|
|
14
|
-
mock_temp_file.name = TEMP_FILE_PATH
|
|
15
|
-
mock_temp_file.__enter__ = MagicMock(return_value=mock_temp_file)
|
|
16
|
-
mock_temp_file.__exit__ = MagicMock(return_value=False)
|
|
17
|
-
|
|
18
|
-
return mock_temp_file
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def _make_open_mock(text: str) -> MagicMock:
|
|
22
|
-
mock_file = MagicMock()
|
|
23
|
-
mock_file.read.return_value = text
|
|
24
|
-
mock_file.__enter__ = MagicMock(return_value=mock_file)
|
|
25
|
-
mock_file.__exit__ = MagicMock(return_value=False)
|
|
26
|
-
|
|
27
|
-
return mock_file
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
class TestOpenInEditor:
|
|
31
|
-
def test_returns_stripped_edited_text(self):
|
|
32
|
-
with patch('git_commit_msg_ai.editor.tempfile.NamedTemporaryFile', return_value=_make_named_temporary_file_mock()):
|
|
33
|
-
with patch('git_commit_msg_ai.editor.subprocess.run'):
|
|
34
|
-
with patch('git_commit_msg_ai.editor.open', return_value=_make_open_mock(' edited text ')):
|
|
35
|
-
with patch('git_commit_msg_ai.editor.os.unlink'):
|
|
36
|
-
result = open_in_editor('initial text')
|
|
37
|
-
|
|
38
|
-
assert result == 'edited text'
|
|
39
|
-
|
|
40
|
-
def test_uses_editor_env_var(self):
|
|
41
|
-
with patch('git_commit_msg_ai.editor.tempfile.NamedTemporaryFile', return_value=_make_named_temporary_file_mock()):
|
|
42
|
-
with patch('git_commit_msg_ai.editor.subprocess.run') as mock_run:
|
|
43
|
-
with patch('git_commit_msg_ai.editor.open', return_value=_make_open_mock('text')):
|
|
44
|
-
with patch('git_commit_msg_ai.editor.os.unlink'):
|
|
45
|
-
with patch('git_commit_msg_ai.editor.os.environ.get', return_value='vim'):
|
|
46
|
-
open_in_editor('initial text')
|
|
47
|
-
|
|
48
|
-
mock_run.assert_called_once_with(['vim', TEMP_FILE_PATH], check=True)
|
|
49
|
-
|
|
50
|
-
def test_falls_back_to_notepad_when_editor_not_set(self):
|
|
51
|
-
with patch('git_commit_msg_ai.editor.tempfile.NamedTemporaryFile', return_value=_make_named_temporary_file_mock()):
|
|
52
|
-
with patch('git_commit_msg_ai.editor.subprocess.run') as mock_run:
|
|
53
|
-
with patch('git_commit_msg_ai.editor.open', return_value=_make_open_mock('text')):
|
|
54
|
-
with patch('git_commit_msg_ai.editor.os.unlink'):
|
|
55
|
-
with patch('git_commit_msg_ai.editor.os.environ.get', return_value='notepad'):
|
|
56
|
-
open_in_editor('initial text')
|
|
57
|
-
|
|
58
|
-
mock_run.assert_called_once_with(['notepad', TEMP_FILE_PATH], check=True)
|
|
59
|
-
|
|
60
|
-
def test_raises_editor_error_on_temp_file_creation_failure(self):
|
|
61
|
-
with patch('git_commit_msg_ai.editor.tempfile.NamedTemporaryFile', side_effect=OSError):
|
|
62
|
-
with patch('git_commit_msg_ai.editor.os.unlink') as mock_unlink:
|
|
63
|
-
with pytest.raises(EditorError, match='temporary file'):
|
|
64
|
-
open_in_editor('initial text')
|
|
65
|
-
|
|
66
|
-
mock_unlink.assert_not_called()
|
|
67
|
-
|
|
68
|
-
def test_raises_editor_error_when_editor_not_found(self):
|
|
69
|
-
with patch('git_commit_msg_ai.editor.tempfile.NamedTemporaryFile', return_value=_make_named_temporary_file_mock()):
|
|
70
|
-
with patch('git_commit_msg_ai.editor.subprocess.run', side_effect=FileNotFoundError):
|
|
71
|
-
with patch('git_commit_msg_ai.editor.os.unlink') as mock_unlink:
|
|
72
|
-
with patch('git_commit_msg_ai.editor.os.environ.get', return_value='vim'):
|
|
73
|
-
with pytest.raises(EditorError, match='was not found'):
|
|
74
|
-
open_in_editor('initial text')
|
|
75
|
-
|
|
76
|
-
mock_unlink.assert_called_once_with(TEMP_FILE_PATH)
|
|
77
|
-
|
|
78
|
-
def test_raises_editor_error_when_editor_exits_with_error(self):
|
|
79
|
-
with patch('git_commit_msg_ai.editor.tempfile.NamedTemporaryFile', return_value=_make_named_temporary_file_mock()):
|
|
80
|
-
with patch('git_commit_msg_ai.editor.subprocess.run', side_effect=subprocess.CalledProcessError(1, 'vim')):
|
|
81
|
-
with patch('git_commit_msg_ai.editor.os.unlink') as mock_unlink:
|
|
82
|
-
with patch('git_commit_msg_ai.editor.os.environ.get', return_value='vim'):
|
|
83
|
-
with pytest.raises(EditorError, match='exited with an error'):
|
|
84
|
-
open_in_editor('initial text')
|
|
85
|
-
|
|
86
|
-
mock_unlink.assert_called_once_with(TEMP_FILE_PATH)
|
|
87
|
-
|
|
88
|
-
def test_raises_editor_error_when_file_read_fails(self):
|
|
89
|
-
with patch('git_commit_msg_ai.editor.tempfile.NamedTemporaryFile', return_value=_make_named_temporary_file_mock()):
|
|
90
|
-
with patch('git_commit_msg_ai.editor.subprocess.run'):
|
|
91
|
-
with patch('git_commit_msg_ai.editor.open', side_effect=OSError):
|
|
92
|
-
with patch('git_commit_msg_ai.editor.os.unlink') as mock_unlink:
|
|
93
|
-
with pytest.raises(EditorError, match='Could not read'):
|
|
94
|
-
open_in_editor('initial text')
|
|
95
|
-
|
|
96
|
-
mock_unlink.assert_called_once_with(TEMP_FILE_PATH)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{git_commit_msg_ai-1.3.0 → git_commit_msg_ai-1.4.0}/git_commit_msg_ai.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{git_commit_msg_ai-1.3.0 → git_commit_msg_ai-1.4.0}/git_commit_msg_ai.egg-info/entry_points.txt
RENAMED
|
File without changes
|
|
File without changes
|
{git_commit_msg_ai-1.3.0 → git_commit_msg_ai-1.4.0}/git_commit_msg_ai.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|