home / skills / dhughes / claude-marketplace / pr-creation

This skill creates draft pull requests by automatically detecting related tickets, applying templates, and including ticket references for easy review.

npx playbooks add skill dhughes/claude-marketplace --skill pr-creation

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
9.5 KB
---
name: pr-creation
description: This skill should be used when you need to create, open, or edit a pull request (PR), or the user asks to "create a PR", "open a PR", "submit a PR", "raise a PR", "file a PR", "make a PR", "create a pull request", "open a pull request", "new PR", or any variation requesting GitHub pull request creation.
allowed-tools: Read, Bash, Grep, Glob, AskUserQuestion
---

# Pull Request Creation Best Practices

## Purpose

This skill enforces three critical best practices when creating GitHub pull requests:

1. **Include ticket numbers** - Associates PRs with tracking tickets (Jira, GitHub Issues)
2. **Use PR templates when available** - Ensures consistent, complete PR descriptions
3. **Create PRs as drafts by default** - Allows review before marking ready for review

## Ticket Detection and Integration

Before creating the pull request, attempt to identify an associated ticket number from Jira or GitHub Issues.

### Detection Sources

Check the following sources for ticket numbers (in order of preference):

1. **Conversation context** - Ticket mentioned in recent messages or conversation history
2. **Branch name** - Parse current branch name for ticket patterns:
   - `PROJ-123/description` (Jira-style prefix)
   - `feature/PROJ-123-description` (Jira after prefix)
   - `123-description` (GitHub issue number)
   - Other common patterns using intuition
3. **Recent commit messages** - Check for ticket references in commit messages
4. **Ask user** - If no ticket found in above sources, use AskUserQuestion to ask if there's an associated ticket

### Ticket Number Patterns

