Skip to content
Development
Command

/pr-auto-update

A command that automatically updates Pull Request descriptions and labels. Analyzes Git changes to generate and set appropriate descriptions and labels.

From plugin
claude-code-cookbook
1.1k39 skills9 agents39 commands8 MCP
Install
> /plugin marketplace add wasabeef/claude-code-cookbook

How it fires

How this command gets triggered: by you, by Claude, or both.

  • Fires itselfClaude auto-loads it when your prompt matches the work.
  • You can call itInvoke it directly when you want it.
  • Slash command/pr-auto-update

Context preview

What this command does when you run it.

A command that automatically updates Pull Request descriptions and labels. Analyzes Git changes to generate and set appropriate descriptions and labels.

Command definition

pr-auto-update.md

Auto-update PR description and labels from changes

Overview

A command that automatically updates Pull Request descriptions and labels. Analyzes Git changes to generate and set appropriate descriptions and labels.

Usage

/pr-auto-update [options] [PR number]

Options

  • `--pr <number>`: Specify target PR number (automatically detected from current branch if omitted)
  • `--description-only`: Update only the description (keep labels unchanged)
  • `--labels-only`: Update only labels (keep description unchanged)
  • `--dry-run`: Show generated content without making actual updates
  • `--lang <language>`: Specify language (en)

Basic Examples

# Auto-update PR for current branch
/pr-auto-update

# Update specific PR
/pr-auto-update --pr 1234

# Update description only
/pr-auto-update --description-only

# Check with dry-run
/pr-auto-update --dry-run

Feature Details

1. PR Auto Detection

Automatically detects the corresponding PR from the current branch:

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

2. Change Analysis

Collects and analyzes the following information:

  • **File changes**: Added, deleted, or modified files
  • **Code analysis**: Changes to imports, function definitions, class definitions
  • **Tests**: Presence and content of test files
  • **Documentation**: Updates to README, docs
  • **Configuration**: Changes to package.json, pubspec.yaml, configuration files
  • **CI/CD**: Changes to GitHub Actions, workflows

3. Automatic Description Generation

Template Processing Priority

1. **Existing PR description**: Completely follows already written content 2. **Project template**: Gets structure from `.github/PULL_REQUEST_TEMPLATE.md` 3. **Default template**: Fallback when above don't exist

Rules for Preserving Existing Content

**Important**: Do not modify existing content

  • Keep existing sections
  • Only complete empty sections
  • Keep functional comments (like Copilot review rules)

Using Project Templates

# Parse structure of .github/PULL_REQUEST_TEMPLATE.md
parse_template_structure() {
  local template_file="$1"

  if [ -f "$template_file" ]; then
    # Extract section structure
    grep -E '^##|^###' "$template_file"

    # Identify comment placeholders
    grep -E '<!--.*-->' "$template_file"

    # Completely follow existing template structure
    cat "$template_file"
  fi
}

4. Automatic Label Setting

Label Retrieval Mechanism

**Priority**:

1. **`.github/labels.yml`**: Get from project-specific label definitions 2. **GitHub API**: Get existing labels with `gh api repos/{OWNER}/{REPO}/labels --jq '.[].name'`

Automatic Determination Rules

**File Pattern Based**:

  • Documentation: `*.md`, `README`, `docs/` → labels containing `documentation|docs|doc`
  • Tests: `test`, `spec` → labels containing `test|testing`
  • CI/CD: `.github/`, `*.yml`, `Dockerfile` → labels containing `ci|build|infra|ops`
  • Dependencies: `package.json`, `pubspec.yaml`, `requirements.txt` → labels containing `dependencies|deps`

**Change Content Based**:

  • Bug fixes: `fix|bug|error|crash|correction` → labels containing `bug|fix`
  • New features: `feat|feature|add|implement|new-feature|implementation` → labels containing `feature|enhancement|feat`
  • Refactoring: `refactor|clean|restructure` → labels containing `refactor|cleanup|clean`
  • Performance: `performance|perf|optimize|optimization` → labels containing `performance|perf`
  • Security: `security|secure|vulnerability` → labels containing `security`

Constraints

  • **Maximum 3**: Upper limit on automatically selected labels
  • **Existing labels only**: Creating new labels is prohibited
  • **Partial match**: Determined by whether keywords are contained in label names

Actual Usage Examples

**When `.github/labels.yml` exists**:

# Auto-retrieve from label definitions
grep "^- name:" .github/labels.yml | sed "s/^- name: '\?\([^']*\)'\?/\1/"

# Example: Use project-specific label system

**When retrieving from GitHub API**:

# Get list of existing labels
gh api repos/{OWNER}/{REPO}/labels --jq '.[].name'

# Example: Use standard labels like bug, enhancement, documentation

5. Execution Flow

#!/bin/bash

# 1. PR Detection & Retrieval
detect_pr() {
  if [ -n "$PR_NUMBER" ]; then
    echo $PR_NUMBER
  else
    gh pr list --head $(git branch --show-current) --json number --jq '.[0].number'
  fi
}

# 2. Change Analysis
analyze_changes() {
  local pr_number=$1

  # Get file changes
  gh pr diff $pr_number --name-only

  # Content analysis
  gh pr diff $pr_number | head -1000
}

# 3. Description Generation
generate_description() {
  local pr_number=$1
  local changes=$2

  # Get current PR description
  local current_body=$(gh pr view $pr_number --json body --jq -r .body)

  # Use existing content if available
  if [ -n "$current_body" ]; then
    echo "$current_body"
  else
    # Generate new from template
    local template_file=".github/PULL_REQUEST_TEMPLATE.md"
    if [ -f "$template_file" ]; then
      generate_from_template "$(cat "$template_file")" "$changes"
    else
      generate_from_template "" "$changes"
    fi
  fi
}

# Generate from template
generate_from_template() {
  local template="$1"
  local changes="$2"

  if [ -n "$template" ]; then
    # Use template as-is (preserve HTML comments)
    echo "$template"
  else
    # Generate in default format
    echo "## What does this change?"
    echo ""
    echo "$changes"
  fi
}

# 4. Label Determination
determine_labels() {
  local changes=$1
  local file_list=$2
  local pr_number=$3

  # Get available labels
  local available_labels=()
  if [ -f ".github/labels.yml" ]; then
    # Extract label names from labels.yml
    available_labels=($(grep "^- name:" .github/labels.yml | sed "s/^- name: '\?\([^']*\)'\?/\1/"))
  else
    # Get labels from GitHub API
    local repo_info=$(gh repo view --json owner,name)
    local owner=$
Read more
Ships withclaude-code-cookbook

A collection of commands, roles, and automation scripts for Claude Code. Automate your workflow without unnecessary confirmations, allowing you to focus on what matters.

Get the whole plugin

Other commands on claude-code-cookbook.