使用 Azure DevOps 的 REST API 添加注释和格式设置

问题描述 投票:0回答:1

我想在 PowerShell 中使用 REST API 在工作项上添加格式化注释。

我试过这个:

$comment = [System.Net.WebUtility]::HtmlEncode(" Here is a new file with relevant information: $DDJ Relevant Information #@$%^&*")

$commentwithmention = "<div><a href="#">@User</a>$comment</div>" #9c48ef54-c54b-6049-98ab-982453ed3e4c

$body = @{
    "text" = $commentwithmention
} | ConvertTo-Json

评论本身有效!但我无法格式化文本。我想在

$DDJ Relevant Information

上添加格式、粗体和斜体

HTML 应答器不被解释,事件具有 HTML 编码。

这可能吗?

powershell azure-devops format
1个回答
0
投票

我已经测试了脚本示例并重现了相同的问题。

问题的原因可能是特殊字符(例如#)会改变 HTML 代码的格式。

要解决此问题,您可以使用

'code'
替换
"code"
中的
$commentwithmention

这是一个例子:

$token = ""

$commentwithmention = '<div><a href="#">@User</a><strong>This text is important!</strong></div>'

$url=" https://dev.azure.com/xx/xx/_apis/wit/workItems/xx/comments?api-version=7.0-preview.3"

$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))

$body = @{
    "text" = $commentwithmention
} | ConvertTo-Json
echo $body
$response3 = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method POST -Body $body -ContentType application/jsoN

结果:

enter image description here

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.