2

It is my goal to get warnings, like actual compile warnings or clang-tidy output, surfaced in a pull request.

The output is properly annotated and in the build the warnings are all displayed prominently. But unfortunately most developers do not check the build, they mostly care if it's green. Making warning errors is not feasible in all cases.

I would like to make the warnings review comments that need to be actively acknowledged. I would implement this as a small service that listens on a web hook and takes the output and posts to the PR via the REST API. (I already have a service that does similar stuff for other reasons.)

To me this sounds like a problem that should already be solved, like in an existing plugin. Is there a simple drop in solution for this?

rioki
  • 5,988
  • 5
  • 32
  • 55

1 Answers1

1

Is there a simple drop in solution for this?

As far as I know, there is currently no out-of-the-box method(Existing Tasks or Extensions) to send the warning to the pull request comment.

As you said, you can use web hook + Rest API to achieve it

The other way is to use the Rest API:Timeline - Get to get the warning message and use another Rest API :Pull Request Thread Comments - Create to create a comment on Pull Request.

Then in Pipeline (Pull Reuqest Trigger), you could add a Powershell Task to run the two Rest API at the same time.

For example:

- task: PowerShell@2
  condition: eq(variables['Build.Reason'], 'PullRequest')
  displayName: Post Message to PR
  env:
    SYSTEM_ACCESSTOKEN: $(System.AccessToken)  
  inputs:
      targetType: filePath
      filePath: Comment.ps1

In this case, when the Pipeline is triggered by Pull Reuqest, the task will run and send the Warning message to comment.

Powershell to Get the warning message sample:

$token = "PAT"

$url="https://dev.azure.com/{OrganizationNAME}/{ProjectName}/_apis/build/builds/{Build.buildid}/timeline?api-version=6.0"

$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))


$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method GET  -ContentType application/json

echo $response.records.issues.message 

..... Send the message to PR Comment....
...

Here is a ticket, you could refer to it.

On the other hand, this requirement is valuable.

You could add your request for this feature on our UserVoice site, which is our main forum for product suggestions. Hope this feature can become a tool out of the box.

Kevin Lu-MSFT
  • 20,786
  • 3
  • 19
  • 28
  • Thank you for the answer, my hunch was correct that there is no canned solutions for this; which is a shame. – rioki Nov 17 '20 at 11:54