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>
This commit is contained in:
parent
247f32e6ef
commit
05a2e5194a
24
.github/workflows/backport-pr.yml
vendored
24
.github/workflows/backport-pr.yml
vendored
@ -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 <target-branch>" >&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 }}
|
||||
Loading…
x
Reference in New Issue
Block a user