GitHub action to add a label to approved Pull Requests
50K+
Label PRs that have been approved a number of times.
Inspired from label-when-approved-action but with support for PRs from forks.
Install this GitHub action by creating a file in your repo at .github/workflows/label-approved.yml.
A minimal example could be:
name: Label Approved
on:
schedule:
- cron: "0 0 * * *"
jobs:
label-approved:
runs-on: ubuntu-latest
steps:
- uses: docker://tiangolo/label-approved:0.0.2
# You can also use the action directly, but that will take about an extra minute:
# - uses: tiangolo/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
This example uses the defaults configurations.
It will run every night and check all the open PRs, for each PR with the label awaiting review, it will check the approvals.
If there are 2 or more approvals, it will remove the label awaiting review and will add the label approved-2.
You can add different labels to apply.
And for each label, you can specify:
number: the minimum number of approvals.await_label: a label to filter the PRs. In the example above it is awaiting review (the default when no configs are provided).
await_label is omitted or null, it will apply to all open PRs.These configs are passed as a JSON object, but as GitHub actions can only take strings as parameters, the JSON object has to be converted to a string.
Check the next example...
Here's an example with 3 labels to apply, each with its own config.
It's all inside of a single JSON config, passed as a multiline string.
In YAML (this format) you can use > to declare that a string has multiple lines.
name: Label Approved
on:
schedule:
- cron: "0 0 * * *"
jobs:
label-approved:
runs-on: ubuntu-latest
steps:
- uses: docker://tiangolo/label-approved:0.0.2
with:
token: ${{ secrets.GITHUB_TOKEN }}
config: >
{
"approved-1":
{
"number": 1,
"await_label": "awaiting review"
},
"omg 2 approved":
{
"number": 2,
"await_label": "only 2"
},
"approvals in 3D":
{
"number": 3
}
}
Note: Have in mind that after the > the multiline has to have at least one more level of indentation than the key config above.
Here's what this config will do:
Check each open PR, and:
approved-1 to open PRs with:
awaiting review (removing it afterwards).omg 2 approved to open PRs with:
only 2 (removing it afterwards).approvals in 3D to open PRs with:
await_label was not declared, so, any open PR will match.First release 🎉
This project is licensed under the terms of the MIT license.
Content type
Image
Digest
sha256:02a19d33e…
Size
381.4 MB
Last updated
almost 2 years ago
docker pull tiangolo/label-approved