Label PRs that have been approved a number of times.
Inspired from label-when-approved-action but with support for PRs from forks.
This GitHub Action is now deprecated.
This GitHub Action has been mainly used in FastAPI, the logic is very simple and quite specific to the FastAPI repo. It can be easily implemented in a GitHub Action workflow, in a local script.
If you need similar behavior, consider copying the logic to your own GitHub Action workflow. You can get inspiration from this PR in FastAPI.
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 * * *"
permissions:
pull-requests: write
jobs:
label-approved:
runs-on: ubuntu-latest
steps:
- uses: docker://tiangolo/label-approved:0.0.5
# You can also use the action directly, but that will take about an extra minute:
# - uses: tiangolo/label-approved@0.0.3
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 isawaiting-review
(the default when no configs are provided).- If
await_label
is omitted ornull
, it will apply to all open PRs.
- If
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 * * *"
permissions:
pull-requests: write
jobs:
label-approved:
runs-on: ubuntu-latest
steps:
- uses: docker://tiangolo/label-approved:0.0.5
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:
- Apply the label
approved-1
to open PRs with:- 1 approval (or more).
- The label
awaiting-review
(removing it afterwards).
- Apply the label
omg 2 approved
to open PRs with:- 2 approvals (or more).
- The label
only 2
(removing it afterwards).
- Apply the label
approvals in 3D
to open PRs with:- 3 approvals (or more).
await_label
was not declared, so, any open PR will match.
This GitHub Action is now deprecated.
This GitHub Action has been mainly used in FastAPI, the logic is very simple and quite specific to the FastAPI repo. It can be easily implemented in a GitHub Action workflow, in a local script.
If you need similar behavior, consider copying the logic to your own GitHub Action workflow. You can get inspiration from this PR in FastAPI.
- 📝 Deprecate GitHub Action. PR #25 by @tiangolo.
- 📝 Update required permissions. PR #24 by @tiangolo.
- 📝 Update docs to use needed permissions for orgs. PR #19 by @tiangolo.
- ⬆ Bump tiangolo/issue-manager from 0.5.0 to 0.5.1. PR #23 by @dependabot[bot].
- ⬆ Bump docker/build-push-action from 5 to 6. PR #22 by @dependabot[bot].
- ⬆ Bump docker/build-push-action from 2 to 5. PR #10 by @dependabot[bot].
- ⬆ Bump docker/login-action from 1 to 3. PR #12 by @dependabot[bot].
- ⬆ Bump docker/setup-buildx-action from 1 to 3. PR #9 by @dependabot[bot].
- 👷 Update
issue-manager.yml
. PR #21 by @tiangolo. - 👷 Update
latest-changes
GitHub Action. PR #20 by @tiangolo. - 🔧 Add GitHub templates for discussions and issues, and security policy. PR #18 by @alejsdev.
- ♻️ Upgrade Pydantic version and logic to handle GitHub providing env vars even without values. PR #15 by @tiangolo.
- 🔧 Add funding. PR #13 by @tiangolo.
- 👷 Add dependabot. PR #8 by @tiangolo.
- 👷 Add latest-changes GitHub Action. PR #7 by @tiangolo.
- 🐛 Fix approved user count logic. PR #6 by @tiangolo.
- 🐛 Fix Python app name to be called in Docker. PR #5 by @tiangolo.
- ⬆️ Upgrade GitHub Action Latest Changes. PR #4 by @tiangolo.
- 🐛 Fix logic to compute the number of approvals, count only last approval per user. PR #3 by @tiangolo.
First release 🎉
This project is licensed under the terms of the MIT license.