Initial commit
This commit is contained in:
135
skills/pr-review-helper/SKILL.md
Normal file
135
skills/pr-review-helper/SKILL.md
Normal file
@@ -0,0 +1,135 @@
|
||||
---
|
||||
name: pr-review-helper
|
||||
description: Create pull requests with an interactive review and approval step. Use this skill when the user asks to create a pull request, open a PR, or submit their changes for review. This skill ensures PR descriptions are reviewed before submission.
|
||||
---
|
||||
|
||||
# PR Review Helper
|
||||
|
||||
## Overview
|
||||
|
||||
Create pull requests with an interactive review workflow that allows users to edit the PR description before submission. This skill analyzes all commits since diverging from the base branch and generates a comprehensive PR summary for user review.
|
||||
|
||||
## Workflow
|
||||
|
||||
Follow these steps sequentially when creating a pull request:
|
||||
|
||||
### 1. Gather Git Context
|
||||
|
||||
Collect all necessary git information to understand the full scope of changes:
|
||||
|
||||
- Current git status: `git status`
|
||||
- All changes since diverging from main: `git diff main...HEAD`
|
||||
- Current branch name: `git branch --show-current`
|
||||
- All commits on this branch: `git log main..HEAD`
|
||||
- Remote tracking status: `git status -b --porcelain | head -1`
|
||||
- Check if current branch tracks a remote: `git rev-parse --abbrev-ref @{upstream} 2>/dev/null || echo "No upstream tracking"`
|
||||
|
||||
Execute these commands in parallel for efficiency.
|
||||
|
||||
### 2. Analyze Changes and Draft PR Description
|
||||
|
||||
Based on the gathered context:
|
||||
|
||||
- Analyze ALL commits that will be included in the pull request (not just the latest commit)
|
||||
- Review the full diff to understand the complete scope of changes
|
||||
- Draft a comprehensive PR summary that includes:
|
||||
- Clear, descriptive title
|
||||
- Summary section with 1-3 bullet points covering the main changes
|
||||
- Test plan section with a bulleted markdown checklist of testing TODOs
|
||||
|
||||
### 3. Write Description to File for Review
|
||||
|
||||
Use the `write_pr_description.py` script to write the PR description to a deterministic location in `docs/prs/`:
|
||||
|
||||
```bash
|
||||
python scripts/write_pr_description.py "PR Title" "## Summary
|
||||
|
||||
- Main change point 1
|
||||
- Main change point 2
|
||||
- Main change point 3
|
||||
|
||||
## Test plan
|
||||
|
||||
- [ ] Test item 1
|
||||
- [ ] Test item 2
|
||||
- [ ] Test item 3"
|
||||
```
|
||||
|
||||
The script will:
|
||||
- Create the `docs/prs/` directory if it doesn't exist
|
||||
- Write the description to a timestamped file (e.g., `docs/prs/pr_20250129_143022.md`)
|
||||
- Display the file path for the user to review
|
||||
|
||||
Inform the user where the PR description has been written and ask them to review and edit it before creating the PR.
|
||||
|
||||
### 4. Wait for User Approval
|
||||
|
||||
After writing the description file, explicitly wait for the user to indicate they have reviewed and approved the description. Do not proceed to creating the PR until the user confirms they are ready.
|
||||
|
||||
### 5. Create the Pull Request
|
||||
|
||||
Once the user approves, use the `create_pr.py` script to create the PR:
|
||||
|
||||
```bash
|
||||
# Ensure current branch is pushed to remote with upstream tracking if needed
|
||||
git push -u origin $(git branch --show-current)
|
||||
|
||||
# Create the PR from the most recent description file
|
||||
python scripts/create_pr.py
|
||||
```
|
||||
|
||||
Optionally, specify a particular PR description file or base branch:
|
||||
|
||||
```bash
|
||||
# Use a specific PR description file
|
||||
python scripts/create_pr.py docs/prs/pr_20250129_143022.md
|
||||
|
||||
# Use a different base branch
|
||||
python scripts/create_pr.py docs/prs/pr_20250129_143022.md develop
|
||||
```
|
||||
|
||||
The script will:
|
||||
- Read the PR description file (uses the most recent one if not specified)
|
||||
- Parse the title and body
|
||||
- Create the PR using `gh pr create`
|
||||
- Display the PR URL
|
||||
- Clean up by deleting the PR description file
|
||||
|
||||
Return the PR URL to the user.
|
||||
|
||||
## Important Notes
|
||||
|
||||
- Always analyze ALL commits in the branch, not just the most recent one
|
||||
- The PR description should reflect the complete scope of changes since diverging from the base branch
|
||||
- Never skip the user review step - this is a critical part of the workflow
|
||||
- If the user provides additional notes or context as arguments, incorporate them into the PR description
|
||||
- The scripts handle file I/O and git operations deterministically, reducing errors
|
||||
- PR description files are stored in `docs/prs/` with timestamps for easy tracking
|
||||
|
||||
## Scripts Reference
|
||||
|
||||
### write_pr_description.py
|
||||
|
||||
Creates a PR description file in `docs/prs/` with a timestamp.
|
||||
|
||||
**Usage:**
|
||||
```bash
|
||||
python scripts/write_pr_description.py <title> <body>
|
||||
```
|
||||
|
||||
**Arguments:**
|
||||
- `title`: The PR title (required)
|
||||
- `body`: The PR body content with summary and test plan (required)
|
||||
|
||||
### create_pr.py
|
||||
|
||||
Creates a GitHub PR from a description file in `docs/prs/` and cleans up the file after.
|
||||
|
||||
**Usage:**
|
||||
```bash
|
||||
python scripts/create_pr.py [filepath] [base-branch]
|
||||
```
|
||||
|
||||
**Arguments:**
|
||||
- `filepath`: Path to PR description file (optional, defaults to most recent)
|
||||
- `base-branch`: Base branch for the PR (optional, defaults to "main")
|
||||
114
skills/pr-review-helper/scripts/create_pr.py
Executable file
114
skills/pr-review-helper/scripts/create_pr.py
Executable file
@@ -0,0 +1,114 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Create a GitHub pull request from a description file in docs/prs/.
|
||||
|
||||
This script reads the most recent (or specified) PR description file from docs/prs/
|
||||
and creates a pull request using the gh CLI tool.
|
||||
"""
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def get_latest_pr_file(pr_dir: Path) -> Path:
|
||||
"""Get the most recently created PR description file."""
|
||||
pr_files = sorted(pr_dir.glob("pr_*.md"), reverse=True)
|
||||
if not pr_files:
|
||||
raise FileNotFoundError(f"No PR description files found in {pr_dir}")
|
||||
return pr_files[0]
|
||||
|
||||
|
||||
def parse_pr_description(filepath: Path) -> tuple[str, str]:
|
||||
"""
|
||||
Parse PR description file to extract title and body.
|
||||
|
||||
Args:
|
||||
filepath: Path to the PR description file
|
||||
|
||||
Returns:
|
||||
Tuple of (title, body)
|
||||
"""
|
||||
content = filepath.read_text()
|
||||
lines = content.split("\n")
|
||||
|
||||
# Extract title (first line after removing '# ' prefix)
|
||||
title = lines[0].lstrip("# ").strip() if lines else ""
|
||||
|
||||
# Extract body (everything after the title)
|
||||
body = "\n".join(lines[2:]).strip() if len(lines) > 2 else ""
|
||||
|
||||
return title, body
|
||||
|
||||
|
||||
def create_pull_request(title: str, body: str, base: str = "main") -> str:
|
||||
"""
|
||||
Create a pull request using gh CLI.
|
||||
|
||||
Args:
|
||||
title: PR title
|
||||
body: PR body content
|
||||
base: Base branch (default: main)
|
||||
|
||||
Returns:
|
||||
The PR URL
|
||||
"""
|
||||
cmd = ["gh", "pr", "create", "--title", title, "--body", body, "--base", base]
|
||||
|
||||
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
||||
return result.stdout.strip()
|
||||
|
||||
|
||||
def main():
|
||||
pr_dir = Path("docs/prs")
|
||||
|
||||
if not pr_dir.exists():
|
||||
print(f"Error: {pr_dir} directory does not exist", file=sys.stderr)
|
||||
print(
|
||||
"Run write_pr_description.py first to create a PR description",
|
||||
file=sys.stderr,
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
# Get PR file (either specified or latest)
|
||||
if len(sys.argv) > 1:
|
||||
pr_file = Path(sys.argv[1])
|
||||
if not pr_file.exists():
|
||||
print(f"Error: File not found: {pr_file}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
else:
|
||||
try:
|
||||
pr_file = get_latest_pr_file(pr_dir)
|
||||
print(f"Using latest PR description: {pr_file}")
|
||||
except FileNotFoundError as e:
|
||||
print(f"Error: {e}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
# Parse the PR description
|
||||
title, body = parse_pr_description(pr_file)
|
||||
|
||||
if not title:
|
||||
print("Error: PR description file is missing a title", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
# Get base branch (default to main, but can be overridden)
|
||||
base = sys.argv[2] if len(sys.argv) > 2 else "main"
|
||||
|
||||
# Create the PR
|
||||
try:
|
||||
pr_url = create_pull_request(title, body, base)
|
||||
print("\n✅ Pull request created successfully!")
|
||||
print(f"URL: {pr_url}")
|
||||
|
||||
# Clean up the PR description file
|
||||
pr_file.unlink()
|
||||
print(f"\n🧹 Cleaned up: {pr_file}")
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
stderr_output = e.stderr if isinstance(e.stderr, str) else "" # pyright: ignore[reportAny]
|
||||
print(f"Error creating pull request: {stderr_output}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
59
skills/pr-review-helper/scripts/write_pr_description.py
Executable file
59
skills/pr-review-helper/scripts/write_pr_description.py
Executable file
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Write a PR description to a deterministic location for review.
|
||||
|
||||
This script creates a PR description file in docs/prs/ with a timestamp-based
|
||||
filename for easy tracking and review before submission.
|
||||
"""
|
||||
|
||||
import sys
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def write_pr_description(title: str, body: str) -> str:
|
||||
"""
|
||||
Write PR description to docs/prs/ directory.
|
||||
|
||||
Args:
|
||||
title: The PR title
|
||||
body: The PR body content
|
||||
|
||||
Returns:
|
||||
The path to the created file
|
||||
"""
|
||||
# Create docs/prs directory if it doesn't exist
|
||||
pr_dir = Path("docs/prs")
|
||||
pr_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Generate filename with timestamp
|
||||
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||
filename = pr_dir / f"pr_{timestamp}.md"
|
||||
|
||||
# Write the PR description
|
||||
content = f"# {title}\n\n{body}"
|
||||
_ = filename.write_text(content)
|
||||
|
||||
return str(filename)
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 3:
|
||||
print("Usage: write_pr_description.py <title> <body>", file=sys.stderr)
|
||||
print("\nExample:", file=sys.stderr)
|
||||
print(
|
||||
' write_pr_description.py "Add new feature" "## Summary\\n- Added X\\n- Fixed Y"',
|
||||
file=sys.stderr,
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
title = sys.argv[1]
|
||||
body = sys.argv[2]
|
||||
|
||||
filepath = write_pr_description(title, body)
|
||||
print(f"PR description written to: {filepath}")
|
||||
print("\nPlease review and edit the file before creating the PR.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user