Skip to content

Add workflow to update PR title based on target branch version #18835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 14, 2024
26 changes: 26 additions & 0 deletions .github/workflows/pr-title-update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Update PR Title If Target Branch Is A Version Branch

on:
pull_request_target:
types: [opened]
branches:
- 'release_**'

jobs:
update-title:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Update PR title
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
TARGET_BRANCH=$(gh pr view $PR_NUMBER --json baseRefName -q .baseRefName)
PR_TITLE=$(gh pr view $PR_NUMBER --json title -q .title)
VERSION=$(echo $TARGET_BRANCH | grep -oP '\d+\.\d+')
if [[ -n "$VERSION" && ! "$PR_TITLE" =~ ^\[$VERSION\] ]]; then
NEW_TITLE="[$VERSION] $PR_TITLE"
gh pr edit $PR_NUMBER --title "$NEW_TITLE"
fi
Loading