diff --git a/.github/workflows/backport-pr.yml b/.github/workflows/backport-pr.yml index e5955ea9c..c7bcb117e 100644 --- a/.github/workflows/backport-pr.yml +++ b/.github/workflows/backport-pr.yml @@ -15,7 +15,7 @@ jobs: # everybody to trigger backports and create branches in our repository. if: > github.event.issue.pull_request && - startsWith(github.event.comment.body, '/backport') && + startsWith(github.event.comment.body, '/backport ') && ( github.event.comment.author_association == 'OWNER' || github.event.comment.author_association == 'COLLABORATOR' || @@ -28,23 +28,19 @@ jobs: run: | set -euo pipefail body="${{ github.event.comment.body }}" - labels_json='${{ toJSON(github.event.pull_request.labels || github.event.issue.labels) }}' - target=$(echo "$body" | sed -n 's/.*\/backport[[:space:]]\+\([^[:space:]]\+\).*/\1/p') - - if [ -z "$target" ]; then - echo "No backport target found in comment." >&2 + + line=${body%%$'\n'*} # Get the first line + if [[ $line =~ ^/backport[[:space:]]+([^[:space:]]+) ]]; then + echo "BACKPORT_TARGET=${BASH_REMATCH[1]}" >> "$GITHUB_ENV" + else + echo "Usage: /backport " >&2 exit 1 fi - echo "BACKPORT_TARGET=$target" >> $GITHUB_ENV - labels=$(echo "$labels_json" | jq -r 'if . == null then "" else map(.name) | join(",") end') - if [ -z "$labels" ]; then - echo "BACKPORT_PR_LABELS=backport" >> $GITHUB_ENV - else - echo "BACKPORT_PR_LABELS=backport,$labels" >> $GITHUB_ENV - fi - name: Create backport pull request uses: korthout/backport-action@v4 with: - add_labels: ${{ env.BACKPORT_PR_LABELS }} + add_labels: 'backport' + copy_labels_pattern: '.*' + label_pattern: '' target_branches: ${{ env.BACKPORT_TARGET }} \ No newline at end of file