【发布时间】:2020-07-31 07:51:37
【问题描述】:
当 PR 获得批准时,会出现“正在完成 Pull Request 123 和相关工作项”的消息。添加到相关工作项的 cmets 区域。
有什么方法可以添加 PR 描述吗?
我在 cmets 上附加了 zapier webhook,我不会在另一个应用程序中收到 PR 消息。
【问题讨论】:
标签: azure-devops pull-request tfs-workitem
当 PR 获得批准时,会出现“正在完成 Pull Request 123 和相关工作项”的消息。添加到相关工作项的 cmets 区域。
有什么方法可以添加 PR 描述吗?
我在 cmets 上附加了 zapier webhook,我不会在另一个应用程序中收到 PR 消息。
【问题讨论】:
标签: azure-devops pull-request tfs-workitem
当 PR 被批准时,会有消息“Completing Pull Request 123 and 关联的工作项。”添加到关联的工作项的 cmets 地区。
基于此描述,我猜您正试图将 PR 描述附加到工作项评论,而 Pull Request is completing,对吧?
恐怕没有这种开箱即用的功能可以让你直接使用。但是您可以考虑在构建管道中运行 powershell 脚本和 rest api 来实现这样的目标。
我建议的逻辑是:
第 1 步:准备环境。
创建一个构建管道,并将其trigger type 设为Continues Integration(CI)。只有这样,拉取请求完成才能触发这个管道处理,然后做下一个工作。
第二步:获取PR完成节点id,然后调用PRs query api获取对应的Pull request ID。
对于CI运行的构建,有一个环境变量Build.SourceVersion可以代表Pull request完成生成的合并节点id。
POST https://dev.azure.com/{org}/{project name}/_apis/git/repositories/{repo name}/PullRequestQuery?api-version=6.0-preview.1
{
"queries": [
{
"type": 1,
"items": [
"$(Build.SourceVersion)" // Put the $(Build.SourceVersion) value here.
]
}
]
}
然后,在其响应正文中,您将看到有一个参数 pullRequestId 与此提交 ID 关联的 Pull 请求的目标。
第 3 步:Get detailed PR description and work item id 使用我们在第 2 步中得到的 pull request id。
Get https://dev.azure.com/{org}/{project name}/_apis/git/repositories/{repo name}/pullrequests/{pull request id}?includeWorkItemRefs=true&api-version=5.1
把我们从step 2得到的pull reqeust id放到这个api中,然后你就可以从它的响应体中看到description的内容和work item id:
第四步:Add这个描述内容到对应的工作项评论区。
POST https://dev.azure.com/{org}/{project name}/_apis/wit/workItems/{WorkItem Id}?api-version=5.1-preview.3
[
{
"op": "add",
"path": "/fields/System.History",
"Value": $(description) // put the description here
}
]
正如我首先提到的,确保此管道由 CI 触发。然后,一旦拉取请求完成,您将获得 description 内容被添加到 WIT comment。
【讨论】:
$response.results.$(Build,SourceVersion).PullRequestId
results 对象,所以这里你不需要使用这样的格式:results[0]