From f3e65fa1b95bca02981283f2259d085fa738138a Mon Sep 17 00:00:00 2001 From: Arash Date: Mon, 25 Nov 2024 11:39:58 +0100 Subject: [PATCH 1/2] Refactor PR title update workflow to handle version extraction and title formatting more efficiently --- .github/workflows/pr-title-update.yml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pr-title-update.yml b/.github/workflows/pr-title-update.yml index ee47e16d84e1..6ed945cae0f7 100644 --- a/.github/workflows/pr-title-update.yml +++ b/.github/workflows/pr-title-update.yml @@ -3,8 +3,6 @@ name: Update PR title on: pull_request_target: types: [opened, edited, reopened] - branches: - - "release_**" jobs: update-title: @@ -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 From afdfa789f171963cdcb0509a442a7196be70861c Mon Sep 17 00:00:00 2001 From: Arash Date: Tue, 26 Nov 2024 12:20:19 +0100 Subject: [PATCH 2/2] Refactor version extraction in PR title update workflow for improved accuracy Co-authored-by: Nicola Soranzo --- .github/workflows/pr-title-update.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pr-title-update.yml b/.github/workflows/pr-title-update.yml index 6ed945cae0f7..8ffd54a45da4 100644 --- a/.github/workflows/pr-title-update.yml +++ b/.github/workflows/pr-title-update.yml @@ -19,11 +19,10 @@ jobs: PR_TITLE: "${{ github.event.pull_request.title }}" REPO: "${{ github.repository }}" run: | - VERSION=$(echo $TARGET_BRANCH | grep -oP 'release_\K.*' || true) + VERSION=$(echo $TARGET_BRANCH | grep -oP '^release_\K\d+.\d+$' || true) + NEW_TITLE=$(echo "$PR_TITLE" | sed -E "s/\[[0-9]+\.[0-9]+\] //") if [[ -n "$VERSION" ]]; then - NEW_TITLE="[$VERSION] ${PR_TITLE#*\] }" - else - NEW_TITLE="${PR_TITLE#*\] }" + NEW_TITLE="[$VERSION] $NEW_TITLE" fi if [[ "$NEW_TITLE" != "$PR_TITLE" ]]; then gh pr edit $PR_NUMBER --repo "$REPO" --title "$NEW_TITLE"