Azure DevOps中的Ping(@)用户评论

时间:2019-10-25 12:17:15

标签: c# azure azure-devops azure-devops-rest-api tfs-workitem

我具有下面的方法,该方法将注释发布到Azure DevOps中的工作项。

我如何@注释中的用户?

下面的两个示例仅发布了@firstName lastName的字符串,并且未标记用户。

pMessage = "@User you need to take a look at this workitem"

pMessage = "@firstName lastName <mail> you need to take a look at this workitem"

public async Task PingUser(List<int> pId, string pMessage, VssConnection pConnection)
{
    WorkItemTrackingHttpClient client = pConnection.GetClient<WorkItemTrackingHttpClient>();

    foreach (var id in pId)
    {
        await client.UpdateWorkItemAsync(
            new JsonPatchDocument()
            {new JsonPatchOperation(){
                Operation = Operation.Add,
                Value = pMessage,
                Path = "/fields/System.History",
            }}, id);
    }
}

1 个答案:

答案 0 :(得分:2)

如果执行Get操作,您会看到所需的格式:

var wi = workitemClient.GetWorkItemAsync("project", id).Result;

wi.Fields["System.History"]的值是:

enter image description here

因此格式为:

<a href="#" data-vss-mention="version:2.0,userid"></a>

用用户ID替换userid,可以使用User Entitlements - List Rest API来获取它。