Skip to content

Instantly share code, notes, and snippets.

@eskfung
Created October 6, 2021 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eskfung/6e66d623f234bf65bfa7877d76443ff7 to your computer and use it in GitHub Desktop.
Save eskfung/6e66d623f234bf65bfa7877d76443ff7 to your computer and use it in GitHub Desktop.
Require the presence of certain labels before a pull request is ready to merge
# .github/workflow/require-pr-labels.yml
name: Require Pull Request Labels
permissions:
pull-requests: read # Needs read permissions in order to read labels and reviews
on:
pull_request:
types: [labeled, unlabeled, opened, edited, reopened, synchronize]
pull_request_review:
types: [submitted, edited, dismissed]
jobs:
require_pr_labels:
runs-on: ubuntu-latest
steps:
- uses: octokit/request-action@v2.x
id: get_reviews
with:
route: GET ${{ github.event.pull_request.url }}/reviews
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: mheap/github-action-required-labels@v1
if: contains(fromJson(steps.get_reviews.outputs.data)[*].state, 'APPROVED')
with:
mode: exactly
count: 0
labels: "pending-acceptance"
- uses: mheap/github-action-required-labels@v1
if: contains(fromJson(steps.get_reviews.outputs.data)[*].state, 'APPROVED')
with:
mode: minimum
count: 1
labels: "accepted, chore, dependencies, migration"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment