Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
48 changes: 44 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ NOTE: All common config can be configured via `~/.fastcommit/config.toml`
```bash
# Generate commit message for the last commit
fastcommit -r HEAD~1

# Generate commit message for a range of commits
fastcommit -r abc123..def456
```
Expand All @@ -96,10 +96,10 @@ NOTE: All common config can be configured via `~/.fastcommit/config.toml`
```bash
# Disable text wrapping
fastcommit --no-wrap

# Set custom line width
fastcommit --wrap-width 60

# Combine with other options
fastcommit -b -m --wrap-width 100
```
Expand All @@ -114,9 +114,49 @@ NOTE: All common config can be configured via `~/.fastcommit/config.toml`
fastcommit -c --commit-args "-s" --commit-args "--no-verify"
```

## GitHub PR Integration

`fastcommit` can generate commit messages for GitHub Pull Requests, which is useful when merging PRs.

### Prerequisites

- [GitHub CLI (`gh`)](https://cli.github.com/) must be installed and authenticated

### Usage

```bash
# Auto-detect PR from current branch
fastcommit pr

# Generate commit message for a specific PR
fastcommit pr 123

# Specify repository (when not in a git directory)
fastcommit pr 123 --repo owner/repo

# Use conventional commit style
fastcommit pr 123 --conventional true

# Specify language
fastcommit pr 123 -l zh
```

### PR Command Options

- `[PR_NUMBER]`: PR number to generate commit message for. If not specified, auto-detects from current branch.
- `--repo <REPO>`: Specify repository in `owner/repo` format.
- `--conventional <CONVENTIONAL>`: Enable conventional commit style.
- `-l, --language <LANGUAGE>`: Specify language (`en` or `zh`).
- `-v, --verbosity <VERBOSITY>`: Set detail level (`verbose`, `normal`, `quiet`).
- `-p, --prompt <PROMPT>`: Additional context for AI.
- `--no-sanitize`: Disable sensitive info sanitizer.
- `--no-wrap`: Disable text wrapping.

For more details, see [GitHub PR Integration Guide](docs/github-pr-integration.md).

## Contributing

Contributions of code or suggestions are welcome! Please read the [Contributing Guide](CONTRIBUTING.md) first.
Contributions of code or suggestions are welcome! Please read the [Contributing Guide](CONTRIBUTING.md) first.

## License

Expand Down
50 changes: 45 additions & 5 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cargo install --git https://github.com/fslongjin/fastcommit --tag v0.6.0

```bash
git add .
fastcommit
fastcommit
```

### 选项
Expand All @@ -29,7 +29,7 @@ NOTE: All common config can be configured via `~/.fastcommit/config.toml`
- `-l, --language <LANGUAGE>`: 指定提交信息的语言。可选值为 `en`(英文)或 `zh`(中文)。
- `-b, --generate-branch`: 生成分支名
- `--branch-prefix`: 生成的分支名的前缀
- `-m, --message`: 生成提交信息(与 -b 一起使用可同时输出)
- `-m, --message`: 生成提交信息(与 -b 一起使用可同时输出)
- `-v, --verbosity <VERBOSITY>`: 设置提交信息的详细级别。可选值为 `verbose`(详细)、`normal`(正常)或 `quiet`(简洁)。 默认为 `quiet`。
- `-p, --prompt <PROMPT>`: 额外的提示信息,帮助 AI 理解提交上下文。
- `-r, --range <RANGE>`: 指定差异范围以生成提交信息(例如:HEAD~1, abc123..def456)。
Expand Down Expand Up @@ -83,7 +83,7 @@ NOTE: All common config can be configured via `~/.fastcommit/config.toml`
```bash
# 为最近一次提交生成提交信息
fastcommit -r HEAD~1

# 为指定提交范围生成提交信息
fastcommit -r abc123..def456
```
Expand All @@ -93,10 +93,10 @@ NOTE: All common config can be configured via `~/.fastcommit/config.toml`
```bash
# 禁用文本换行
fastcommit --no-wrap

# 设置自定义行宽度
fastcommit --wrap-width 60

# 与其他选项组合使用
fastcommit -b -m --wrap-width 100
```
Expand All @@ -111,6 +111,46 @@ NOTE: All common config can be configured via `~/.fastcommit/config.toml`
fastcommit -c --commit-args "-s" --commit-args "--no-verify"
```

## GitHub PR 集成

`fastcommit` 可以为 GitHub Pull Request 生成提交信息,适用于合并 PR 时使用。

### 前置条件

