-
Notifications
You must be signed in to change notification settings - Fork 3
/
action.yml
40 lines (40 loc) · 1.62 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
name: 'mergify-merge-queue-labels-copier'
description: 'Mergify: copies pull request labels to merge queue draft PRs'
branding:
icon: arrow-up
color: 'blue'
inputs:
labels:
description: 'Comma separated list of labels to copy (all if empty)'
required: true
default: ''
additional-labels:
description: 'Comma separated list of additional labels to add to the merge queue PR'
required: false
default: ''
token:
description: 'The GitHub token to use for API requests'
required: false
default: ${{ github.token }}
runs:
using: "composite"
steps:
- name: Copying labels
shell: bash
if: startsWith(github.head_ref, 'mergify/merge-queue/')
env:
REPOSITORY_URL: ${{ github.server_url }}/${{ github.repository }}
MERGE_QUEUE_PR_URL: ${{ github.server_url }}/${{ github.repository }}/pull/${{ github.event.pull_request.number }}
GH_TOKEN: ${{ inputs.token}}
ADDITIONAL_LABELS: ${{ inputs.additional-labels }}
run: |
gh pr view --json body -q ".body" $MERGE_QUEUE_PR_URL | sed -n -e '/```yaml/,/```/p' | sed -e '1d;$d' | yq '.pull_requests[]|.number' | while read pr_number ; do
gh pr view --json labels -q '.labels[]|.name' ${REPOSITORY_URL}/pull/$pr_number | while read label ; do
if [[ -z "$labels" ]] || [[ ",$labels," =~ ",$label," ]]; then
gh pr edit --add-label "$label" $MERGE_QUEUE_PR_URL
fi
done
for additional_label in $(echo $ADDITIONAL_LABELS | sed "s/,/ /g") ; do
gh pr edit --add-label "$additional_label" $MERGE_QUEUE_PR_URL
done
done