2

I am trying to write a bash function which should return me the pull request approvals count using the PR ID. I know the below API URL will provide me with the whole body of pull request response in json. I want to know if there is any other way to easily get through instead looping all the approvals in response body? Samples will help me. Please assist.

local getDetails=$(curl -w "status_code:%{http_code}\\n" -s -k -u "${User}:${Password}" -X GET        "$BITBUCKET_URL/rest/api/1.0/projects/${projectCode}/repos/${repoName}/pull-requests/${prId}")

local resBody=$(echo $getDetails| sed -e 's/status_code\:.*//g')
   
user1125741
  • 45
  • 1
  • 6

1 Answers1

0
curl -s 'https://bitbucket/rest/api/1.0/projects/{project}/repos/{repo}/pull-requests/{pr-id}/' --header 'Authorization: Bearer KEY'|jq '.reviewers[].approved'|grep true|wc -l

I used this solution to count current approvals in Jenkins, so according to this number I continue pipeline in a different ways. The output should be the number of approvals for example: 0 if nobody approved, and 3 if there are 3 approves.

dirol13
  • 1
  • 1