Skip to content

Commit d7795a5

Browse files
committed
🔧 Update version and improve commit message handling
- Bump version from 0.26.1 to 0.26.2. - Enhance `CommitMessage` model for Python 3.9 compatibility by using `Optional[str]`. - Refactor commit message generation to handle optional details more gracefully.
1 parent 4d1cfb8 commit d7795a5

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

aicodebot/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
version = "0.26.1"
1+
version = "0.26.2"
22
AICODEBOT_NO_EMOJI = "AICodeBot"
33
AICODEBOT = f"🤖 {AICODEBOT_NO_EMOJI}"

aicodebot/commands/commit.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,22 @@
44
from aicodebot.output import OurMarkdown, get_console
55
from aicodebot.prompts import get_prompt
66
from pathlib import Path
7-
from pydantic import BaseModel, Field, constr
7+
from pydantic import BaseModel, Field
88
from rich.panel import Panel
9+
from typing import Optional
910
import click, os, shutil, subprocess, sys, tempfile
1011

1112

1213
class CommitMessage(BaseModel):
13-
git_message_summary: constr(max_length=72) = Field(
14-
description="A brief summary of the commit message (max 72 characters)"
15-
)
16-
git_message_detail: str | None = Field(
17-
default=None, description="An optional detailed explanation of the changes made in this commit"
14+
# Use Optional[str] instead of str | None for Python 3.9 compatibility
15+
git_message_detail: Optional[str] = Field( # noqa: UP007
16+
default="",
17+
description="An optional detailed explanation of the changes made in this commit,"
18+
" if the summary doesn't provide enough context",
1819
)
1920

21+
git_message_summary: str = Field(description="A brief summary of the commit message (max 72 characters)")
22+
2023

2124
@click.command()
2225
@click.option("-t", "--response-token-size", type=int, default=250)
@@ -100,15 +103,18 @@ def commit(response_token_size, yes, skip_pre_commit, files): # noqa: PLR0915
100103
chain = prompt | structured_llm
101104
response = chain.invoke({"diff_context": diff_context, "languages": languages})
102105

103-
console.print(Panel(OurMarkdown(f"{response.git_message_summary}\n\n{response.git_message_detail}")))
106+
commit_message = response["git_message_summary"]
107+
if response.get("git_message_detail"):
108+
commit_message += f"\n\n{response['git_message_detail']}"
109+
110+
console.print(Panel(OurMarkdown(commit_message)))
104111

105112
commit_message_approved = not console.is_terminal or click.confirm(
106113
"Would you like to use this generated commit message? Type 'n' to edit it.", default=True
107114
)
108115

109116
# Write the commit message to a temporary file
110117
with tempfile.NamedTemporaryFile(mode="w", delete=False) as temp:
111-
commit_message = f"{response.git_message_summary}\n\n{response.git_message_detail}"
112118
temp.write(commit_message)
113119
temp_file_name = temp.name
114120

0 commit comments

Comments
 (0)