Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
8118937
feat: implement signoff feature for commit messages ✍️
mingcheng Mar 5, 2025
823f9e0
feat: add auto signoff detection from environment variable ✍️
mingcheng Mar 5, 2025
7d250da
docs: update README with new environment variable for signoff 📚
mingcheng Jun 30, 2025
758c8f0
style: update log message formatting in git and openai modules 🖌️ (#13)
mingcheng Jun 30, 2025
3766ebf
docs: correct environment variable name in README 📚
mingcheng Jun 30, 2025
2322b50
style: update log message formatting in git and openai modules 🖌️ (#13)
mingcheng Jun 30, 2025
5a433d8
docs: correct environment variable name in README 📚
mingcheng Jun 30, 2025
1fec4c7
docs: update file modification timestamps 📅
mingcheng Jun 30, 2025
4a2fd05
feat: update version to 1.3.3 and add grok keyword 🚀
mingcheng Jun 30, 2025
254047a
feat: add CLI check for OpenAI API and model availability 🔍
mingcheng Jun 30, 2025
0bb7d81
refactor: simplify string formatting in model validation 🛠️
mingcheng Jun 30, 2025
25bd5b8
feat: implement signoff feature for git commits ✍️
mingcheng Jul 11, 2025
c145e60
feat: update system template with new requirements ✏️
mingcheng Jul 18, 2025
2681a66
feat: bump version to 1.4.0 and update system template 🚀
mingcheng Aug 1, 2025
f00e6f1
feat: implement signoff feature for git commits ✍️
mingcheng Jul 11, 2025
0f66fa6
chore: update system template file ✨
mingcheng Sep 26, 2025
79c33bc
feat: introduce --check flag to validate OpenAI API and model availab…
mingcheng Sep 26, 2025
15812ba
feat: refine user template for improved clarity 📝
mingcheng Sep 26, 2025
0a7119d
Add a feat to auto sign off the commit if the environment is provided…
mingcheng Jun 30, 2025
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
687 changes: 376 additions & 311 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aigitcommit"
version = "1.3.3"
version = "1.4.0"
edition = "2021"
description = "A simple git commit message generator by OpenAI compaction model."
license-file = "LICENSE"
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@

![screenshots](./assets/screenshots.png)

A simple tool to help you write better Git commit messages using AI.
A simple tool to help you write Git semantic commit messages by using AI.

## References

- https://www.conventionalcommits.org/en/v1.0.0/
- https://nitayneeman.com/blog/understanding-semantic-commit-messages-using-git-and-angular/
- https://ssshooter.com/2020-09-30-commit-message/

## Features

Expand Down
2 changes: 1 addition & 1 deletion src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* File Created: 2025-03-01 21:55:54
*
* Modified By: mingcheng (mingcheng@apache.org)
* Last Modified: 2025-07-11 18:36:58
* Last Modified: 2025-09-26 14:43:17
*/

use git2::{Repository, RepositoryOpenFlags, Signature, StatusOptions};
Expand Down
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* File Created: 2025-03-01 17:17:30
*
* Modified By: mingcheng (mingcheng@apache.org)
* Last Modified: 2025-07-11 18:39:26
* Last Modified: 2025-09-26 15:45:37
*/

use aigitcommit::cli::Cli;
Expand Down Expand Up @@ -88,6 +88,8 @@ async fn main() -> std::result::Result<(), Box<dyn Error>> {
// Check if the model name is valid
if cli.check {
trace!("check option is enabled, will check the OpenAI API key and model name");
debug!("the model name is `{}`", &model_name);

match client.check_model(&model_name).await {
Ok(()) => {
debug!("the model name `{}` is available", model_name);
Expand Down
22 changes: 13 additions & 9 deletions src/openai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
* File Created: 2025-03-01 21:55:58
*
* Modified By: mingcheng (mingcheng@apache.org)
* Last Modified: 2025-07-11 17:45:53
* Last Modified: 2025-09-26 15:51:48
*/

use crate::cli;
use crate::cli::{CMD, CMD_ABOUT, CMD_ABOUT_URL};
use askama::Template;
use async_openai::config::OPENAI_API_BASE;
use async_openai::error::OpenAIError;
Expand Down Expand Up @@ -55,15 +55,19 @@ impl OpenAI {
.with_api_base(
env::var("OPENAI_API_BASE").unwrap_or_else(|_| String::from(OPENAI_API_BASE)),
)
.with_org_id(cli::CMD);
.with_org_id(CMD);

// Set up HTTP client builder with default headers
let mut http_client_builder = ClientBuilder::new().user_agent(cli::CMD).default_headers({
let mut headers = HeaderMap::new();
headers.insert("HTTP-Referer", HeaderValue::from_static(cli::CMD_ABOUT_URL));
headers.insert("X-Title", HeaderValue::from_static(cli::CMD));
headers
});
let mut http_client_builder = ClientBuilder::new()
.user_agent(format!("{} ({})", CMD, CMD_ABOUT))
.default_headers({
let mut headers = HeaderMap::new();
headers.insert("HTTP-Referer", HeaderValue::from_static(CMD_ABOUT_URL));
headers.insert("X-Title", HeaderValue::from_static(CMD));
headers.insert("X-Client-Type", HeaderValue::from_static("CLI"));
headers

});

// Set up proxy if specified
let proxy_addr: String = env::var("OPENAI_API_PROXY").unwrap_or_else(|_| String::from(""));
Expand Down
72 changes: 54 additions & 18 deletions templates/system.txt
Original file line number Diff line number Diff line change
@@ -1,35 +1,71 @@
You are an experienced senior in software development with years of experience contributing to the open-source community.
You are an expert in generating Git commit messages following the Conventional Commits specification, focusing on creating precise, meaningful, and standardized commit documentation. English must be your primary language.

You are a generator of git commit messages, utilising user-supplied logs and diffs to formulate a commit message.
Please generate a git commit message with the specified requirements.

Avoid needless language; be direct and concise.
1. Conventional Commit Format Structure:

English must be your primary language.
<type>[optional scope]: <brief description> [optional emoji]

Please generate a git commit message with the specified requirements.
[optional body]

2. Semantic Commit Types:

- feat: New feature
- fix: Bug fix
- docs: Documentation update
- style: Code formatting
- refactor: Code restructuring
- perf: Performance optimization
- test: Test modification
- build: Build system change
- ci: CI configuration update
- chore: Maintenance task
- revert: Revert previous change

3. Composition Rules:

- Header: Concise, max 50 characters
- Body: Max 5 bullet points
- Emphasize "what" and "why"
- Use imperative, present tense
- Be technical and objective
- Eliminate unnecessary words
- No personal pronouns

4. Formatting Principles:

1. First line: conventional commit format (type: concise explanation) (ensure the usage of semantic kinds such as feat, fix, docs, style, refactor, perf, test, chore, etc.).
- Capitalize first letter in the header
- No trailing period in the header
- Blank line between header and body
- Body uses bullet points
- No capitalization in the body at the start of bullet points
- Maintain consistent language
- The body should not exceed 72-80 characters per line
- The body should be sorted by priority in modifications

2. An emoji can be used appropriately at the end of the statement for the first line.
5. Optional Emoji:

3. Optional bullet points to provide further details, and briefly summarise, keeping it to no more than five main points.
- Symbolically represent commit type
- Only to enhance readability
- Not mandatory

- The second line should be left empty.
- Focus on changes and be succinct and clear.
- Steer clear of excessive information.
- Eliminate formal or superfluous language.
6. Avoid:

4. The optional bullet points should not contain the emoji or other non-English statements.
- Personal remarks
- Signed-off messages
- Overly detailed explanations
- Informal language
- Duplicate or similar descriptions

5. Deliver exclusively the commit message without any introductory remarks, explanations, or quotation marks.
7. Don't include any of the illustrations in your response.

6. Important: Don't include any of the illustrations in your response.
8. Your message should be based on the provided diff, with only minor styling taken from the most recent commits you will be reviewing.

7. Your message should be based on the provided diff, with only minor styling taken from the most recent commits you will be reviewing.
9. Importantly, directly output the above requirements without any additional content, including explanations, etc.

Finally, Here are a few examples that will be demonstrated below.

feat: add user auth system

- Add JWT tokens for API auth
- Handle token refresh for long sessions
- add JWT tokens for API auth
- handle token refresh for long sessions
8 changes: 6 additions & 2 deletions templates/user.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
The latest commit history from the repository is shown here, quote by using the "```" charsets.
The latest commit history from the repository is shown below, including the recent git commit messages:

```
{{logs}}
```

Additionally, a variety of content is provided below, quote by using the "```" charsets.
Please note that some commits may not relevantly affect the current code, as they might pertain to other changes.

Additionally, a variety of content is provided below:

```
{{diffs}}
```

Note that the main changes are in the diffs content above, while the commit history is provided for context.
Loading