我想在 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 编码。
这可能吗?
我已经测试了脚本示例并重现了相同的问题。
问题的原因可能是特殊字符(例如#)会改变 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
结果: