Skip to content

Commit

Permalink
Refactor PR title update workflow to handle version extraction and ti…
Browse files Browse the repository at this point in the history
…tle formatting more efficiently
  • Loading branch information
arash77 committed Nov 25, 2024
1 parent d59f7a6 commit f3e65fa
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/pr-title-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ name: Update PR title
on:
pull_request_target:
types: [opened, edited, reopened]
branches:
- "release_**"

jobs:
update-title:
Expand All @@ -19,9 +17,14 @@ jobs:
PR_NUMBER: ${{ github.event.pull_request.number }}
TARGET_BRANCH: "${{ github.base_ref }}"
PR_TITLE: "${{ github.event.pull_request.title }}"
REPO: "${{ github.repository }}"
run: |
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 --repo "${{ github.repository }}" --title "$NEW_TITLE"
VERSION=$(echo $TARGET_BRANCH | grep -oP 'release_\K.*' || true)
if [[ -n "$VERSION" ]]; then
NEW_TITLE="[$VERSION] ${PR_TITLE#*\] }"
else
NEW_TITLE="${PR_TITLE#*\] }"
fi
if [[ "$NEW_TITLE" != "$PR_TITLE" ]]; then
gh pr edit $PR_NUMBER --repo "$REPO" --title "$NEW_TITLE"
fi

0 comments on commit f3e65fa

Please sign in to comment.