-
Hello everyone, is there any way of counting the approved PR using github actions? I found this API |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 1 reply
-
@so-amuk, So every time when you execute the API or view the github context of a latest workflow run for the PR, you may get different result with previous. Here I have two workarounds that are relying on jq:
After you open a PR and have added all the reviewers on the PR, in the first workflow run for the PR, you can use this step to get the total count of the reviewers. Store and save this number via some way (such as cache) so that you can use it in the subsequent workflow runs for the PR. In the subsequent workflow runs, if some reviewers have approved the PR, you will get the count of the rest reviewers who have not approved the PR. Subtract this count from the saved total count to get the count of approved. (2) Read from the Response body of the API (List reviews on a pull request).
Every time when you execute this, it should return the count of approved. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the answer. Can you please tell me how do you store count number in cache and use it? |
Beta Was this translation helpful? Give feedback.
-
@brightran I tried using 2nd approach here. I get one issue here. If single user has approved the same PR 10 times, then I am getting 10 Approvals for same user in this case. |
Beta Was this translation helpful? Give feedback.
-
@so-amuk,
You can simply write the total count of the reviewers into a text file, then save this text file as a cache with a specified key (for example, key: PR-<PR_number>-total-reviewers). In the subsequent workflow runs, you can restore this cache to the workspace and read the total count of the reviewers from the text file.
Sorry for my mistake, I forget that the command “ConvertTo-Json” is used in PowerShell. If you have added “Content-Type: application/json” into the header of the API, you do not need to convert the response to JSON-type again. Due to the current APIs are based on the review requests, not reviewers. One user may be requested as reviewer multiple times in a PR. So if a user has been requested multiple times, the APIs will return the approvals multiple times. |
Beta Was this translation helpful? Give feedback.
-
Thanks @brightran for your answer and ConvertTo-Json is working fine. Finally I am able to call API and receive data.
Now I am facing some new problem, and didn’t get any solution yet. Can you please have a look jq: error: APPROVED/0 is not defined at , line 1: |
Beta Was this translation helpful? Give feedback.
-
@so-amuk,
Or try cURL on bash:
But there is a problem I found, the select function will return each of the matched objects/elements in the array as an individual object, not group them into a new array. So in this way, it’s hard to get the number of the matched objects. |
Beta Was this translation helpful? Give feedback.
-
Thanks @brightran, really appreciated for your answer. This would help me to resolve my problem. Thanks!! |
Beta Was this translation helpful? Give feedback.
-
@so-amuk, |
Beta Was this translation helpful? Give feedback.
@so-amuk,
Workaround 1: (update)
You can simply write the total count of the reviewers into a text file, then save this text file as a cache with a specified key (for example, key: PR-<PR_number>-total-reviewers). In the subsequent workflow runs, you can restore this cache to the workspace and read the total count of the reviewers from the text file.
However, if some reviewers are add…