Skip to content

Commit 0d2ff89

Browse files
committed
Add PR labeling buttons in the PR template
1 parent b0c26b4 commit 0d2ff89

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,11 @@ Closes #<ticket number>
77
- [ ] (not applicable?)
88
- [ ] Documentation
99
- [ ] (not applicable?)
10+
11+
#### PR label(s): <!-- It's easier to fill those after submitting your PR -->
12+
- [ ] https://github.com/procrastinate-org/procrastinate/labels/PR%20type%3A%20breaking%20%F0%9F%92%A5
13+
- [ ] https://github.com/procrastinate-org/procrastinate/labels/PR%20type%3A%20feature%20%E2%AD%90%EF%B8%8F
14+
- [ ] https://github.com/procrastinate-org/procrastinate/labels/PR%20type%3A%20bugfix%20%F0%9F%95%B5%EF%B8%8F
15+
- [ ] https://github.com/procrastinate-org/procrastinate/labels/PR%20type%3A%20miscellaneous%20%F0%9F%91%BE
16+
- [ ] https://github.com/procrastinate-org/procrastinate/labels/PR%20type%3A%20dependencies%20%F0%9F%A4%96
17+
- [ ] https://github.com/procrastinate-org/procrastinate/labels/PR%20type%3A%20documentation%20%F0%9F%93%9A

.github/workflows/pr-labels.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Label PR
2+
3+
on:
4+
pull_request_target:
5+
types:
6+
- opened
7+
- reopened
8+
- edited
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
pull-requests: write
15+
steps:
16+
- run: |
17+
export LABELS=$(gh repo view $REPO --json="labels" --jq='.labels[].name | select(startswith(env.PREFIX))')
18+
python <(cat <<EOF
19+
import sys, os
20+
from urllib.parse import quote
21+
url = f"https://github.com/{os.environ['REPO']}/labels/"
22+
labels = os.environ['LABELS'].strip().splitlines()
23+
prefix = os.environ['PREFIX']
24+
checked = "- [x] "
25+
unchecked = "- [ ] "
26+
for line in os.environ["BODY"].splitlines():
27+
for label in labels:
28+
if label.startswith(prefix) and line.strip().endswith(url + quote(label)):
29+
if line.strip().startswith(checked):
30+
print(f"--add-label={label}")
31+
elif line.strip().startswith(unchecked):
32+
print(f"--remove-label={label}")
33+
EOF) | xargs -d '\n' gh pr --repo $REPO edit
34+
35+
env:
36+
PREFIX: "PR type: "
37+
REPO: procrastinate-org/procrastinate
38+
BODY: ${{github.event.pull_request.body}}
39+
NUMBER: ${{ github.event.pull_request.number }}
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)