Skip to content

Commit f0a9332

Browse files
authored
feat: 添加同时生成分支名和提交信息的功能 (#15)
* docs: 更新命令行选项文档和功能说明 更新 README 和 README_CN 文档,添加 -m/--message 选项说明和示例用法。同时修改 CLI 参数别名,将 -gb 改为 -b,并添加 generate_message 字段支持同时生成分支名和提交信息的功能。 Signed-off-by: jinlong <jinlong@tencent.com> * chore: 更新版本号至0.2.3 更新Cargo.toml、Cargo.lock及README文档中的版本号,从0.2.2升级至0.2.3。 Signed-off-by: jinlong <jinlong@tencent.com> --------- Signed-off-by: jinlong <jinlong@tencent.com>
1 parent ab34ca5 commit f0a9332

7 files changed

Lines changed: 64 additions & 11 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "fastcommit"
3-
version = "0.2.2"
3+
version = "0.2.3"
44
description = "AI-based command line tool to quickly generate standardized commit messages."
55
edition = "2021"
66
authors = ["longjin <fslongjin@vip.qq.com>"]

README.md

Lines changed: 16 additions & 3 deletions
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.2.2
13+
cargo install --git https://github.com/fslongjin/fastcommit --tag v0.2.3
1414
```
1515

1616
## Usage
@@ -29,8 +29,9 @@ NOTE: All common config can be configured via `~/.fastcommit/config.toml`
2929
- `-d, --diff-file <DIFF_FILE>`: Specify the path to the file containing the differences.
3030
- `--conventional <CONVENTIONAL>`: Enable or disable conventional commit style analysis. Acceptable values are `true` or `false`.
3131
- `-l, --language <LANGUAGE>`: Specify the language for the commit message. Acceptable values are `en` (English) or `zh` (Chinese).
32-
- `-gb, --generate-branch`: Generate branch name.
32+
- `-b, --generate-branch`: Generate branch name.
3333
- `--branch-prefix`: prefix of the generated branch name
34+
- `-m, --message`: Generate commit message (use with -b to output both)
3435
- `-v, --verbosity <VERBOSITY>`: Set the detail level of the commit message. Acceptable values are `verbose` (detailed), `normal`, or `quiet` (concise). The default is `quiet`.
3536
- `-p, --prompt <PROMPT>`: Additional prompt to help AI understand the commit context.
3637
- `-r, --range <RANGE>`: Specify diff range for generating commit message (e.g. HEAD~1, abc123..def456).
@@ -63,7 +64,19 @@ NOTE: All common config can be configured via `~/.fastcommit/config.toml`
6364
fastcommit -d changes.diff -p "Fixed login page styling issues, especially button alignment"
6465
```
6566

66-
5. Generate commit message for a specific diff range:
67+
5. Generate branch name only:
68+
69+
```bash
70+
fastcommit -b
71+
```
72+
73+
6. Generate both branch name and commit message:
74+
75+
```bash
76+
fastcommit -b -m
77+
```
78+
79+
7. Generate commit message for a specific diff range:
6780

6881
```bash
6982
# Generate commit message for the last commit

README_CN.md

Lines changed: 17 additions & 4 deletions
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.2.2
11+
cargo install --git https://github.com/fslongjin/fastcommit --tag v0.2.3
1212
```
1313

1414
## 使用
@@ -27,8 +27,9 @@ NOTE: All common config can be configured via `~/.fastcommit/config.toml`
2727
- `-d, --diff-file <DIFF_FILE>`: 指定包含差异的文件路径。
2828
- `--conventional <CONVENTIONAL>`: 启用或禁用规范提交风格分析。可选值为 `true``false`
2929
- `-l, --language <LANGUAGE>`: 指定提交信息的语言。可选值为 `en`(英文)或 `zh`(中文)。
30-
- `-gb, --generate-branch`: 模式:生成分支名
31-
- `--branch-prefix`: 生成的分支名的前缀
30+
- `-b, --generate-branch`: 生成分支名
31+
- `--branch-prefix`: 生成的分支名的前缀
32+
- `-m, --message`: 生成提交信息(与 -b 一起使用可同时输出)
3233
- `-v, --verbosity <VERBOSITY>`: 设置提交信息的详细级别。可选值为 `verbose`(详细)、`normal`(正常)或 `quiet`(简洁)。 默认为 `quiet`
3334
- `-p, --prompt <PROMPT>`: 额外的提示信息,帮助 AI 理解提交上下文。
3435
- `-r, --range <RANGE>`: 指定差异范围以生成提交信息(例如:HEAD~1, abc123..def456)。
@@ -61,7 +62,19 @@ NOTE: All common config can be configured via `~/.fastcommit/config.toml`
6162
fastcommit -d changes.diff -p "修复了登录页面的样式问题,特别是按钮对齐"
6263
```
6364

64-
5. 为特定的差异范围生成提交信息:
65+
5. 仅生成分支名:
66+
67+
```bash
68+
fastcommit -b
69+
```
70+
71+
6. 同时生成分支名和提交信息:
72+
73+
```bash
74+
fastcommit -b -m
75+
```
76+
77+
7. 为特定的差异范围生成提交信息:
6578

6679
```bash
6780
# 为最近一次提交生成提交信息

src/cli.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub struct Args {
2525

2626
#[clap(
2727
long = "generate-branch",
28-
alias = "gb",
28+
short = 'b',
2929
help = "Generate a branch name based on changes (optionally with prefix)"
3030
)]
3131
pub generate_branch: bool,
@@ -46,4 +46,11 @@ pub struct Args {
4646
help = "Specify diff range (e.g. HEAD~1, abc123..def456)"
4747
)]
4848
pub range: Option<String>,
49+
50+
#[clap(
51+
short = 'm',
52+
long = "message",
53+
help = "Generate commit message (use with -b to output both)"
54+
)]
55+
pub generate_message: bool,
4956
}

