2 回答

TA貢獻1821條經驗 獲得超5個贊
默認情況下,我們只能通過登錄用戶添加評論。
但是,您可以使用 REST API 將評論添加到與另一個用戶的討論中,以更新啟用System.ChangedBy字段的值bypassRules:
以下樣本供您參考:
Param(
[string]$baseurl = "http://server:8080/tfs/DefaultCollection",
[string]$projectName = "ProjectName",
[string]$workitemID = "26",
[string]$user = "username",
[string]$token = "token/Password"
)
# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
write-host $WorkitemType
function CreateJsonBody
{
$value = @"
[
{
"op": "add",
"path": "/fields/System.History",
"value": "Comment here"
},
{
"op": "add",
"path": "/fields/System.ChangedBy",
"value": "[email protected]"
}
]
"@
return $value
}
$json = CreateJsonBody
$uri = "$baseurl/$($projectName)/_apis/wit/workitems/$($workitemID)?bypassRules=true&api-version=2.2"
Write-Host $uri
$result = Invoke-RestMethod -Uri $uri -Method Patch -Body $json -ContentType "application/json-patch+json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
"value": "[email protected]" 可以是其他用戶的有效用戶 ID (guid) 或用戶電子郵件。

TA貢獻1921條經驗 獲得超9個贊
僅當您使用他的憑據登錄時,您才能以其他用戶的身份向討論添加評論:
NetworkCredential cred = new NetworkCredential("anotherUserName", "password");
TfsTeamProjectCollection _tfs = new TfsTeamProjectCollection(new Uri("serverUrl"), cred);
_tfs.EnsureAuthenticated();
在您像其他用戶一樣進行身份驗證后,您將文本添加到“歷史記錄”字段,您將在討論中看到作為其他用戶登錄的文本。
- 2 回答
- 0 關注
- 224 瀏覽
添加回答
舉報