-
Notifications
You must be signed in to change notification settings - Fork 56
42 lines (39 loc) · 1.38 KB
/
pr-labels.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
41
42
name: Label PR
on:
pull_request_target:
types:
- opened
- reopened
- edited
jobs:
label:
name: Label PR
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- run: |
export LABELS=$(gh repo view $REPO --json="labels" --jq='.labels[].name | select(startswith(env.PREFIX))')
python <(cat <<EOF
import sys, os
from urllib.parse import quote
url = f"https://github.com/{os.environ['REPO']}/labels/"
labels = os.environ['LABELS'].strip().splitlines()
prefix = os.environ['PREFIX']
checked = "- [x] "
unchecked = "- [ ] "
for line in os.environ["BODY"].splitlines():
for label in labels:
if label.startswith(prefix) and line.strip().endswith(url + quote(label)):
if line.strip().startswith(checked):
print(f"--add-label={label}")
elif line.strip().startswith(unchecked):
print(f"--remove-label={label}")
EOF
) | xargs --no-run-if-empty --delimiter '\n' gh pr --repo $REPO edit $NUMBER
env:
PREFIX: "PR type: "
REPO: procrastinate-org/procrastinate
BODY: ${{github.event.pull_request.body}}
NUMBER: ${{ github.event.pull_request.number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}