Skip to content

Commit f7d9275

Browse files
committed
Initial import of check_labels action
1 parent 870618f commit f7d9275

File tree

7 files changed

+620
-0
lines changed

7 files changed

+620
-0
lines changed

.travis.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
language: python
2+
python:
3+
- "3.8"
4+
- "3.8-dev"
5+
- "nightly"
6+
jobs:
7+
allow_failures:
8+
- python: "nightly"
9+
# command to install dependencies
10+
install:
11+
- pip install -r requirements.txt
12+
- pip install pytest pytest-cov codecov pylint flake8
13+
# command to run tests
14+
script:
15+
- flake8 check_labels.py
16+
- pylint check_labels.py
17+
- pytest
18+
after_success:
19+
- codecov

Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM python:3.8-alpine
2+
3+
COPY requirements.txt /tmp/requirements.txt
4+
RUN pip3 install -r /tmp/requirements.txt
5+
6+
COPY check_labels.py /check_labels.py
7+
8+
ENTRYPOINT ["/check_labels.py"]

README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
Check Labels Action
2+
===================
3+
4+
This action checks the labels of a Pull Request and will succeed or fail based
5+
on the configuration.
6+
7+
Inputs
8+
------
9+
10+
### `access_token`
11+
An optional [personal access token], required for private repositories and to
12+
decrease rate limiting.
13+
14+
[personal access token]: https://github.com/settings/tokens
15+
16+
### `set_labels`
17+
Comma-separated list of labels required to be set. Optional. Globing syntax is
18+
possible for the label name, as defined in [fnmatch].
19+
20+
### `unset_labels`
21+
Comma-separated list of labels required not to be set. Optional. Globing syntax
22+
is possible for the label name, as defined in [fnmatch].
23+
24+
### `cond_labels`
25+
Comma-separated list of (label,condition) tuples for labels introducing a
26+
condition. Optional. Globing syntax is possible for the label name, as defined
27+
in [fnmatch].
28+
29+
#### Supported conditions
30+
- `review.approvals>x`: If the label is set in the Pull Request it requires more
31+
than `x` approving reviews for the action to succeed
32+
33+
[fnmatch]: https://docs.python.org/3/library/fnmatch.html
34+
35+
# Examples
36+
37+
We recommend the following workflow triggers:
38+
39+
```yml
40+
on:
41+
pull_request:
42+
types: [opened, reopened, labeled, unlabeled]
43+
pull_request_review:
44+
types: [submitted, dismissed]
45+
```
46+
47+
The action will fail if "REQUIRE" and "MANDATORY" are not set, if any label
48+
starting with "INVALID" is set, or if "NEEDS >1 ACK" is set, but the PR only has
49+
one or no approval:
50+
51+
```yml
52+
uses: RIOT-OS/[email protected]
53+
with:
54+
access_token: '${{ secrets.GITHUB_ACCESS_TOKEN }}'
55+
set_labels: 'REQUIRE, MANDATORY'
56+
unset_labels: 'INVALID*'
57+
cond_labels: '(NEEDS >1 ACK,review.approvals > 1)'
58+
```

action.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: 'Check Pull Request Labels'
2+
author: 'Martine S. Lenders'
3+
description: 'Checks if certain labels are set or not set and allows conditions'
4+
inputs:
5+
set_labels:
6+
description: 'List of labels required to be set'
7+
required: false
8+
default: ''
9+
unset_labels:
10+
description: 'List of labels required not to be set'
11+
required: false
12+
default: ''
13+
cond_labels:
14+
description: 'List of (label,condition) tuples for labels introducing a condition'
15+
required: false
16+
default: ''
17+
access_token:
18+
description: 'A GitHub personal access tokens for private repositories'
19+
required: false
20+
default: ''
21+
runs:
22+
using: 'docker'
23+
image: 'Dockerfile'
24+
args:
25+
- ${{ inputs.set_labels }}
26+
- ${{ inputs.unset_labels }}
27+
- ${{ inputs.cond_labels }}

0 commit comments

Comments
 (0)