File tree Expand file tree Collapse file tree 3 files changed +36
-12
lines changed Expand file tree Collapse file tree 3 files changed +36
-12
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ """Labels PRs based on title. Must be run in a github action with the
2
+ pull_request_target event."""
3
+ from ghapi .all import context_github
4
+ from ghapi .all import GhApi
5
+ from ghapi .all import user_repo
6
+ from ghapi .all import github_token
7
+ import re
8
+
9
+ owner , repo = user_repo ()
10
+ pull_request = context_github .event .pull_request
11
+ title = pull_request .title
12
+
13
+ regex_to_labels = [
14
+ (r"\bDOC\b" , "Documentation" ),
15
+ (r"\bCI\b" , "Build / CI" )
16
+ ]
17
+
18
+ labels_to_add = [
19
+ label for regex , label in regex_to_labels
20
+ if re .search (regex , title )
21
+ ]
22
+
23
+ if labels_to_add :
24
+ api = GhApi (owner = owner , repo = repo , token = github_token ())
25
+ api .issues .add_labels (pull_request .number , labels = labels_to_add )
Original file line number Diff line number Diff line change 1
1
name : Pull Request Regex Title Labeler
2
2
on :
3
3
pull_request_target :
4
- types : [opened]
4
+ types : [opened, edited ]
5
5
6
6
jobs :
7
7
8
8
labeler :
9
- runs-on : ubuntu-latest
9
+ runs-on : ubuntu-20.04
10
10
steps :
11
- - name : Check Labels
12
- id : labeler
13
- continue-on-error : true
14
- uses : jimschubert/labeler-action@v2
11
+ - uses : actions/checkout@v2
12
+ - uses : actions/setup-python@v2
15
13
with :
16
- GITHUB_TOKEN : ${{secrets.GITHUB_TOKEN}}
14
+ python-version : ' 3.9'
15
+ - name : Install ghapi
16
+ run : pip install -Uq ghapi
17
+ - name : Label pull request
18
+ run : python .github/scripts/label_title_regex.py
19
+ env :
20
+ CONTEXT_GITHUB : ${{ toJson(github) }}
You can’t perform that action at this time.
0 commit comments