LoginSignup
0
0

レビュー中、レビューOKの時に自動的にラベルを付与するGithubアクション

Posted at

最近作成したレビュー中、レビューOKの時に自動的にラベルを付与するGithubアクション。

レビューがリクエストされた時にラベルを付与する

name: Add Label on Reviewers Assigned

on:
  pull_request:
    types: [review_requested]

jobs:
  add-label:
    runs-on: ubuntu-latest
    steps:
      - name: Add a label
        uses: actions/github-script@v5
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          script: |
            const pr = context.payload.pull_request;
            const labelToAdd = "レビュー中";
            await github.rest.issues.addLabels({
              owner: context.repo.owner,
              repo: context.repo.repo,
              issue_number: pr.number,
              labels: [labelToAdd]
            });

レビューがApproveされた時にラベルを付与し、任意のラベルを削除する

name: Approval Workflow

on:
  pull_request_review:
    types: [submitted]
permissions:
  contents: read
  pull-requests: write
jobs:
  build:
    if: github.event.review.state == 'approved'
    runs-on: ubuntu-latest
    steps:
      - name: Check out code
        uses: actions/checkout@v2

      - name: Add LGTM label after approval
        uses: actions-ecosystem/action-add-labels@v1.1.0
        if: "!contains(github.event.pull_request.labels.*.name, 'LGTM')"
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          labels: 'LGTM'
      - name: Remove "レビュー中" label after approval
        uses: actions-ecosystem/action-remove-labels@v1
        if: "contains(github.event.pull_request.labels.*.name, 'レビュー中')"
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          labels: 'レビュー中'

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0