use branches instead of if in the job, add permissions

This commit is contained in:
Arash
2024-09-17 18:21:40 +02:00
parent 17a124ef43
commit e5acd13f02
+8 -7
View File
@@ -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