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.