Git Product home page Git Product logo

label-approved's Introduction

Label Approved

Label PRs that have been approved a number of times.

Inspired from label-when-approved-action but with support for PRs from forks.

How to use

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.3
    # 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.

Configuration

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).
    • If 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...

Configuration 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.3
      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.

Release Notes

Latest Changes

0.0.4

Refactors

  • ♻️ Rename default label from "awaiting review" to "awaiting-review". PR #16 by @tiangolo.

0.0.3

Fixes

  • ♻️ Upgrade Pydantic version and logic to handle GitHub providing env vars even without values. PR #15 by @tiangolo.

Internal

0.0.2

  • 🐛 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.

0.0.1

First release 🎉

License

This project is licensed under the terms of the MIT license.

label-approved's People

Contributors

tiangolo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.