Skip to content

Commit 00de58d

Browse files
committed
✨ Add PR description generation
Add functionality to generate pull request descriptions. - Add 'pr' subcommand to CLI for generating PR descriptions - Implement logic to compare branches or analyze commit ranges - Create service functions for generating PR descriptions from commits or branch differences. - Implement MCP tool 'git_iris_pr' for generating PR descriptions. - Update documentation and README files with usage instructions.
1 parent 902265f commit 00de58d

File tree

16 files changed

+1857
-73
lines changed

16 files changed

+1857
-73
lines changed

README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,81 @@ The review includes:
353353
- Test Coverage - Analyzes test coverage gaps or brittle tests
354354
- Best Practices - Checks adherence to language-specific conventions and design guidelines
355355

356+
### Generate Pull Request Descriptions
357+
358+
Create comprehensive PR descriptions for changesets spanning multiple commits or single commits:
359+
360+
```bash
361+
git-iris pr --from <from-ref> --to <to-ref>
362+
```
363+
364+
Options:
365+
366+
- `--from`: Starting Git reference (commit hash, tag, or branch name)
367+
- `--to`: Ending Git reference (defaults to HEAD if not specified)
368+
- `-i`, `--instructions`: Custom instructions for PR description generation
369+
- `--preset`: Select an instruction preset for PR description generation
370+
- `-p`, `--print`: Print the generated PR description to stdout and exit
371+
372+
**Examples:**
373+
374+
**Single commit analysis:**
375+
```bash
376+
# Analyze a single commit (compares against its parent)
377+
git-iris pr --from abc1234
378+
git-iris pr --to abc1234
379+
380+
# Analyze a specific commitish (e.g., 2 commits ago)
381+
git-iris pr --to HEAD~2
382+
383+
# Same commit for both from and to
384+
git-iris pr --from abc1234 --to abc1234
385+
```
386+
387+
**Multiple commit analysis:**
388+
```bash
389+
# Review the last 3 commits together
390+
git-iris pr --from HEAD~3
391+
392+
# Review commits from a specific point to now
393+
git-iris pr --from @~5
394+
```
395+
396+
**Commit range analysis:**
397+
```bash
398+
git-iris pr --from v1.0.0 --to HEAD --preset detailed
399+
```
400+
401+
**Branch comparison:**
402+
```bash
403+
git-iris pr --from main --to feature-auth --preset conventional
404+
```
405+
406+
**Comparison to main:**
407+
```bash
408+
# Compare feature branch to main
409+
git-iris pr --to feature-branch
410+
```
411+
412+
The PR description generator analyzes the entire changeset as an atomic unit rather than individual commits, providing:
413+
414+
- A comprehensive title and summary
415+
- Detailed description of what was changed and why
416+
- List of commits included in the PR
417+
- Breaking changes identification
418+
- Testing notes and deployment considerations
419+
- Technical implementation details
420+
421+
This is particularly useful for:
422+
- **Single commits**: Get detailed analysis of what changed in a specific commit or commitish (e.g., `HEAD~2`)
423+
- **Multiple commits**: Review a range of commits together (e.g., `--from HEAD~3` reviews the last 3 commits)
424+
- **Feature branches**: Get a complete overview of all changes in a feature
425+
- **Release preparations**: Understand what's included in a release candidate
426+
- **Code reviews**: Provide reviewers with comprehensive context
427+
- **Documentation**: Create detailed records of what changed between versions
428+
429+
**Supported commitish syntax**: `HEAD~2`, `HEAD^`, `@~3`, `main~1`, `origin/main^`, and other Git commitish references.
430+
356431
### Generate Changelogs
357432

358433
Create a detailed changelog between Git references:

docs/MCP.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,75 @@ Example (remote URL):
103103
}
104104
```
105105

106+
### `git_iris_pr`
107+
108+
Generate comprehensive pull request descriptions for changesets spanning multiple commits or single commits. Analyzes commits and changes as an atomic unit rather than individual commits. Supports Git commitish syntax like `HEAD~2`, `HEAD^`, `@~3`, etc.
109+
110+
**Parameters:**
111+
112+
- `from`: (string, required) Starting reference (commit hash, tag, branch name, or commitish)
113+
- `to`: (string) Ending reference (defaults to HEAD if not specified)
114+
- `preset`: (string) Preset instruction set to use for the PR description
115+
- `custom_instructions`: (string) Custom instructions for the AI
116+
- `repository`: (string, required) Repository path (local) or URL (remote). **Required.**
117+
118+
Example (single commit analysis):
119+
120+
```json
121+
{
122+
"from": "abc1234",
123+
"preset": "conventional",
124+
"custom_instructions": "Focus on the specific changes made in this commit",
125+
"repository": "/home/bliss/dev/myproject"
126+
}
127+
```
128+
129+
Example (multiple commits using commitish):
130+
131+
```json
132+
{
133+
"from": "HEAD~3",
134+
"preset": "conventional",
135+
"custom_instructions": "Review the last 3 commits together as a cohesive change",
136+
"repository": "/home/bliss/dev/myproject"
137+
}
138+
```
139+
140+
Example (single commitish analysis):
141+
142+
```json
143+
{
144+
"to": "HEAD~2",
145+
"preset": "detailed",
146+
"custom_instructions": "Analyze what changed 2 commits ago",
147+
"repository": "/home/bliss/dev/myproject"
148+
}
149+
```
150+
151+
Example (branch comparison):
152+
153+
```json
154+
{
155+
"from": "main",
156+
"to": "feature-auth",
157+
"preset": "conventional",
158+
"custom_instructions": "Highlight security implications and breaking changes",
159+
"repository": "/home/bliss/dev/myproject"
160+
}
161+
```
162+
163+
Example (commit range - remote URL):
164+
165+
```json
166+
{
167+
"from": "v1.0.0",
168+
"to": "HEAD",
169+
"preset": "detailed",
170+
"custom_instructions": "Focus on user-facing changes",
171+
"repository": "https://github.com/example/repo.git"
172+
}
173+
```
174+
106175
### `git_iris_changelog`
107176

108177
Generate a detailed changelog between two Git references.

src/cli.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,38 @@ pub enum Commands {
144144
to: Option<String>,
145145
},
146146

147+
/// Generate a pull request description
148+
#[command(
149+
about = "Generate a pull request description using AI",
150+
long_about = "Generate a comprehensive pull request description based on commit ranges, branch differences, or single commits. Analyzes the overall changeset as an atomic unit and creates professional PR descriptions with summaries, detailed explanations, and testing notes.\n\nUsage examples:\n• Single commit: --from abc1234 or --to abc1234\n• Single commitish: --from HEAD~1 or --to HEAD~2\n• Multiple commits: --from HEAD~3 (reviews last 3 commits)\n• Commit range: --from abc1234 --to def5678\n• Branch comparison: --from main --to feature-branch\n• From main to branch: --to feature-branch\n\nSupported commitish syntax: HEAD~2, HEAD^, @~3, main~1, origin/main^, etc."
151+
)]
152+
Pr {
153+
#[command(flatten)]
154+
common: CommonParams,
155+
156+
/// Print the generated PR description to stdout and exit
157+
#[arg(
158+
short,
159+
long,
160+
help = "Print the generated PR description to stdout and exit"
161+
)]
162+
print: bool,
163+
164+
/// Starting branch, commit, or commitish for comparison
165+
#[arg(
166+
long,
167+
help = "Starting branch, commit, or commitish for comparison. For single commit analysis, specify just this parameter with a commit hash (e.g., --from abc1234). For reviewing multiple commits, use commitish syntax (e.g., --from HEAD~3 to review last 3 commits)"
168+
)]
169+
from: Option<String>,
170+
171+
/// Target branch, commit, or commitish for comparison
172+
#[arg(
173+
long,
174+
help = "Target branch, commit, or commitish for comparison. For single commit analysis, specify just this parameter with a commit hash or commitish (e.g., --to HEAD~2)"
175+
)]
176+
to: Option<String>,
177+
},
178+
147179
/// Generate a changelog
148180
#[command(
149181
about = "Generate a changelog",
@@ -578,5 +610,31 @@ pub async fn handle_command(
578610
print,
579611
} => commands::handle_project_config_command(&common, model, token_limit, param, print),
580612
Commands::ListPresets => commands::handle_list_presets_command(),
613+
Commands::Pr {
614+
common,
615+
print,
616+
from,
617+
to,
618+
} => handle_pr(common, print, from, to, repository_url).await,
581619
}
582620
}
621+
622+
/// Handle the `Pr` command
623+
async fn handle_pr(
624+
common: CommonParams,
625+
print: bool,
626+
from: Option<String>,
627+
to: Option<String>,
628+
repository_url: Option<String>,
629+
) -> anyhow::Result<()> {
630+
log_debug!(
631+
"Handling 'pr' command with common: {:?}, print: {}, from: {:?}, to: {:?}",
632+
common,
633+
print,
634+
from,
635+
to
636+
);
637+
ui::print_version(crate_version!());
638+
ui::print_newline();
639+
commit::handle_pr_command(common, print, repository_url, from, to).await
640+
}

0 commit comments

Comments
 (0)