From 4160c31377017115b52ea9bfa499d80722f4d400 Mon Sep 17 00:00:00 2001 From: Arash Date: Tue, 17 Sep 2024 17:36:47 +0200 Subject: [PATCH 1/7] Add workflow to update PR title based on target branch version --- .github/workflows/pr-title-update.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/pr-title-update.yml diff --git a/.github/workflows/pr-title-update.yml b/.github/workflows/pr-title-update.yml new file mode 100644 index 000000000000..72ba2a6c90eb --- /dev/null +++ b/.github/workflows/pr-title-update.yml @@ -0,0 +1,25 @@ +name: Update PR Title If Target Branch Is A Version Branch + +on: + pull_request: + types: [opened] + +jobs: + update-title: + runs-on: ubuntu-latest + 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) + + if [[ "$TARGET_BRANCH" != "dev" ]]; then + 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 + fi From 17a124ef43ee6ec71842ec7662f04dd0fca2cd48 Mon Sep 17 00:00:00 2001 From: Arash Kadkhodaei Date: Tue, 17 Sep 2024 18:02:42 +0200 Subject: [PATCH 2/7] Use pull_request_target instead of pull_request Co-authored-by: Nicola Soranzo --- .github/workflows/pr-title-update.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-title-update.yml b/.github/workflows/pr-title-update.yml index 72ba2a6c90eb..35b7ef4fa8ad 100644 --- a/.github/workflows/pr-title-update.yml +++ b/.github/workflows/pr-title-update.yml @@ -1,7 +1,7 @@ name: Update PR Title If Target Branch Is A Version Branch on: - pull_request: + pull_request_target: types: [opened] jobs: From e5acd13f024fdbae27fd81b88f580b33e1a8a969 Mon Sep 17 00:00:00 2001 From: Arash Date: Tue, 17 Sep 2024 18:21:40 +0200 Subject: [PATCH 3/7] use branches instead of if in the job, add permissions --- .github/workflows/pr-title-update.yml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pr-title-update.yml b/.github/workflows/pr-title-update.yml index 35b7ef4fa8ad..30d99a1760ad 100644 --- a/.github/workflows/pr-title-update.yml +++ b/.github/workflows/pr-title-update.yml @@ -3,10 +3,14 @@ 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: @@ -15,11 +19,8 @@ jobs: 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) - - if [[ "$TARGET_BRANCH" != "dev" ]]; then - 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 + 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 From d3c9e0354cdf9ad88b5c3b4afa996135cfc791f7 Mon Sep 17 00:00:00 2001 From: Arash Kadkhodaei Date: Tue, 17 Sep 2024 18:29:52 +0200 Subject: [PATCH 4/7] Trigger workflow on edited PR --- .github/workflows/pr-title-update.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-title-update.yml b/.github/workflows/pr-title-update.yml index 30d99a1760ad..cc577d95bb16 100644 --- a/.github/workflows/pr-title-update.yml +++ b/.github/workflows/pr-title-update.yml @@ -2,7 +2,7 @@ name: Update PR Title If Target Branch Is A Version Branch on: pull_request_target: - types: [opened] + types: [opened, edited] branches: - 'release_**' From b5d143281834d91d4ca64ac15d87584a36195c7a Mon Sep 17 00:00:00 2001 From: Arash Date: Thu, 10 Oct 2024 18:43:39 +0200 Subject: [PATCH 5/7] checkout first as it need to run git commands --- .github/workflows/pr-title-update.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr-title-update.yml b/.github/workflows/pr-title-update.yml index cc577d95bb16..2a54a9c736d3 100644 --- a/.github/workflows/pr-title-update.yml +++ b/.github/workflows/pr-title-update.yml @@ -4,7 +4,7 @@ on: pull_request_target: types: [opened, edited] branches: - - 'release_**' + - "release_**" jobs: update-title: @@ -12,6 +12,7 @@ jobs: permissions: pull-requests: write steps: + - uses: actions/checkout@v4 - name: Update PR title env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From f4ffa9d74b364fe3ec019ce43e9a3e7fed140388 Mon Sep 17 00:00:00 2001 From: Arash Kadkhodaei Date: Fri, 11 Oct 2024 13:50:20 +0200 Subject: [PATCH 6/7] More generic and shorter title Co-authored-by: Nicola Soranzo --- .github/workflows/pr-title-update.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-title-update.yml b/.github/workflows/pr-title-update.yml index 2a54a9c736d3..a4f6e32ebf47 100644 --- a/.github/workflows/pr-title-update.yml +++ b/.github/workflows/pr-title-update.yml @@ -1,4 +1,4 @@ -name: Update PR Title If Target Branch Is A Version Branch +name: Update PR title on: pull_request_target: From 9433ecef185e2e4c745bf26dbce1b592da36b0f2 Mon Sep 17 00:00:00 2001 From: Arash Date: Mon, 14 Oct 2024 10:51:10 +0200 Subject: [PATCH 7/7] Using github action contexts instead of gh CLI Co-authored-by: Nicola Soranzo --- .github/workflows/pr-title-update.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-title-update.yml b/.github/workflows/pr-title-update.yml index a4f6e32ebf47..482794257069 100644 --- a/.github/workflows/pr-title-update.yml +++ b/.github/workflows/pr-title-update.yml @@ -18,8 +18,8 @@ jobs: 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) + TARGET_BRANCH="${{ github.base_ref }}" + PR_TITLE="${{ github.event.pull_request.title }}" VERSION=$(echo $TARGET_BRANCH | grep -oP '\d+\.\d+') if [[ -n "$VERSION" && ! "$PR_TITLE" =~ ^\[$VERSION\] ]]; then NEW_TITLE="[$VERSION] $PR_TITLE"