- 需要安装并登录 [GitHub CLI (`gh`)](https://cli.github.com/)

### 使用方法

```bash
# 自动检测当前分支关联的 PR
fastcommit pr

# 为指定 PR 生成提交信息
fastcommit pr 123

# 指定仓库(不在 git 目录中时)
fastcommit pr 123 --repo owner/repo

# 使用约定式提交风格
fastcommit pr 123 --conventional true

# 指定语言
fastcommit pr 123 -l zh
```

### PR 命令选项

- `[PR_NUMBER]`: PR 编号,不指定则自动检测当前分支关联的 PR
- `--repo <REPO>`: 指定仓库,格式为 `owner/repo`
- `--conventional <CONVENTIONAL>`: 启用约定式提交风格
- `-l, --language <LANGUAGE>`: 指定语言(`en` 或 `zh`)
- `-v, --verbosity <VERBOSITY>`: 设置详细级别(`verbose`、`normal`、`quiet`)
- `-p, --prompt <PROMPT>`: 额外的提示信息
- `--no-sanitize`: 禁用敏感信息清理
- `--no-wrap`: 禁用文本换行

更多详情请参阅 [GitHub PR 集成指南](docs/github-pr-integration.md)。

## 贡献

欢迎贡献代码或提出建议!请先阅读 [贡献指南](CONTRIBUTING.md)。
Expand Down
191 changes: 191 additions & 0 deletions docs/github-pr-integration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
# GitHub PR Integration

This document describes how to use `fastcommit` to generate commit messages for GitHub Pull Requests.

## Overview

The `fastcommit pr` command allows you to generate a commit message for an entire Pull Request. This is particularly useful when you're ready to merge a PR and need a comprehensive commit message that summarizes all the changes.

## Prerequisites

Before using the PR integration, ensure you have:

1. **GitHub CLI (`gh`) installed**

```bash
# Check if gh is installed
gh --version

# Install gh on macOS
brew install gh

# Install gh on Linux
# See: https://github.com/cli/cli/blob/trunk/docs/install_linux.md
```

2. **GitHub CLI authenticated**

```bash
gh auth login
```

## Usage

### Basic Usage

```bash
# Auto-detect PR from current branch
fastcommit pr

# Generate commit message for a specific PR
fastcommit pr 123
```

### Specify Repository

When running `fastcommit pr` outside the target repository, use the `--repo` flag:

```bash
fastcommit pr 123 --repo owner/repo
```

### All Options

```
fastcommit pr [PR_NUMBER] [OPTIONS]

Arguments:
[PR_NUMBER] PR number to generate commit message for.
If not specified, auto-detects from current branch.

Options:
--repo <REPO> Specify repository (format: owner/repo)
--conventional <BOOL> Enable conventional commit style (true/false)
-l, --language <LANG> Specify language (en/zh)
-v, --verbosity <LEVEL> Set detail level (verbose/normal/quiet)
-p, --prompt <TEXT> Additional context for AI
--no-sanitize Disable sensitive info sanitizer
--no-wrap Disable text wrapping
--wrap-width <WIDTH> Set custom line width for wrapping
```

## Examples

### Generate commit message for current branch's PR

```bash
# Assuming you're on a branch with an open PR
fastcommit pr
```

Output:
```
feat: add user authentication system

- Implement JWT-based authentication
- Add login/logout endpoints
- Integrate with existing user service
- Add rate limiting for auth endpoints
```

### Generate with conventional commit style

```bash
fastcommit pr 456 --conventional true
```

Output:
```
fix(auth): resolve token refresh issue

- Fix improper token validation on refresh
- Add proper error handling for expired tokens
- Update token storage to use secure cookies
```

### Add context for better results

```bash
fastcommit pr 789 -p "This PR fixes the performance issues reported in issue #123"
```

### Generate in Chinese

```bash
fastcommit pr 123 -l zh
```

Output:
```
feat: 添加用户认证系统

- 实现 JWT 认证机制
- 添加登录/登出接口
- 与现有用户服务集成
- 添加认证接口的速率限制
```

## How It Works

1. **PR Detection**: If no PR number is specified, `fastcommit` uses `gh pr view` to detect the PR associated with the current branch.

2. **Diff Retrieval**: The tool fetches the PR diff using `gh pr diff`.

3. **Message Generation**: The diff is processed by the AI to generate a commit message, using the same logic as the standard `fastcommit` command.

## Troubleshooting

### "GitHub CLI (gh) is not installed"

Install GitHub CLI:
- **macOS**: `brew install gh`
- **Linux**: See [installation guide](https://github.com/cli/cli/blob/trunk/docs/install_linux.md)
- **Windows**: `winget install GitHub.cli`

### "Failed to detect current PR"

This happens when:
- You're not on a branch with an open PR
- The PR is in a different repository

**Solution**: Specify the PR number explicitly:
```bash
fastcommit pr 123
```

### "gh pr diff failed"

This usually indicates:
- You're not authenticated with GitHub CLI

**Solution**: Run `gh auth login`

### "No diff found for PR"

This happens when the PR has no changes (empty PR).

## Tips

1. **Use with PR merge**: Generate the commit message before merging:
```bash
# Generate the message
fastcommit pr 123

# Then merge with the generated message
gh pr merge 123 --merge
```

2. **Combine with conventional commits**: For projects following conventional commit conventions:
```bash
fastcommit pr 123 --conventional true
```

3. **Add merge context**: Provide additional context about the PR's purpose:
```bash
fastcommit pr 123 -p "Closes #456, implements feature requested by users"
```

## Related Documentation

- [README.md](../README.md) - Main documentation
- [GitHub CLI Documentation](https://cli.github.com/manual/)
Loading