Agent pr creator

From ravnhq/ai-toolkit · View interactive version

Agent pr creator is an AI agent skill from the GitHub repository ravnhq/ai-toolkit. Analyzes git diffs and commit history to intelligently fill PR templates and create pull requests via gh CLI. Use when: creating a PR, needing PR description help, saying ''create a pull request'', ''fill PR template'', ''make a PR'', ''open a pull request''. Triggers on: create PR, open pull reques

How to use this skill

Skill file

Agent PR Creator

Analyze git diffs and commit history to intelligently fill PR templates and create pull requests via gh CLI. This skill walks through detecting the base branch, analyzing changes, reading the project's PR template, filling it with context from commits and diffs, and creating the PR.

Workflow

Phase 1: Detect Base Branch and Check for Existing PR

Determine what base branch this PR will target:

# Check if develop exists; fall back to main
git rev-parse --verify develop 2>/dev/null && echo "develop" || echo "main"

# Current branch
git branch --show-current

Check if a PR already exists for the current branch:

gh pr list --head $(git branch --show-current) --json number,url,title

If a PR exists, stop and inform the user. Ask if they want to update the description with gh pr edit instead.

Gate: If there are uncommitted changes or the branch is behind remote, warn the user and stop:

# Check for uncommitted changes
git status --porcelain

# Check if branch is behind remote
git rev-parse @{u} 2>/dev/null && git log --oneline @..@{u}

If the branch has no remote tracking, push with -u before creating the PR:

git push -u origin $(git branch --show-current)

Phase 2: Analyze Changes

Gather the full context of changes since the base branch:

# Get the base branch
BASE=$(git rev-parse --verify develop 2>/dev/null && echo "develop" || echo "main")

# Changed files
git diff ${BASE}...HEAD --name-only

# Commit log with oneline format
git log --oneline ${BASE}..HEAD

# Diff stats (file-level changes)
git diff ${BASE}...HEAD --stat

# Full diff for review (optional, context-dependent)
git diff ${BASE}...HEAD

Analyze the changes to understand:

Phase 3: Read the PR Template

Locate and read the project's PR template:

# Standard locations
ls -la .github/PULL_REQUEST_TEMPLATE.md .github/pull_request_template.md PULL_REQUEST_TEMPLATE.md pull_request_template.md 2>/dev/null | head -1

If found, read the entire template to understand:

If no template is found, create a minimal PR with just title and description.

Phase 4: Fill the PR Template

Fill each section of the template based on the changes:

Title: Use conventional commit format

Description:

Type of Change:

Breaking Changes:

Screenshots / Videos:

Additional Notes / Checklist:

Phase 5: Create the PR

Use gh pr create with the filled template and title:

gh pr create \
  --base ${BASE} \
  --title "<type>: <short description>" \
  --body "<filled template body as HEREDOC or string>"

Example:

gh pr create --base develop \
  --title "feat: add authentication service integration" \
  --body $'## Description\nAdds OAuth 2.0 support for third-party integrations.\n\n## Type of Change\n- [x] New Feature\n- [ ] Bug Fix\n\n## Breaking Changes\n- [ ] Yes\n- [x] No\n\n## Screenshots\nN/A'

Important: Preserve markdown formatting from the template. Use shell HEREDOC ($'...') or multi-line strings to maintain section separators and formatting.

Phase 6: Confirm and Report

After gh pr create succeeds, output:

  1. The PR URL (e.g., https://github.com/owner/repo/pull/456)
  2. PR number
  3. A brief summary of what was included (types of changes, key areas affected)
  4. Mention if any reviewers were auto-assigned or any special status (draft, ready for review)

Example output:

PR created: https://github.com/ravn/ai-toolkit/pull/123
Type: feat (New Feature)
Changes: 3 files, 156 additions
Affected areas: Authentication service, OAuth integration tests
Ready for review.

Examples

Positive Trigger

User: "fill the PR template and create a pull request for my branch"

Expected behavior: Use agent-pr-creator workflow to analyze git history, read the PR template, fill all sections intelligently based on the changes, and create the PR via gh pr create.


User: "I need to open a pull request with a good description"

Expected behavior: Use agent-pr-creator to gather context from commits and diffs, analyze the change type (feat/fix/refactor), detect breaking changes, and create a comprehensive PR with proper title and body following conventions.


User: "Make a PR to main"

Expected behavior: Use agent-pr-creator to detect the base branch, analyze all changes since branching, fill the template following project conventions, and create the PR.

Non-Trigger

User: "Review this pull request: https://github.com/org/repo/pull/123"

Expected behavior: Do not use agent-pr-creator. The user wants to review an existing PR, not create one. Use gh pr view or a review skill instead.


User: "What changes are in my branch?"

Expected behavior: Do not use agent-pr-creator. The user wants to see changes, not create a PR. Use git diff or git log directly.

Troubleshooting

Skill Does Not Trigger

PR Template Not Found

PR Already Exists for This Branch

Uncommitted Changes or Branch Behind Remote

Missing Remote Tracking Branch

gh CLI Authentication Failed

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.