[GitAction] Fix Duplicate Approvals
authorDongHak Park <donghak.park@samsung.com>
Mon, 3 Apr 2023 04:59:10 +0000 (13:59 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Tue, 4 Apr 2023 11:50:13 +0000 (20:50 +0900)
Fix Duplicate Approval
- now git action count all approval
- For example someone Approve PR --> Update PR --> Approve Again then they count 2
- For example CI Approve PR every time they success then gitaction count them all

The given Git Action code performs the following tasks
1. Uses the curl command to call the GitHub REST API and retrieve a list of reviews for the given pull request in the repository.
2. Uses the jq command to filter the reviews based on whether their state is "APPROVED".
3. Extracts the login names of the users who wrote each of the filtered reviews.
4. Uses the unique function to filter out only the unique login names, removing any duplicates.
5. Calculates the length of the resulting list of unique login names, giving the count of unique users who have approved the pull request.

Therefore, this code removes any duplicate approvals, counting each unique user only once, even if they have approved more than once.

Signed-off-by: DongHak Park <donghak.park@samsung.com>
.github/workflows/Upload.yml

index d7e4fcb..f5f18b6 100644 (file)
@@ -18,7 +18,7 @@ jobs:
         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')
+          | jq '[ .[] | select(.state=="APPROVED") | .user.login ] | unique | length')
           echo "Number of approved review_count: $review"
           echo "CONTAIN=$IS_CONTAIN"