azure-devops - Copy pull request description to work item comments on Azure Devops
问题描述
When PR is approved, there is message "Completing Pull Request 123 and the associated work items." added to associated work item's comments area.
Is there any way how to append PR description?
I have zapier webhook attached to comments and I wont to get PR message in another app.
解决方案
When PR is approved, there is message "Completing Pull Request 123 and the associated work items." added to associated work item's comments area.
Based on this description, I guess you are attempting to append the PR description to work item comment while the Pull Request is completing
, right?
Afraid to say that there's no such out-of-box feature can let you direct to use. But you can consider to run powershell scripts along with rest api in build pipeline to achieve such goal.
The logic of my suggestion is:
Step 1: Prepare environment.
Create one build pipeline, and make its trigger type
as Continues Integration
(CI). Only this, the pull request completing can trigger this pipeline processing, then do next job.
Step 2: Get the PR completing node id, then get corresponding Pull request ID by calling this PRs query api.
For the build which run by CI, there has one environment variable Build.SourceVersion
can represents the merge node id which generated by Pull request complete.
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.
]
}
]
}
Then, in its response body, you will see there has one parameter pullRequestId
which target to the Pull request this commit id associated with.
Step 3: Get detailed PR description
and work item id
by using the pull request id
we get in step 2.
Get https://dev.azure.com/{org}/{project name}/_apis/git/repositories/{repo name}/pullrequests/{pull request id}?includeWorkItemRefs=true&api-version=5.1
Put the pull reqeust id
we got from step 2
into this api, then you can see the description
contents along with the work item id
from its response body:
Step 4: Add this description contents to corresponding work item comment area.
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
}
]
As I mentioned firstly, make sure this pipeline is triggered by CI. Then you will get the description
contents be added into WIT comment
once the Pull request is completing.
推荐阅读
- facebook-graph-api - Facebook 图形 API 和到达时间
- java - 实际 Jackrabbit/Oak 指南和文档
- sas - SAS:通过 ID 识别最后一个非缺失值
- phoenix-framework - 不能为 elixir 中的 rumbl 教程项目使用生成器
- java - JSONArray 大于 261 时应用崩溃
- excel - 更新工作簿链接源
- php - 使用 .htaccess 和 php 代码在 seo 友好的 .htaccess 中处理不存在的页面
- python - 在 Windows 中获取用户日期格式
- html - 如何更改复选框的大小并添加 icheck 插件的边框半径?
- extended-sql - 将数字转换为时间格式 HH:mm:ss