Search code examples
azure-devopsazure-devops-rest-api

Possible CodeReviewThreadTypes of Azure Devops Git Api Threads


I was unable to find anywhere on the internet what the accepted CodeReviewThreadType values were in the Azure DevOps Thread API. I am trying to make our remote service add a system message like "Pull Request successfully linked with XY." and don't want to spam it with huge comments.

I tried abusing some of the types that I usually see in pullrequests - StatusUpdate, RefUpdate, ReviewersUpdate, IsDraftUpdate... but they seem to be translated so the "content" of the comment is ignored and the message stays empty.

Does anyone have any experience with this? I don't need all supported types, just one that gives the desired output.

Desired output with example of content being ignored:

Desired output with example of content being ignored

Code sample:

await gitApi.createThread({
    comments: [
        {
            parentCommentId: 0,
            content: "System Comment Test",
            commentType: CommentType.System,
        },
    ],
    properties: {
        CodeReviewThreadType: {
            "$type": "System.String",
            "$value": "StatusUpdate"
        },
    },
}, (pr.repository!).id!, pr.pullRequestId!);

Solution

  • I am trying to make our remote service add a system message like "Pull Request successfully linked with XY." and don't want to spam it with huge comments.

    It seems that there is no API can create a system message in the pull request currently.

    Maybe you can try the workaround to Comment on the pull request with the default status closed. This would reduce the time you manually close the comment.

    sample script:

    $organization = ""
    $project=""
    $pullRequestId="64"
    $PAT=""
    
    $PATGetBytes = [System.Text.Encoding]::ASCII.GetBytes(":$PAT")
    $Authentication = [System.Convert]::ToBase64String($PATGetBytes)
    $Headers = @{Authorization = ("Basic {0}" -f $Authentication) }
    $Uri = "https://dev.azure.com/$organization/$($project)/_apis/git/repositories/testrepo/pullRequests/$pullRequestId/threads?api-version=7.2-preview.1"
    
    $body = @"
    {
      "comments": [
        {
          "parentCommentId": 0,
          "content": "Pull Request successfully linked with XY."
        }
      ],
      "status": "closed"
    }
    "@
    
    $response = Invoke-RestMethod -Uri $Uri  -Method 'POST' -Headers $headers -Body $body -ContentType 'application/json'
    $response | ConvertTo-Json
    
    

    Result:

    comment

    You can also request the feature for Azure DevOps here to help the feature better. Engineers usually prioritize features that are urgent or have more votes.