commitwise 0.1.2__tar.gz → 0.1.3__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.
- {commitwise-0.1.2 → commitwise-0.1.3}/PKG-INFO +1 -1
- commitwise-0.1.3/commitwise/__init__.py +1 -0
- {commitwise-0.1.2 → commitwise-0.1.3}/commitwise/cli.py +11 -39
- commitwise-0.1.3/commitwise/cli_utils.py +87 -0
- {commitwise-0.1.2 → commitwise-0.1.3}/commitwise/git_utils.py +34 -1
- {commitwise-0.1.2 → commitwise-0.1.3}/commitwise.egg-info/PKG-INFO +1 -1
- {commitwise-0.1.2 → commitwise-0.1.3}/commitwise.egg-info/SOURCES.txt +1 -0
- {commitwise-0.1.2 → commitwise-0.1.3}/pyproject.toml +1 -1
- commitwise-0.1.2/commitwise/__init__.py +0 -1
- {commitwise-0.1.2 → commitwise-0.1.3}/README.md +0 -0
- {commitwise-0.1.2 → commitwise-0.1.3}/commitwise/ai/__init__.py +0 -0
- {commitwise-0.1.2 → commitwise-0.1.3}/commitwise/ai/base.py +0 -0
- {commitwise-0.1.2 → commitwise-0.1.3}/commitwise/ai/local_engine.py +0 -0
- {commitwise-0.1.2 → commitwise-0.1.3}/commitwise/ai/openai_engine.py +0 -0
- {commitwise-0.1.2 → commitwise-0.1.3}/commitwise/ai_source.py +0 -0
- {commitwise-0.1.2 → commitwise-0.1.3}/commitwise/config.py +0 -0
- {commitwise-0.1.2 → commitwise-0.1.3}/commitwise/file_source.py +0 -0
- {commitwise-0.1.2 → commitwise-0.1.3}/commitwise.egg-info/dependency_links.txt +0 -0
- {commitwise-0.1.2 → commitwise-0.1.3}/commitwise.egg-info/entry_points.txt +0 -0
- {commitwise-0.1.2 → commitwise-0.1.3}/commitwise.egg-info/requires.txt +0 -0
- {commitwise-0.1.2 → commitwise-0.1.3}/commitwise.egg-info/top_level.txt +0 -0
- {commitwise-0.1.2 → commitwise-0.1.3}/setup.cfg +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__='0.1.3'
|
|
@@ -1,58 +1,25 @@
|
|
|
1
|
-
import argparse
|
|
2
1
|
import sys
|
|
3
2
|
|
|
4
3
|
from commitwise import __version__
|
|
4
|
+
from commitwise.cli_utils import (
|
|
5
|
+
build_parser,
|
|
6
|
+
)
|
|
5
7
|
from commitwise.git_utils import (
|
|
6
8
|
get_staged_diff,
|
|
7
9
|
git_commit_with_message,
|
|
10
|
+
confirm_commit,
|
|
8
11
|
)
|
|
9
12
|
from commitwise.file_source import read_commit_file
|
|
10
13
|
from commitwise.ai_source import generate_ai_commit_message
|
|
11
14
|
|
|
12
15
|
|
|
13
|
-
def build_parser() -> argparse.ArgumentParser:
|
|
14
|
-
parser = argparse.ArgumentParser(
|
|
15
|
-
prog="commitwise",
|
|
16
|
-
description="CommitWise - Smart Git commits, wisely.",
|
|
17
|
-
formatter_class=argparse.RawTextHelpFormatter,
|
|
18
|
-
)
|
|
19
|
-
|
|
20
|
-
parser.add_argument(
|
|
21
|
-
"--version",
|
|
22
|
-
"-V",
|
|
23
|
-
action="store_true",
|
|
24
|
-
help="Display the version of commitwise that is currently installed.",
|
|
25
|
-
)
|
|
26
|
-
|
|
27
|
-
parser.add_argument(
|
|
28
|
-
"--ai",
|
|
29
|
-
action="store_true",
|
|
30
|
-
help=(
|
|
31
|
-
"Generate commit message using AI.\n"
|
|
32
|
-
"Automatically uses OpenAI if OPENAI_APP_KEY is set,\n"
|
|
33
|
-
"otherwise falls back to a local model (Ollama)."
|
|
34
|
-
),
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
parser.add_argument(
|
|
38
|
-
"--file",
|
|
39
|
-
metavar="PATH",
|
|
40
|
-
help=(
|
|
41
|
-
"Read commit message from a text file and commit it\n"
|
|
42
|
-
"exactly as written (preserves formatting)."
|
|
43
|
-
),
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
return parser
|
|
47
|
-
|
|
48
|
-
|
|
49
16
|
def main() -> None:
|
|
50
17
|
parser = build_parser()
|
|
51
18
|
args = parser.parse_args()
|
|
52
19
|
|
|
53
20
|
# version flag
|
|
54
21
|
if args.version:
|
|
55
|
-
print(f
|
|
22
|
+
print(f"commitwise {__version__}")
|
|
56
23
|
sys.exit(0)
|
|
57
24
|
|
|
58
25
|
# [X] both flags used
|
|
@@ -69,6 +36,11 @@ def main() -> None:
|
|
|
69
36
|
if args.ai:
|
|
70
37
|
diff = get_staged_diff()
|
|
71
38
|
message = generate_ai_commit_message(diff)
|
|
39
|
+
|
|
40
|
+
if not confirm_commit(message):
|
|
41
|
+
print("\n\nCommit aborted.")
|
|
42
|
+
sys.exit(0)
|
|
43
|
+
|
|
72
44
|
git_commit_with_message(message)
|
|
73
45
|
return
|
|
74
46
|
|
|
@@ -77,7 +49,7 @@ def main() -> None:
|
|
|
77
49
|
message = read_commit_file(args.file)
|
|
78
50
|
git_commit_with_message(message)
|
|
79
51
|
return
|
|
80
|
-
|
|
52
|
+
|
|
81
53
|
except Exception as e:
|
|
82
54
|
print(f"\n [X] Error: {e}", file=sys.stderr)
|
|
83
55
|
sys.exit(1)
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import os
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
7
|
+
"""
|
|
8
|
+
Defines and return all command-line flags for the CommitWise CLI.
|
|
9
|
+
|
|
10
|
+
Flags:
|
|
11
|
+
--version, -V
|
|
12
|
+
Display the currently installed commitwise version.
|
|
13
|
+
|
|
14
|
+
--ai
|
|
15
|
+
Generate a commit message using AI.
|
|
16
|
+
|
|
17
|
+
--file PATH
|
|
18
|
+
Read a commit message from a text file and commit it
|
|
19
|
+
exactly as written, preserving formatting.
|
|
20
|
+
|
|
21
|
+
Returns:
|
|
22
|
+
argparser.ArgumentParser: Configured parser with all CLI flags.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
parser = argparse.ArgumentParser(
|
|
26
|
+
prog="commitwise",
|
|
27
|
+
description="CommitWise - Smart Git commits, wisely.",
|
|
28
|
+
formatter_class=argparse.RawTextHelpFormatter,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
parser.add_argument(
|
|
32
|
+
"--version",
|
|
33
|
+
"-V",
|
|
34
|
+
action="store_true",
|
|
35
|
+
help="Display the version of commitwise that is currently installed.",
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
parser.add_argument(
|
|
39
|
+
"--ai",
|
|
40
|
+
action="store_true",
|
|
41
|
+
help=(
|
|
42
|
+
"Generate commit message using AI.\n"
|
|
43
|
+
"Automatically uses OpenAI if OPENAI_APP_KEY is set,\n"
|
|
44
|
+
"otherwise falls back to a local model (Ollama)."
|
|
45
|
+
),
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
parser.add_argument(
|
|
49
|
+
"--file",
|
|
50
|
+
metavar="PATH",
|
|
51
|
+
help=(
|
|
52
|
+
"Read commit message from a text file and commit it\n"
|
|
53
|
+
"exactly as written (preserves formatting)."
|
|
54
|
+
),
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
return parser
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def read_single_key() -> str:
|
|
61
|
+
"""
|
|
62
|
+
Reads a single keypress from the user without requiring Enter.
|
|
63
|
+
|
|
64
|
+
Works cross-platform:
|
|
65
|
+
- Windows: uses msvcrt.getch()
|
|
66
|
+
- Linux/macOS: uses termios and tty to set raw input mode.
|
|
67
|
+
|
|
68
|
+
Returns:
|
|
69
|
+
str: The pressed key as a lowercase string.
|
|
70
|
+
"""
|
|
71
|
+
|
|
72
|
+
if os.name == "nt":
|
|
73
|
+
import msvcrt
|
|
74
|
+
|
|
75
|
+
return msvcrt.getch().decode("utf-8", errors="ignore").lower()
|
|
76
|
+
else:
|
|
77
|
+
import termios
|
|
78
|
+
import tty
|
|
79
|
+
|
|
80
|
+
fd = sys.stdin.fileno()
|
|
81
|
+
old_settings = termios.tcgetattr(fd)
|
|
82
|
+
try:
|
|
83
|
+
tty.setraw(fd)
|
|
84
|
+
ch = sys.stdin.read(1).lower()
|
|
85
|
+
finally:
|
|
86
|
+
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
|
|
87
|
+
return ch
|
|
@@ -2,6 +2,8 @@ import subprocess
|
|
|
2
2
|
import tempfile
|
|
3
3
|
import os
|
|
4
4
|
|
|
5
|
+
from commitwise.cli_utils import read_single_key
|
|
6
|
+
|
|
5
7
|
|
|
6
8
|
def get_staged_diff() -> str:
|
|
7
9
|
"""
|
|
@@ -41,7 +43,38 @@ def git_commit_with_message(message: str) -> None:
|
|
|
41
43
|
tmp.write(message.rstrip() + "\n")
|
|
42
44
|
temp_file_path = tmp.name
|
|
43
45
|
|
|
44
|
-
subprocess.run(["git", "commit", "-F", temp_file_path], check=True)
|
|
46
|
+
# subprocess.run(["git", "commit", "-F", temp_file_path], check=True)
|
|
47
|
+
result = subprocess.run(
|
|
48
|
+
["git", "commit", "-F", temp_file_path],
|
|
49
|
+
capture_output=True,
|
|
50
|
+
text=True,
|
|
51
|
+
).stdout.strip()
|
|
52
|
+
|
|
53
|
+
output_message = (
|
|
54
|
+
f"\n\n[✔] Commit created successfully. More details:\n\n{result}"
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
print(output_message)
|
|
58
|
+
|
|
45
59
|
finally:
|
|
46
60
|
if temp_file_path and os.path.exists(temp_file_path):
|
|
47
61
|
os.remove(temp_file_path)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def confirm_commit(message: str) -> bool:
|
|
65
|
+
"""
|
|
66
|
+
Confirm the suggested commit message.
|
|
67
|
+
"""
|
|
68
|
+
print("\nProposed commit message:\n")
|
|
69
|
+
print("-" * 40)
|
|
70
|
+
print(message.strip())
|
|
71
|
+
print("-" * 40)
|
|
72
|
+
print("\nCommit this message? [y/n] ", end="", flush=True)
|
|
73
|
+
|
|
74
|
+
while True:
|
|
75
|
+
key = read_single_key()
|
|
76
|
+
if key == "y":
|
|
77
|
+
return True
|
|
78
|
+
|
|
79
|
+
if key == "n":
|
|
80
|
+
return False
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__='0.1.2'
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|