tgit 0.11.2__tar.gz → 0.12.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.
- {tgit-0.11.2 → tgit-0.12.0}/PKG-INFO +1 -1
- {tgit-0.11.2 → tgit-0.12.0}/pyproject.toml +1 -1
- {tgit-0.11.2 → tgit-0.12.0}/tgit/commit.py +50 -21
- {tgit-0.11.2 → tgit-0.12.0}/tgit/prompts/commit.txt +10 -1
- {tgit-0.11.2 → tgit-0.12.0}/uv.lock +394 -318
- {tgit-0.11.2 → tgit-0.12.0}/.gitignore +0 -0
- {tgit-0.11.2 → tgit-0.12.0}/.python-version +0 -0
- {tgit-0.11.2 → tgit-0.12.0}/.tgit.yml +0 -0
- {tgit-0.11.2 → tgit-0.12.0}/CHANGELOG.md +0 -0
- {tgit-0.11.2 → tgit-0.12.0}/README.md +0 -0
- {tgit-0.11.2 → tgit-0.12.0}/scripts/publish.sh +0 -0
- {tgit-0.11.2 → tgit-0.12.0}/tgit/__init__.py +0 -0
- {tgit-0.11.2 → tgit-0.12.0}/tgit/add.py +0 -0
- {tgit-0.11.2 → tgit-0.12.0}/tgit/changelog.py +0 -0
- {tgit-0.11.2 → tgit-0.12.0}/tgit/cli.py +0 -0
- {tgit-0.11.2 → tgit-0.12.0}/tgit/config.py +0 -0
- {tgit-0.11.2 → tgit-0.12.0}/tgit/settings.py +0 -0
- {tgit-0.11.2 → tgit-0.12.0}/tgit/utils.py +0 -0
- {tgit-0.11.2 → tgit-0.12.0}/tgit/version.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tgit
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.12.0
|
|
4
4
|
Summary: Tool for Git Interaction Temptation (tgit): An elegant CLI tool that simplifies and streamlines your Git workflow, making version control a breeze.
|
|
5
5
|
Author-email: Jannchie <jannchie@gmail.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "tgit"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.12.0"
|
|
4
4
|
description = "Tool for Git Interaction Temptation (tgit): An elegant CLI tool that simplifies and streamlines your Git workflow, making version control a breeze."
|
|
5
5
|
authors = [{ name = "Jannchie", email = "jannchie@gmail.com" }]
|
|
6
6
|
dependencies = [
|
|
@@ -7,11 +7,15 @@ from pathlib import Path
|
|
|
7
7
|
import git
|
|
8
8
|
from jinja2 import Environment, FileSystemLoader
|
|
9
9
|
from pydantic import BaseModel
|
|
10
|
-
from rich import
|
|
10
|
+
from rich import (
|
|
11
|
+
get_console,
|
|
12
|
+
print, # noqa: A004
|
|
13
|
+
)
|
|
11
14
|
|
|
12
15
|
from tgit.settings import settings
|
|
13
16
|
from tgit.utils import get_commit_command, run_command, type_emojis
|
|
14
17
|
|
|
18
|
+
console = get_console()
|
|
15
19
|
with importlib.resources.path("tgit", "prompts") as prompt_path:
|
|
16
20
|
env = Environment(loader=FileSystemLoader(prompt_path), autoescape=True)
|
|
17
21
|
|
|
@@ -56,7 +60,7 @@ class CommitData(BaseModel):
|
|
|
56
60
|
is_breaking: bool
|
|
57
61
|
|
|
58
62
|
|
|
59
|
-
def get_ai_command() -> str | None:
|
|
63
|
+
def get_ai_command(specified_type: str | None = None) -> str | None:
|
|
60
64
|
current_dir = Path.cwd()
|
|
61
65
|
try:
|
|
62
66
|
repo = git.Repo(current_dir, search_parent_directories=True)
|
|
@@ -64,32 +68,45 @@ def get_ai_command() -> str | None:
|
|
|
64
68
|
print("[yellow]Not a git repository[/yellow]")
|
|
65
69
|
return None
|
|
66
70
|
diff = repo.git.diff("--cached")
|
|
71
|
+
|
|
72
|
+
current_branch = repo.active_branch.name
|
|
73
|
+
|
|
67
74
|
if not diff:
|
|
68
75
|
print("[yellow]No changes to commit, please add some changes before using AI[/yellow]")
|
|
69
76
|
return None
|
|
70
77
|
try:
|
|
71
78
|
from litellm import completion
|
|
72
79
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
80
|
+
# 准备模板渲染参数,如果用户指定了类型,则传递给模板
|
|
81
|
+
template_params = {"types": commit_types, "branch": current_branch}
|
|
82
|
+
|
|
83
|
+
if specified_type:
|
|
84
|
+
template_params["specified_type"] = specified_type
|
|
85
|
+
with console.status("[bold green]Generating commit message...[/bold green]"):
|
|
86
|
+
chat_completion = completion(
|
|
87
|
+
messages=[
|
|
88
|
+
{
|
|
89
|
+
"role": "system",
|
|
90
|
+
"content": commit_prompt_template.render(**template_params),
|
|
91
|
+
},
|
|
92
|
+
{"role": "user", "content": diff},
|
|
93
|
+
],
|
|
94
|
+
model=settings.get("model", "openai/gpt-4o"),
|
|
95
|
+
api_key=settings.get("apiKey", None),
|
|
96
|
+
base_url=settings.get("apiUrl", None),
|
|
97
|
+
max_tokens=200,
|
|
98
|
+
response_format=CommitData,
|
|
99
|
+
)
|
|
87
100
|
except Exception:
|
|
88
101
|
print("[red]Could not connect to AI provider[/red]")
|
|
89
102
|
return None
|
|
90
103
|
resp = CommitData.model_validate_json(chat_completion.choices[0].message.content)
|
|
104
|
+
|
|
105
|
+
# 如果用户指定了类型,则使用用户指定的类型
|
|
106
|
+
commit_type = specified_type or resp.type
|
|
107
|
+
|
|
91
108
|
return get_commit_command(
|
|
92
|
-
|
|
109
|
+
commit_type,
|
|
93
110
|
resp.scope,
|
|
94
111
|
resp.msg,
|
|
95
112
|
use_emoji=settings.get("commit", {}).get("emoji", False),
|
|
@@ -101,15 +118,26 @@ def handle_commit(args: CommitArgs) -> None:
|
|
|
101
118
|
prefix = ["", "!"]
|
|
102
119
|
choices = ["".join(data) for data in itertools.product(commit_types, prefix)] + ["ci", "test", "version"]
|
|
103
120
|
|
|
104
|
-
if args.ai:
|
|
121
|
+
if args.ai or len(args.message) == 0:
|
|
122
|
+
# 如果明确指定使用 AI
|
|
105
123
|
command = get_ai_command()
|
|
106
124
|
if not command:
|
|
107
125
|
return
|
|
126
|
+
elif len(args.message) == 1:
|
|
127
|
+
# 如果只提供了一个参数(只有类型)
|
|
128
|
+
commit_type = args.message[0]
|
|
129
|
+
if commit_type not in choices:
|
|
130
|
+
print(f"Invalid type: {commit_type}")
|
|
131
|
+
print(f"Valid types: {choices}")
|
|
132
|
+
return
|
|
133
|
+
|
|
134
|
+
# 使用 AI 生成提交信息,但保留用户指定的类型
|
|
135
|
+
command = get_ai_command(specified_type=commit_type)
|
|
136
|
+
if not command:
|
|
137
|
+
return
|
|
108
138
|
else:
|
|
139
|
+
# 正常的提交流程
|
|
109
140
|
messages = args.message
|
|
110
|
-
if len(messages) == 0:
|
|
111
|
-
print("Please provide a commit message, or use --ai to generate by AI")
|
|
112
|
-
return
|
|
113
141
|
commit_type = messages[0]
|
|
114
142
|
if len(messages) > 2: # noqa: PLR2004
|
|
115
143
|
commit_scope = messages[1]
|
|
@@ -126,4 +154,5 @@ def handle_commit(args: CommitArgs) -> None:
|
|
|
126
154
|
use_emoji = settings.get("commit", {}).get("emoji", False)
|
|
127
155
|
is_breaking = args.breaking
|
|
128
156
|
command = get_commit_command(commit_type, commit_scope, commit_msg, use_emoji=use_emoji, is_breaking=is_breaking)
|
|
157
|
+
|
|
129
158
|
run_command(command)
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
You are a git bot. You should read the diff and suggest a commit message.
|
|
2
2
|
|
|
3
3
|
Type:
|
|
4
|
-
|
|
4
|
+
{% if specified_type is defined %}
|
|
5
|
+
The user has specified the commit type as "{{ specified_type }}". You MUST honor this choice and generate a commit message that is appropriate for a "{{ specified_type }}" type of change.
|
|
6
|
+
{% else %}
|
|
5
7
|
The type should be one of {{ types | join(', ') }}.
|
|
8
|
+
{% endif %}
|
|
6
9
|
|
|
7
10
|
Scope:
|
|
8
11
|
|
|
@@ -25,6 +28,12 @@ Additional Considerations:
|
|
|
25
28
|
Search the name and instruction online for the copyright content check.
|
|
26
29
|
Make sure to search the name and instruction online for the copyright content check.
|
|
27
30
|
|
|
31
|
+
The Current Branch is {{ branch }}. You should referrence the branch name.
|
|
32
|
+
|
|
33
|
+
{% if specified_type is defined %}
|
|
34
|
+
IMPORTANT: The user has explicitly chosen "{{ specified_type }}" as the commit type. Your response MUST use this type. Do not change it.
|
|
35
|
+
{% endif %}
|
|
36
|
+
|
|
28
37
|
The Json format you return should be parsed to the following class:
|
|
29
38
|
|
|
30
39
|
```
|