Skip to content

Commit 84bc57d

Browse files
authored
feat: 添加自动更新检查功能 & 更新到0.2.0 (#12)
* feat: 添加自动更新检查功能 新增更新检查器模块,在程序启动时自动检查最新版本并提示用户更新 Signed-off-by: longjin <[email protected]> * docs(readme): 更新版本号至 v0.2.0 Signed-off-by: longjin <[email protected]> --------- Signed-off-by: longjin <[email protected]>
1 parent d4147e7 commit 84bc57d

File tree

9 files changed

+1363
-27
lines changed

9 files changed

+1363
-27
lines changed

Cargo.lock

Lines changed: 952 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "fastcommit"
3-
version = "0.1.7"
3+
version = "0.2.0"
44
description = "AI-based command line tool to quickly generate standardized commit messages."
55
edition = "2021"
66
authors = ["longjin <[email protected]>"]
@@ -10,12 +10,15 @@ keywords = ["fastcommit", "conventional-commits", "AI"]
1010

1111
[dependencies]
1212
anyhow = { version = "1.0.97", features = ["backtrace"] }
13+
chrono = { version = "0.4.38", features = ["serde"] }
1314
clap = { version = "4.5.31", features = ["derive"] }
1415
dirs = "6.0.0"
1516
env_logger = "0.11.6"
1617
lazy_static = "1.5.0"
1718
log = "0.4.26"
1819
openai_api_rust = { git = "https://github.com/fslongjin/openai-api", rev = "e2a3f6f" }
20+
reqwest = { version = "0.12.9", features = ["json"] }
1921
serde = { version = "1.0.218", features = ["derive"] }
22+
serde_json = "1.0.134"
2023
tokio = { version = "1.43.0", features = ["full"] }
2124
toml = "0.8.20"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ You can install `fastcommit` using the following method:
1010

1111
```bash
1212
# Install using cargo
13-
cargo install --git https://github.com/fslongjin/fastcommit --tag v0.1.7
13+
cargo install --git https://github.com/fslongjin/fastcommit --tag v0.2.0
1414
```
1515

1616
## Usage

README_CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
```bash
1010
# 使用 cargo 安装
11-
cargo install --git https://github.com/fslongjin/fastcommit --tag v0.1.7
11+
cargo install --git https://github.com/fslongjin/fastcommit --tag v0.2.0
1212
```
1313

1414
## 使用

src/cli.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ pub struct Args {
2727
#[clap(long, help = "Override branch prefix (default from config)")]
2828
pub branch_prefix: Option<String>,
2929

30-
#[clap(short, long, help = "Additional prompt to help AI understand the commit context")]
30+
#[clap(
31+
short,
32+
long,
33+
help = "Additional prompt to help AI understand the commit context"
34+
)]
3135
pub prompt: Option<String>,
3236

3337
#[clap(

src/constants.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,6 @@ username-refactor-payment-module
134134
135135
{{diff}}
136136
"#;
137+
138+
pub const UPDATE_CHECKER_URL: &str =
139+
"http://update-checker.longjin666.cn/v1/updates/fastcommit/latest";

src/generate.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ async fn generate_commit_message(
2828
format!("commit message: {}", desc)
2929
}
3030
});
31-
31+
3232
let template_ctx = TemplateContext::new(
3333
config.conventional,
3434
config.language,
@@ -130,13 +130,13 @@ fn get_diff(diff_file: Option<&str>, range: Option<&str>) -> anyhow::Result<Stri
130130
None => {
131131
let mut cmd = Command::new("git");
132132
cmd.arg("diff");
133-
133+
134134
if let Some(range_str) = range {
135135
cmd.arg(range_str);
136136
} else {
137137
cmd.arg("--cached");
138138
}
139-
139+
140140
let output = cmd.output()?;
141141
let diff_str = String::from_utf8_lossy(&output.stdout).into_owned();
142142
if diff_str.trim().is_empty() {

src/main.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use clap::Parser;
2+
use log::error;
23

34
#[macro_use]
45
extern crate lazy_static;
@@ -8,6 +9,7 @@ mod config;
89
mod constants;
910
mod generate;
1011
mod template_engine;
12+
mod update_checker;
1113

1214
#[tokio::main]
1315
async fn main() -> anyhow::Result<()> {
@@ -26,6 +28,8 @@ async fn main() -> anyhow::Result<()> {
2628
config.verbosity = v;
2729
}
2830

31+
run_update_checker().await;
32+
2933
if args.generate_branch {
3034
let branch_name = generate::generate_branch(&args, &config).await?;
3135
println!("Generated branch name: {}", branch_name);
@@ -35,3 +39,18 @@ async fn main() -> anyhow::Result<()> {
3539
}
3640
Ok(())
3741
}
42+
43+
async fn run_update_checker() {
44+
match update_checker::check_for_updates().await {
45+
Ok(Some(update_info)) => {
46+
update_checker::display_update_info(&update_info);
47+
}
48+
Ok(None) => {
49+
// 没有新版本,无需处理
50+
}
51+
Err(e) => {
52+
// 忽略更新检查错误,不影响主功能
53+
error!("Error checking for updates: {}", e);
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)