[Propose][GitAction] Review Request Auto labeler
authorDonghak PARK <donghak.park@samsung.com>
Wed, 15 Feb 2023 04:23:53 +0000 (13:23 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Thu, 23 Feb 2023 11:25:13 +0000 (20:25 +0900)
- this git action yml will automatically label "Need Review" when cretae PR
- when it edit or reopen it will automatically make label
- and It also remove when approved review exceed 3

For this we need ```secrets.GITHUB_TOKEN```

Signed-off-by: DongHak Park <donghak.park@samsung.com>
.github/workflows/labeler.yml [new file with mode: 0644]

diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml
new file mode 100644 (file)
index 0000000..0868c61
--- /dev/null
@@ -0,0 +1,56 @@
+# @author : Donghak Park <donghak.park@samsung.com>
+# @file   : labeler.yml
+# @date   : 15 Feb 2023
+
+name: Auto Need-Review labeler
+
+on:
+  pull_request:
+    types: [opened, edited, reopened, synchronize]
+  pull_request_review:
+    types: [edited, dismissed, submitted]
+
+jobs:
+  label:
+    runs-on: ubuntu-latest
+    steps:
+      - name: review_count
+        id: review_count
+        run: |
+          review=$(curl -s -H "Accept: application/vnd.github.black-cat-preview+json" \
+          https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/reviews \
+          | jq '[ .[] | select(.state=="APPROVED") ] | length')
+          echo "Number of approved review_count: $review"
+          echo "::set-output name=review::$review"
+          echo "REVIEW=$review" >> $GITHUB_OUTPUT
+
+      
+      - name: DEBUG
+        run: |
+          echo "Number of Approved review_count : ${{ steps.review_count.outputs.REVIEW }}"
+
+      - name: Make label if approved review < 3
+        if: ${{ steps.review_count.outputs.REVIEW < 3 && !contains(github.event.pull_request.labels.*.name, 'Need Review') }}
+        uses: actions/github-script@v4
+        with:
+          script: |
+            github.issues.addLabels({
+              owner: context.repo.owner,
+              repo: context.repo.repo,
+              issue_number: context.issue.number,
+              labels: ["Need Review"]
+            })
+          token: ${{ secrets.GITHUB_TOKEN }}
+
+      - name: Remove label if approved review >= 3
+        if: ${{ steps.review_count.outputs.REVIEW >= 3 && contains(github.event.pull_request.labels.*.name, 'Need Review') }}
+        uses: actions/github-script@v4
+        with:
+          script: |
+            github.issues.removeLabel({
+              owner: context.repo.owner,
+              repo: context.repo.repo,
+              issue_number: context.issue.number,
+              name : ["Need Review"]
+            })
+          token: ${{ secrets.GITHUB_TOKEN }}