DEV Community

Alex
Alex

Posted on

Never Write PR Descriptions Again — Let AI Do It

Nobody likes writing PR descriptions. You know what's in the diff. The reviewer can read the code. So you write "fixed stuff" and move on.

But good PR descriptions matter. They help reviewers understand intent, they document decisions, and they make your git history searchable. The solution: make the machine write them.

The Git Hook Approach

We'll create a script that reads your commits and diff, sends them to an AI, and outputs a formatted PR description you can paste.

Create scripts/generate-pr-desc.sh:

#!/bin/bash

BASE_BRANCH=${1:-main}

# Get commit messages since branching
COMMITS=$(git log $BASE_BRANCH..HEAD --oneline)

# Get the diff summary
DIFF_STAT=$(git diff $BASE_BRANCH..HEAD --stat)

# Get the actual diff (truncated for large PRs)
DIFF=$(git diff $BASE_BRANCH..HEAD | head -c 8000)

# Generate description with AI
RESPONSE=$(curl -s https://api.anthropic.com/v1/messages \
  -H "content-type: application/json" \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -d "{
    \"model\": \"claude-sonnet-4-20250514\",
    \"max_tokens\": 512,
    \"messages\": [{
      \"role\": \"user\",
      \"content\": \"Generate a concise PR description in markdown. Include: Summary (2-3 sentences), Changes (bullet list), Testing notes. Based on:\\n\\nCommits:\\n$COMMITS\\n\\nFiles changed:\\n$DIFF_STAT\\n\\nDiff:\\n$DIFF\"
    }]
  }")

echo "$RESPONSE" | jq -r '.content[0].text'
Enter fullscreen mode Exit fullscreen mode

Make it executable:

chmod +x scripts/generate-pr-desc.sh
Enter fullscreen mode Exit fullscreen mode

Using It

# Generate description against main branch
./scripts/generate-pr-desc.sh main

# Or against a different base
./scripts/generate-pr-desc.sh develop
Enter fullscreen mode Exit fullscreen mode

Output looks like this:

## Summary
Adds user authentication with JWT tokens and password hashing.
Includes login, register, and token refresh endpoints.

## Changes
- Added `/auth/login` and `/auth/register` routes
- Implemented JWT token generation with 24h expiry
- Added bcrypt password hashing in user model
- Created auth middleware for protected routes
- Added rate limiting on auth endpoints (5 req/min)

## Testing
- Unit tests for token generation and validation
- Integration tests for login/register flow
- Manual testing needed for rate limiting edge cases
Enter fullscreen mode Exit fullscreen mode

Automating with GitHub CLI

Take it further. Create a PR with the generated description in one command:

#!/bin/bash
# scripts/create-pr.sh

BASE_BRANCH=${1:-main}
TITLE=$(git log -1 --pretty=%s)
BODY=$(./scripts/generate-pr-desc.sh $BASE_BRANCH)

gh pr create \
  --title "$TITLE" \
  --body "$BODY" \
  --base "$BASE_BRANCH"
Enter fullscreen mode Exit fullscreen mode

Now ./scripts/create-pr.sh creates a PR with a perfect description every time.

Adding Structure to PR Descriptions

For teams that need structured PR metadata (ticket numbers, breaking changes, deployment notes), you can extract that information from your commits and diff using structured data extraction.

Here's how to get structured PR metadata using StructureAI:

curl -X POST https://api-service-wine.vercel.app/api/extract \
  -H "Content-Type: application/json" \
  -H "X-API-Key: YOUR_KEY" \
  -d "{
    \"text\": \"$(git log main..HEAD --oneline)\",
    \"schema\": \"custom\",
    \"custom_fields\": [
      \"ticket_numbers\",
      \"breaking_changes\",
      \"new_dependencies\",
      \"requires_migration\"
    ]
  }"
Enter fullscreen mode Exit fullscreen mode

This returns clean JSON:

{
  "ticket_numbers": ["PROJ-123", "PROJ-456"],
  "breaking_changes": false,
  "new_dependencies": ["bcrypt", "jsonwebtoken"],
  "requires_migration": true
}
Enter fullscreen mode Exit fullscreen mode

Pipe that into your PR template for perfectly structured descriptions every time.

VS Code Integration

Add a task to .vscode/tasks.json so you can generate descriptions without leaving your editor:

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Generate PR Description",
      "type": "shell",
      "command": "./scripts/generate-pr-desc.sh",
      "args": ["main"],
      "presentation": {
        "reveal": "always",
        "panel": "new"
      }
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

Hit Cmd+Shift+P > "Run Task" > "Generate PR Description" and copy the output.

Team Setup

Want the whole team using this? Add the script to your repo and document it in the contributing guide:

## Creating Pull Requests

Run `./scripts/generate-pr-desc.sh` to auto-generate your PR description.
Set `ANTHROPIC_API_KEY` in your shell profile.
Enter fullscreen mode Exit fullscreen mode

Cost per PR description: approximately $0.003. A team of 10 developers creating 100 PRs/month costs about $0.30 total.

Why This Beats Templates

PR templates are static. They give you headers to fill in but don't write the content. AI-generated descriptions actually analyze your code changes and write relevant descriptions.

The AI catches things you'd forget to mention: new dependencies, config changes, migration requirements, breaking changes. It reads the diff, so it knows what actually changed — not just what you remember changing.

Stop writing PR descriptions. Let the machine do it. Spend your time on code that matters.


Built by Avatrix LLC. Extract structured data from any text with StructureAI.

Top comments (0)