Azure DevOps:代表另一个用户创建评论

Azure DevOps: create a comment on behalf of another user

我正在寻找一种方法来代表另一个用户(模拟另一个用户)向工作项添加评论。

        VssConnection connection = new VssConnection(new Uri(url), new VssClientCredentials());
        WorkItemTrackingHttpClient client = connection.GetClient<WorkItemTrackingHttpClient>();

        patchDocument.Add(
            new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path = "/fields/System.History",
                Value = "Sample comment 1"
            }
        );

        await client.UpdateWorkItemAsync(patchDocument, id);

要在 Azure DevOps 中的工作项上创建评论(或代表某人进行更改),您需要在补丁文档中设置 System.ChangedBy 字段并使用 bypassRules:true

        WorkItemTrackingHttpClient client = connection.GetClient<WorkItemTrackingHttpClient>();

        patchDocument.Add(
            new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path = "/fields/System.History",
                Value = "Sample comment 1"
            }
        );
        patchDocument.Add(
            new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path = "/fields/System.ChangedBy",
                Value = "user@onbehalfof.com" //can be valid user id (guid) or user email (domain\alias for onprem).
            });

        await client.UpdateWorkItemAsync(patchDocument, id, bypassRules:true);

此外,要能够设置 bypassRules:true - 执行操作的身份必须具有适当的权限:"Bypass rules on work item updates"