Recognize these common patterns:
- **Jira tickets**: `PROJ-123`, `ABC-456` (uppercase letters, hyphen, numbers)
- **GitHub issues**: `#123`, `456` (numbers, optionally with # prefix)

### PR Title Integration

When ticket number is identified, format the PR title as:

```
[TICKET-NUM] Descriptive PR title
```

Examples:
- `[MSI-608] Add Zendesk integration`
- `[#456] Fix authentication bug`
- `[PLATFORM-123] Refactor API endpoints`

### PR Body Integration

**If PR template exists with ticket field:**
- Look for placeholders like `[TICKET]`, `[ISSUE]`, `Ticket:`, `Issue:`, `JIRA:`, etc.
- Replace placeholder with ticket number (as link if URL can be determined)
- Preserve template formatting

**If template has no specific ticket field:**
- Add ticket reference at the top of the PR body
- Format as: `**Ticket:** [TICKET-NUM](url)` or `**Ticket:** TICKET-NUM` if no URL

**If no template:**
- Include ticket reference at the start of the PR description
- Format with link if available

### Ticket URL Determination

Determine ticket URLs from available context and knowledge:

1. **Check CLAUDE.md or project configuration** - Look for Jira base URL, GitHub repo URL, or ticket system configuration
2. **Parse git remote** - Extract GitHub repository URL from git config for GitHub issues
3. **Use conversation context** - Apply knowledge from earlier in conversation about project's ticket systems
4. **Infer from project structure** - Look for `.jira`, project config files, or documentation mentioning ticket URLs

**URL formats:**
- Jira: `https://company.atlassian.net/browse/PROJ-123`
- GitHub Issues: `https://github.com/owner/repo/issues/123`

If URL cannot be determined, include ticket number without link.

## PR Template Discovery

Before creating the pull request, check for GitHub PR templates in the `.github/` directory using the following search order:

1. `.github/pull_request_template.md` (lowercase, standard GitHub convention)
2. `.github/PULL_REQUEST_TEMPLATE.md` (uppercase variant)
3. `.github/PULL_REQUEST_TEMPLATE/*.md` (multiple templates in subdirectory)

### Template Usage

If a template is found:
- Read the template file to understand the required sections
- Use the template structure when constructing the PR body with `gh pr create --body`
- Fill in each template section appropriately based on the changes being submitted
- Preserve template formatting, headings, and structure

If multiple templates exist in `.github/PULL_REQUEST_TEMPLATE/`:
- List available templates to the user
- Ask which template to use for this PR
- Proceed with the selected template

If no template is found:
- Proceed with standard PR creation
- Generate a comprehensive PR description including:
  - Summary of changes
  - Test plan or verification steps
  - Any relevant context or decisions

## Draft PR Creation

Always create pull requests as drafts using the `--draft` flag:

```bash
gh pr create --draft --title "PR title" --body "$(cat <<'EOF'
PR description here
EOF
)"
```

### Why Draft by Default

Draft PRs provide several benefits:
- Allows CI/CD checks to run before requesting reviews
- Provides opportunity to review the PR diff on GitHub before soliciting feedback
- Prevents accidental notification spam to reviewers for incomplete work
- Enables incremental commits and refinements before marking ready

### Making PR Ready for Review

After creating the draft PR, inform the user they can mark it ready for review when appropriate:

```bash
gh pr ready <pr-number>
```

Or they can mark it ready directly on GitHub.

## Complete Workflow

Follow this sequence when the user requests PR creation:

1. **Detect ticket number**:
   - Check conversation context for ticket references
   - Parse current branch name for ticket patterns
   - Check recent commit messages
   - If no ticket found, use AskUserQuestion to ask user
   - Determine ticket URL if possible from context, CLAUDE.md, or git config

2. **Check for PR templates**:
   - Search `.github/` directory for template files
   - If found, read template content
   - Identify if template has ticket field/placeholder

3. **Gather PR information**:
   - Analyze recent commits using `git log` and `git diff`
   - Generate appropriate PR title with ticket: `[TICKET] Title`
   - Generate PR description:
     - If template with ticket field: fill in ticket (with link if available)
     - If template without ticket field: add ticket at top of body
     - If no template: include ticket at start of description
   - If using template, structure description according to template format

4. **Create draft PR**:
   - Use `gh pr create --draft` with ticket-formatted title and body
   - Include template content if applicable
   - Ensure body is passed via heredoc for proper formatting

5. **Verify creation**:
   - Confirm PR was created successfully
   - Display PR URL to user
   - Remind user that PR is in draft state

6. **Provide next steps**:
   - Inform user how to mark PR ready when appropriate
   - Note any CI/CD checks that will run

## Example Commands

### PR with ticket from branch name

```bash
# Detect ticket from branch (e.g., MSI-608/zendesk2)
BRANCH=$(git branch --show-current)
# Parse ticket: MSI-608

# Create draft PR with ticket in title
gh pr create --draft --title "[MSI-608] Add Zendesk integration" --body "$(cat <<'EOF'
**Ticket:** [MSI-608](https://company.atlassian.net/browse/MSI-608)

## Summary
Added Zendesk integration for customer support tickets

## Changes
- Implemented Zendesk API client
- Added webhook handlers
EOF
)"
```

### PR with template containing ticket placeholder

```bash
# Template has "Ticket: [TICKET]" placeholder
# Replace with actual ticket and link

gh pr create --draft --title "[PLATFORM-123] Refactor API endpoints" --body "$(cat <<'EOF'
## Ticket
[PLATFORM-123](https://jira.company.com/browse/PLATFORM-123)

## Summary
[Filled from template]

## Test Plan
[Filled from template]
EOF
)"
```

### PR with GitHub issue number

```bash
# Detect from branch: 456-fix-auth-bug

gh pr create --draft --title "[#456] Fix authentication bug" --body "$(cat <<'EOF'
**Related Issue:** [#456](https://github.com/owner/repo/issues/456)

## Summary
Fixed authentication token expiration handling
EOF
)"
```

## Important Notes

- **Detect ticket numbers** - Always attempt to find associated ticket from context, branch, or commits before asking user
- **Always use `--draft` flag** - Never create PRs as immediately ready for review
- **Include ticket in title** - Format as `[TICKET] Title` when ticket is identified
- **Link tickets when possible** - Use context knowledge to determine ticket URLs
- **Respect template structure** - When templates exist, follow their format exactly
- **Use heredoc for body** - Ensures proper multiline formatting and prevents shell escaping issues
- **Verify template locations** - Check all three standard locations before proceeding
- **Inform the user** - Always communicate that the PR was created as a draft and how to mark it ready

## Edge Cases

**No ticket found and user declines to provide**: If user indicates there's no associated ticket or chooses not to provide one, proceed with PR creation without ticket in title or body

**Multiple ticket references**: If multiple tickets are found, ask user which is the primary ticket for this PR

**Invalid ticket format**: If detected ticket doesn't match expected patterns, verify with user before using

**Cannot determine ticket URL**: If ticket is identified but URL cannot be determined from context, include ticket number without link

**No git repository**: Verify current directory is a git repository before proceeding

**Not a GitHub repository**: Confirm remote is GitHub before using `gh` commands

**No GitHub CLI**: If `gh` command is not available, inform user to install GitHub CLI

**Branch already has PR**: If a PR already exists for the current branch, inform user rather than creating duplicate

**No commits to push**: Ensure there are commits to include in the PR before creating it

Overview

This skill helps you create, open, or edit GitHub pull requests following team best practices. It detects associated ticket numbers, applies PR templates when present, and creates PRs as drafts by default to avoid premature review notifications. The goal is consistent, traceable PRs with clear titles and formatted descriptions.

How this skill works

The skill inspects conversation context, current branch name, and recent commit messages to detect ticket identifiers (Jira or GitHub issues). It searches the repository for PR templates in .github/, fills template fields (including ticket placeholders), constructs a ticket-prefixed title and a well-structured body, and runs gh pr create --draft with a heredoc body. It verifies creation, returns the PR URL, and reminds the user how to mark the PR ready for review.

When to use it

  • When the user asks to create, open, submit, raise, file, or make a PR
  • When you want the PR to include a ticket reference automatically
  • When a repository contains a PR template that should be respected
  • When you prefer creating a draft PR to run CI before requesting reviews
  • When preparing a PR from a branch or recent commits and need a standardized description

Best practices

  • Always attempt to detect a ticket from conversation, branch name, or commits before asking the user
  • Search .github/ for pull request templates and preserve template structure when filling fields
  • Format titles as [TICKET] Descriptive title when a ticket is found
  • Create PRs as drafts using --draft to prevent premature reviewer notifications
  • Include ticket links when a ticket URL can be determined; otherwise include the ticket number

Example use cases

  • Create a draft PR from branch MSI-608/zendesk2, include [MSI-608] in the title and fill the template’s ticket field
  • Open a PR when branch name contains an issue number like 456-fix-auth-bug and link to the GitHub issue
  • Generate a PR body from recent commits when no template exists, adding summary, changes, and test plan
  • Ask which template to use if multiple templates exist in .github/PULL_REQUEST_TEMPLATE/
  • Prompt the user to select the primary ticket when multiple ticket references are detected

FAQ

What if no ticket is found?

I will ask whether a ticket should be associated; if the user declines, I will proceed without a ticket in title or body.

What if the repository has no PR template?

I will generate a comprehensive PR description with summary, changes, and test plan and include the ticket (if any) at the top.

Will the PR be ready for review immediately?

No. The skill creates draft PRs by default. You can mark a draft ready with gh pr ready <pr-number> or using the GitHub web UI.