src/generate.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,3 +238,14 @@ pub async fn generate_branch(args: &cli::Args, config: &Config) -> anyhow::Resul
238238
let branch_name = generate_branch_name_with_ai(&diff, prefix, config).await?;
239239
Ok(branch_name)
240240
}
241+
242+
pub async fn generate_both(args: &cli::Args, config: &Config) -> anyhow::Result<(String, String)> {
243+
let diff = get_diff(args.diff_file.as_deref(), args.range.as_deref())?;
244+
let prefix = args
245+
.branch_prefix
246+
.as_deref()
247+
.or(config.branch_prefix.as_deref());
248+
let branch_name = generate_branch_name_with_ai(&diff, prefix, config).await?;
249+
let commit_message = generate_commit_message(&diff, config, args.prompt.as_deref()).await?;
250+
Ok((branch_name, commit_message))
251+
}

src/main.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,19 @@ async fn main() -> anyhow::Result<()> {
2727

2828
run_update_checker().await;
2929

30-
if args.generate_branch {
30+
// 根据参数决定生成内容:
31+
// 1. --gb --m 同时:生成分支名 + 提交信息
32+
// 2. 仅 --gb:只生成分支名
33+
// 3. 默认(无 --gb 或仅 --m):生成提交信息
34+
if args.generate_branch && args.generate_message {
35+
let (branch_name, msg) = generate::generate_both(&args, &config).await?;
36+
println!("Generated branch name: {}", branch_name);
37+
println!("{}", msg);
38+
} else if args.generate_branch {
3139
let branch_name = generate::generate_branch(&args, &config).await?;
3240
println!("Generated branch name: {}", branch_name);
3341
} else {
42+
// 包括:无参数 或 仅 --m
3443
let msg = generate::generate(&args, &config).await?;
3544
println!("{}", msg);
3645
}

0 commit comments

Comments
 (0)