Update pr title workflow
The Update PR Title is a GitHub workflow that modifies the title of a GitHub Pull Request (PR) to match the branch name. The workflow is triggered whenever a pull request is created (opened), reopened, or new commits are pushed to the PR's branch (synchronize).
I created this workflow to make it easier to correlate GitHub PRs with Jira issue IDs, which were already baked into our branch names using GitFlow Workflow. By default, GitHub pulls the first commit message into the PR title, which usually results in vague or unhelpful names. Manually renaming PRs to match branch names is tedious, so this workflow automates the process. It supports any branch naming convention. Below are some examples of expected behavior:
Git branch name | PR title (before) | PR title (after) |
---|---|---|
feature/proj-210-add-login | first commit to add feature | feature/proj-210-add-login |
bugfix/quick-fix | attempt to fix | bugfix/quick-fix |
cicd-developmenet | update configuration | cicd-developmenet |
Implementation
Copy the workflow definition below into a file named update_pr_title.yml
and drop it under .github/workflows
directory at the root of your repo. Then commit and push to GitHub to start using it.
name: Update PR Title
on:
pull_request:
types: [opened, reopened, synchronize]
jobs:
update_pr_title:
permissions:
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: secureframe/pr-update-action@v3
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
base-branch-regex: '[a-z\d-_.\\/]+'
head-branch-regex: '.*'
title-template: '%headbranch%'
title-update-action: replace
title-uppercase-head-match: false
The workflow won't run if someone renames the PR manually or leaves a comment, only on the trigger events mentioned above. And when it does run, it will replace the PR title, regardless of whether the PR was named manually or not.
This workflow depends on the secureframe/pr-update-action.
grafts: