[GitHub Actions] Check Pull request labels

2024-02-03 hit count image

Let's see how to use PR Labels Checker that is one of GitHub Actions to check the labels of Pull request in GitHub.

Outline

You can manage Pull request using Labels in GitHub.

GitHub Actions - PR Labels Checker, pull request labels

In this blog post, I will introduce how to use PR Labels Checker that is one of GitHub Actions to check the Labels of Pull request in GitHub.

Blog series

This blog is made in series. Please check other blog posts through the following link.

PR Labels Checker

PR Labels Checker is one of GitHub Actions and provides a function to check the Labels of Pull request.

Create GitHub Actions

Let’s create GitHub Actions to check the Labels of Pull request using PR Labels Checker. Create .github/workflows/pr-labels-checker.yml file and modify it as follows.

name: PR Labels Checker

on:
  push:
    branches:
      - main
  pull_request:
    types:
      - opened
      - reopened
      - synchronize
      - labeled
      - unlabeled

jobs:
  pr_labels_checker:
    permissions:
      pull-requests: write
      checks: write
    runs-on: ubuntu-latest
    steps:
      - uses: danielchabr/[email protected]
        with:
          hasSome: breaking change,feature,bug,style,refactor,test,chore,docs,ci,dependencies
          githubToken: $

This GitHub Actions is executed when Pull request is created or Label of Pull request is added or removed.

on:
  push:
    branches:
      - main
  pull_request:
    types:
      - opened
      - reopened
      - synchronize
      - labeled
      - unlabeled

PR Labels Checker requires permission to Pull request and checks.

jobs:
  pr_labels_checker:
    permissions:
      pull-requests: write
      checks: write

Now, you can check the Labels of Pull request using PR Labels Checker. You can use the following conditions to check the Labels.

  • hasSome: The list of Labels separated by commas, the Pull request must include at least one of them.
  • hasAll: The list of Labels separated by commas, the Pull request must include all of them.
  • hasNone: The list of Labels separated by commas, the Pull request must not include any of them.
  • hasNotAll: The list of Labels separated by commas, the Pull request must not include all of them.

In this blog post, I used hasSome condition.

hasSome: breaking change,feature,bug,style,refactor,test,chore,docs,ci,dependencies

The Labels included in the above condition are the list required to Automate Release notes. For more information, please refer to the following link.

PR Labels Checker uses GitHub Token to check the Labels of Pull request in GitHub Actions. Therefore, you need to set GITHUB_TOKEN as follows.

githubToken: $

Release Drafter

In my case, I use Release Drafter to automate Release notes. Release Drafter automatically writes Release notes using the Labels of Pull request. It also has a function to automatically set the Labels by looking at the title of Pull request.

Therefore, Labels of Pull request is important in Release Drafter. Release Drafter automatically sets the Labels of Pull request, but to make sure of this, I am checking the Labels of Pull request again using PR Labels Checker.

The GitHub Actions for Release Drafter and PR Labels Checker are as follows.

name: Release Drafter

on:
  push:
    branches:
      - main
  pull_request:
    types:
      - opened
      - reopened
      - synchronize

permissions:
  contents: read

jobs:
  update_release_draft:
    permissions:
      contents: write
      pull-requests: write
      checks: write
    runs-on: ubuntu-latest
    steps:
      - uses: release-drafter/release-drafter@v5
        env:
          GITHUB_TOKEN: $
      - uses: danielchabr/[email protected]
        with:
          hasSome: breaking change,feature,bug,style,refactor,test,chore,docs,ci,dependencies
          githubToken: $

I use Release Drafter to automatically set the Labels of Pull request, and use PR Labels Checker to check the Labels of Pull request is set correctly again.

For more information about Release Drafter, please see the following link.

Completed

Done! We’ve seen how to use PR Labels Checker to check the Labels of Pull request in GitHub Actions.

If you are managing Pull request using Labels or using Release Drafter like me to automate Release notes, please consider using PR Labels Checker.

Was my blog helpful? Please leave a comment at the bottom. it will be a great help to me!

App promotion

You can use the applications that are created by this blog writer Deku.
Deku created the applications with Flutter.

If you have interested, please try to download them for free.

Posts