0

I am trying to read Github labels from Pull Requests as I want to run certain Azure pipeline tasks only if a label bug is present on the Pull Request.

Currently, I have as follows:

steps:
  - bash: |
      if curl -s -H 'Authorization: <pat-token>' "https://api.github.com/repos/$BUILD_REPOSITORY_ID/issues/$SYSTEM_PULLREQUEST_PULLREQUESTNUMBER/labels" | grep '"name": "bug"'
      then 
        echo '##vso[task.setvariable variable=hasLabel;isOutput=true]true"
      else
        echo "Label Bug not found"
      fi
      echo "Value of LabelFlag is : ${hasLabel}" 
    displayName: check for label on PR
    name: checkPRLabel    

I am getting Label Bug not found even if the label actually exists - indicating there may be something wrong in the way I am trying to read the labels from Pull Request. When I try to run the curl alone - I get the Not found as an output of that API call. Any suggestions on how else to read the labels from Pull Request?

rsram312
  • 99
  • 2
  • 13
  • I would try to execute only the curl command to check the output from the build agent. The command seems correct for the gathering of the labels. – GeralexGR Apr 07 '22 at 08:03
  • @GeralexGR When I just run the curl, I get “Message: Not found” as the output of the curl. Wondering if it has anything to do with the way I am passing the tokens ? – rsram312 Apr 07 '22 at 14:26
  • 1
    yes it should be something related to the authentication. Try to adjust curl command. https://docs.github.com/en/rest/overview/other-authentication-methods. The example that is provided from github `curl -v -H "Authorization: token TOKEN" https://api.github.com/user/issues` – GeralexGR Apr 07 '22 at 14:31
  • Issue was with the format `token` was passed. Above syntax of `curl -v -H "Authorization: token TOKEN"` worked. Thanks ! @GeralexGR – rsram312 Apr 13 '22 at 21:16

0 Answers0