Skip to main content

GitHub Format Pull Request Title Action

Overview

The actions/github/formatPullRequestTitle action automatically formats pull request titles based on branch naming conventions. It can enhance titles with proper capitalization, spacing, and custom formatting rules, making PR titles more readable and consistent across the project.

Language/Tool Support

  • GitHub: Pull request management and API integration
  • Branch Naming: Automatic parsing of branch name conventions
  • Custom Formatting: User-defined formatting rules support

Features

  • Automatic Title Formatting: Converts branch names to readable PR titles
  • Custom Formatting Rules: Support for project-specific formatting preferences
  • Intelligent Parsing: Smart handling of common branch naming patterns
  • Caching: Optimized caching for build artifacts and dependencies

Usage

- name: Format Pull Request Title
uses: ./actions/github/formatPullRequestTitle
with:
repository: ${{ github.repository }}
pullRequestNumber: ${{ github.event.number }}
branch: ${{ github.head_ref }}
token: ${{ secrets.GITHUB_TOKEN }}
customFormatting: "api:API,ui:User Interface,db:Database"

Inputs

InputTypeRequiredDefaultDescription
repositorystring-GitHub repository in format "owner/repo"
pullRequestNumberstring-Pull request number to update
branchstring-Branch name to parse for title formatting
tokenstring-GitHub token with pull request write permissions
customFormattingstring""Custom word formatting rules (comma-separated pairs)

Branch Name Patterns

The action recognizes common branch naming conventions:

Supported Patterns

  • Feature branches: feature/user-authentication → "Feature: User Authentication"
  • Bug fixes: fix/login-issue → "Fix: Login Issue"
  • Hotfixes: hotfix/security-patch → "Hotfix: Security Patch"
  • Improvements: improvement/api-performance → "Improvement: API Performance"
  • Chores: chore/update-dependencies → "Chore: Update Dependencies"

Custom Patterns

Define custom formatting with the customFormatting input:

customFormatting: "feat:Feature,fix:Bug Fix,docs:Documentation,test:Testing"

Usage Examples

Basic PR Title Formatting

name: Format PR Title
on:
pull_request:
types: [opened, synchronize]

jobs:
format-title:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Format Pull Request Title
uses: ./actions/github/formatPullRequestTitle
with:
repository: ${{ github.repository }}
pullRequestNumber: ${{ github.event.number }}
branch: ${{ github.head_ref }}
token: ${{ secrets.GITHUB_TOKEN }}

Custom Formatting Rules

name: Custom PR Formatting
on:
pull_request:
types: [opened, synchronize]

jobs:
format-title:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Format with Custom Rules
uses: ./actions/github/formatPullRequestTitle
with:
repository: ${{ github.repository }}
pullRequestNumber: ${{ github.event.number }}
branch: ${{ github.head_ref }}
token: ${{ secrets.GITHUB_TOKEN }}
customFormatting: "api:API Integration,ui:User Interface,auth:Authentication,db:Database Operations"

Multi-Team Configuration

name: Team-Specific Formatting
on:
pull_request:
types: [opened]

jobs:
format-frontend:
if: startsWith(github.head_ref, 'frontend/')
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Format Frontend PR
uses: ./actions/github/formatPullRequestTitle
with:
repository: ${{ github.repository }}
pullRequestNumber: ${{ github.event.number }}
branch: ${{ github.head_ref }}
token: ${{ secrets.GITHUB_TOKEN }}
customFormatting: "ui:User Interface,ux:User Experience,css:Styling"

format-backend:
if: startsWith(github.head_ref, 'backend/')
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Format Backend PR
uses: ./actions/github/formatPullRequestTitle
with:
repository: ${{ github.repository }}
pullRequestNumber: ${{ github.event.number }}
branch: ${{ github.head_ref }}
token: ${{ secrets.GITHUB_TOKEN }}
customFormatting: "api:API Development,db:Database,auth:Authentication"
useGo: true

Formatting Examples

Branch to Title Conversion

Branch NameFormatted Title
feature/user-loginFeature: User Login
fix/broken-apiFix: Broken API
hotfix/security-vulnerabilityHotfix: Security Vulnerability
chore/update-depsChore: Update Deps
improvement/load-timeImprovement: Load Time
docs/api-documentationDocs: API Documentation

With Custom Formatting

customFormatting: "api:API,ui:User Interface,db:Database"
Branch NameFormatted Title
feature/api-integrationFeature: API Integration
fix/ui-layoutFix: User Interface Layout
improvement/db-performanceImprovement: Database Performance

Integration Patterns

Automated PR Workflow

name: PR Automation
on:
pull_request:
types: [opened, synchronize]

jobs:
format-and-validate:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Format PR Title
uses: ./actions/github/formatPullRequestTitle
with:
repository: ${{ github.repository }}
pullRequestNumber: ${{ github.event.number }}
branch: ${{ github.head_ref }}
token: ${{ secrets.GITHUB_TOKEN }}

- name: Validate PR
run: echo "Running additional validation..."

Branch Protection Integration

name: PR Quality Gate
on:
pull_request:
types: [opened, synchronize]

jobs:
format-title:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Format Title
uses: ./actions/github/formatPullRequestTitle
with:
repository: ${{ github.repository }}
pullRequestNumber: ${{ github.event.number }}
branch: ${{ github.head_ref }}
token: ${{ secrets.GITHUB_TOKEN }}

required-checks:
needs: format-title
runs-on: ubuntu-latest
steps:
- name: Run Tests
run: echo "Running required tests..."

Required Permissions

The GitHub token must have the following permissions:

permissions:
pull-requests: write # Required for updating PR titles
contents: read # Required for accessing repository

Custom Formatting Rules

Define custom formatting with key-value pairs:

Format

"key1:value1,key2:value2,key3:value3"

Examples

# Technical abbreviations
customFormatting: "api:API,ui:UI,db:Database,auth:Authentication"

# Business domains
customFormatting: "crm:Customer Relations,hr:Human Resources,fin:Finance"

# Team prefixes
customFormatting: "fe:Frontend,be:Backend,qa:Quality Assurance,ops:Operations"

Troubleshooting

Common Issues

Title Not Updated

  • Verify token has pull-requests: write permission
  • Check pull request number is correct
  • Ensure repository is accessible

Formatting Not Applied

  • Verify branch name follows expected patterns
  • Check custom formatting syntax
  • Test with simplified formatting rules

Error Resolution

Permission Denied

# Ensure proper permissions
permissions:
pull-requests: write
contents: read

Branch Naming Conventions

Establish consistent branch naming:

# Recommended patterns
feature/description # New features
fix/description # Bug fixes
hotfix/description # Critical fixes
chore/description # Maintenance tasks
docs/description # Documentation
test/description # Testing improvements

Best Practices

Branch Naming

  1. Consistent Prefixes: Use standard prefixes (feature, fix, hotfix)
  2. Descriptive Names: Use clear, descriptive branch names
  3. Hyphen Separation: Use hyphens instead of underscores
  4. Lowercase: Use lowercase for consistency

Custom Formatting

  1. Team Standards: Align formatting rules with team conventions
  2. Abbreviation Consistency: Use consistent abbreviations
  3. Documentation: Document custom formatting rules
  4. Regular Review: Review and update formatting rules periodically

Workflow Integration

  1. Early Execution: Run formatting early in PR workflow
  2. Conditional Logic: Use conditions for team-specific formatting