Mar Tin
Mar Tin

Reputation: 2412

Azure DevOps generate an Artifact ID for a Pull Request

The Azure DevOps API article Evaluations - List describe how to receive a list of all the policy evaluation statuses for a specific pull request.

To call

GET https://dev.azure.com/{organization}/{project}/_apis/policy/evaluations?artifactId={artifactId}&api-version=6.0-preview.1

you need the artifactId for the request. The artifactId identify a pull request and it could be a part of the response from the Pull Requests - Get Pull Request. But it isn't, the artifactId? is empty.

Therefore, I think, the Author of the article add the following part:

Evaluations are retrieved using an artifact ID which uniquely identifies the pull request. To generate an artifact ID for a pull request, use this template:

vstfs:///CodeReview/CodeReviewId/{projectId}/{pullRequestId}

What should I do with this template? Is there an example? I do not understand this part and don't know what to do.

Upvotes: 5

Views: 1232

Answers (1)

Levi Lu-MSFT
Levi Lu-MSFT

Reputation: 30353

The description in the document means the value artifact ID is in below format:

vstfs:///CodeReview/CodeReviewId/{projectId}/{pullRequestId}

So you can use the template like below:

https://dev.azure.com/{organization}/{project}/_apis/policy/evaluations?artifactId=vstfs:///CodeReview/CodeReviewId/{projectId}/{pullRequestId}&api-version=6.1-preview.1

See below example in powershell:

$pat = "36w.......f65q"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($pat)"))

$url = "https://dev.azure.com/myOrg/myProj/_apis/policy/evaluations?artifactId=vstfs:///CodeReview/CodeReviewId/39-...e13f/148&api-version=6.1-preview.1"

Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic {0}" -f $base64AuthInfo} -Method Get

Upvotes: 7

Related Questions