Skip to content

Commit

Permalink
Initial import of check_labels action
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed Aug 25, 2020
1 parent 870618f commit f7d9275
Show file tree
Hide file tree
Showing 7 changed files with 620 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
language: python
python:
- "3.8"
- "3.8-dev"
- "nightly"
jobs:
allow_failures:
- python: "nightly"
# command to install dependencies
install:
- pip install -r requirements.txt
- pip install pytest pytest-cov codecov pylint flake8
# command to run tests
script:
- flake8 check_labels.py
- pylint check_labels.py
- pytest
after_success:
- codecov
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM python:3.8-alpine

COPY requirements.txt /tmp/requirements.txt
RUN pip3 install -r /tmp/requirements.txt

COPY check_labels.py /check_labels.py

ENTRYPOINT ["/check_labels.py"]
58 changes: 58 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
Check Labels Action
===================

This action checks the labels of a Pull Request and will succeed or fail based
on the configuration.

Inputs
------

### `access_token`
An optional [personal access token], required for private repositories and to
decrease rate limiting.

[personal access token]: https://github.com/settings/tokens

### `set_labels`
Comma-separated list of labels required to be set. Optional. Globing syntax is
possible for the label name, as defined in [fnmatch].

### `unset_labels`
Comma-separated list of labels required not to be set. Optional. Globing syntax
is possible for the label name, as defined in [fnmatch].

### `cond_labels`
Comma-separated list of (label,condition) tuples for labels introducing a
condition. Optional. Globing syntax is possible for the label name, as defined
in [fnmatch].

#### Supported conditions
- `review.approvals>x`: If the label is set in the Pull Request it requires more
than `x` approving reviews for the action to succeed

[fnmatch]: https://docs.python.org/3/library/fnmatch.html

# Examples

We recommend the following workflow triggers:

```yml
on:
pull_request:
types: [opened, reopened, labeled, unlabeled]
pull_request_review:
types: [submitted, dismissed]
```
The action will fail if "REQUIRE" and "MANDATORY" are not set, if any label
starting with "INVALID" is set, or if "NEEDS >1 ACK" is set, but the PR only has
one or no approval:
```yml
uses: RIOT-OS/[email protected]
with:
access_token: '${{ secrets.GITHUB_ACCESS_TOKEN }}'
set_labels: 'REQUIRE, MANDATORY'
unset_labels: 'INVALID*'
cond_labels: '(NEEDS >1 ACK,review.approvals > 1)'
```
27 changes: 27 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: 'Check Pull Request Labels'
author: 'Martine S. Lenders'
description: 'Checks if certain labels are set or not set and allows conditions'
inputs:
set_labels:
description: 'List of labels required to be set'
required: false
default: ''
unset_labels:
description: 'List of labels required not to be set'
required: false
default: ''
cond_labels:
description: 'List of (label,condition) tuples for labels introducing a condition'
required: false
default: ''
access_token:
description: 'A GitHub personal access tokens for private repositories'
required: false
default: ''
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.set_labels }}
- ${{ inputs.unset_labels }}
- ${{ inputs.cond_labels }}
Loading

0 comments on commit f7d9275

Please sign in to comment.