【问题标题】:Azure DevOps generate an Artifact ID for a Pull RequestAzure DevOps 为拉取请求生成工件 ID
【发布时间】:2021-02-09 07:24:13
【问题描述】:
Azure DevOps API 文章 Evaluations - List 描述了如何接收特定拉取请求的所有策略评估状态的列表。
打电话
GET https://dev.azure.com/{organization}/{project}/_apis/policy/evaluations?artifactId={artifactId}&api-version=6.0-preview.1
您需要artifactId 来进行请求。 artifactId 标识一个拉取请求,它可能是来自 Pull Requests - Get Pull Request 的响应的一部分。但不是,artifactId? 是空的。
因此,我认为,文章的作者添加了以下部分:
使用唯一标识拉取请求的工件 ID 检索评估。要为拉取请求生成工件 ID,请使用此模板:
vstfs:///CodeReview/CodeReviewId/{projectId}/{pullRequestId}
我应该如何处理这个模板?有例子吗?我不明白这部分,不知道该怎么办。
【问题讨论】:
标签:
azure-devops
azure-devops-rest-api
【解决方案1】:
文档中的描述是指artifact ID的值格式如下:
vstfs:///CodeReview/CodeReviewId/{projectId}/{pullRequestId}
所以你可以使用如下模板:
https://dev.azure.com/{organization}/{project}/_apis/policy/evaluations?artifactId=vstfs:///CodeReview/CodeReviewId/{projectId}/{pullRequestId}&api-version=6.1-preview.1
请参见下面的 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