Skip to content

Commit 05a2e51

Browse files
Apply suggestions from code review
Use proper arguments to apply labels from original PR to backport PR. Improve target branch detection. Co-authored-by: AbsurdlyLongUsername <22662897+absurdlylongusername@users.noreply.github.com>
1 parent 247f32e commit 05a2e51

1 file changed

Lines changed: 10 additions & 14 deletions

File tree

.github/workflows/backport-pr.yml

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
# everybody to trigger backports and create branches in our repository.
1616
if: >
1717
github.event.issue.pull_request &&
18-
startsWith(github.event.comment.body, '/backport') &&
18+
startsWith(github.event.comment.body, '/backport ') &&
1919
(
2020
github.event.comment.author_association == 'OWNER' ||
2121
github.event.comment.author_association == 'COLLABORATOR' ||
@@ -28,23 +28,19 @@ jobs:
2828
run: |
2929
set -euo pipefail
3030
body="${{ github.event.comment.body }}"
31-
labels_json='${{ toJSON(github.event.pull_request.labels || github.event.issue.labels) }}'
32-
target=$(echo "$body" | sed -n 's/.*\/backport[[:space:]]\+\([^[:space:]]\+\).*/\1/p')
33-
34-
if [ -z "$target" ]; then
35-
echo "No backport target found in comment." >&2
31+
32+
line=${body%%$'\n'*} # Get the first line
33+
if [[ $line =~ ^/backport[[:space:]]+([^[:space:]]+) ]]; then
34+
echo "BACKPORT_TARGET=${BASH_REMATCH[1]}" >> "$GITHUB_ENV"
35+
else
36+
echo "Usage: /backport <target-branch>" >&2
3637
exit 1
3738
fi
38-
echo "BACKPORT_TARGET=$target" >> $GITHUB_ENV
3939
40-
labels=$(echo "$labels_json" | jq -r 'if . == null then "" else map(.name) | join(",") end')
41-
if [ -z "$labels" ]; then
42-
echo "BACKPORT_PR_LABELS=backport" >> $GITHUB_ENV
43-
else
44-
echo "BACKPORT_PR_LABELS=backport,$labels" >> $GITHUB_ENV
45-
fi
4640
- name: Create backport pull request
4741
uses: korthout/backport-action@v4
4842
with:
49-
add_labels: ${{ env.BACKPORT_PR_LABELS }}
43+
add_labels: 'backport'
44+
copy_labels_pattern: '.*'
45+
label_pattern: ''
5046
target_branches: ${{ env.BACKPORT_TARGET }}

0 commit comments

Comments
 (0)