gpt4 book ai didi

c# - 如何以编程方式链接 Azure DevOps 中的分支和工作项

转载 作者:行者123 更新时间:2023-12-01 22:59:55 25 4
gpt4 key购买 nike

我正在尝试找到一种方法,通过我正在构建的应用程序将分支添加为 Azure DevOps 中的链接 ( Basically just this, but within a C# console app )。

我越来越熟悉 VisualStudio Services 和 TeamFoundation .NET 库,并尝试通过 DevOps UI 创建的其中一个链接来获取工作项,并将其移植到另一个工作项,作为示例像这样:

var workItemWithBranchLink = await _WorkItemTrackingHttpClient.GetWorkItemAsync(3985, expand: WorkItemExpand.Relations);
var workItemWithoutBranchLink = await _WorkItemTrackingHttpClient.GetWorkItemAsync(3988, expand: WorkItemExpand.Relations);
var document = new JsonPatchDocument();
document.Add(new JsonPatchOperation()
{
Operation = Operation.Add,
Path = "/relations",
Value = workItemWithBranchLink.Relations
});
await _WorkItemTrackingHttpClient.UpdateWorkItemAsync(document, (int)workItemWithoutBranchLink.Id);

但是,这会引发异常

Microsoft.VisualStudio.Services.WebApi.Patch.PatchOperationFailedException: 'Work item patch does not support patching the top level property at path /relations.

由于 workItemWithoutBranchLink.Relations 为空,我不确定我还能如何修补它。

有什么想法吗?

最佳答案

对于 git 链接,语法略有不同,这是一个工作示例(链接 master 分支):

VssConnection testConnection = new VssConnection(new Uri("azure-devops-uri"), new Microsoft.VisualStudio.Services.Common.VssCredentials());
var workItemClient = testConnection.GetClient<WorkItemTrackingHttpClient>();
var gitClient = testConnection.GetClient<GitHttpClient>();
string projectId = "cf456145-abgd-ffs23-be61-0fca39681234";
string repositoryId = "d6856145-abgd-42a3-be61-0fca3968c555";
var branchUri = string.Format
(
"vstfs:///Git/Ref/{0}%2f{1}%2f{2}",
projectId,
repositoryId,
"GBmaster"
);

var json = new JsonPatchDocument();
json.Add(
new JsonPatchOperation()
{
Operation = Operation.Add,
Path = "/relations/-",
Value = new
{
rel = "ArtifactLink",
url = branchUri,
attributes = new
{
name = "Branch",
comment = "Comment"
}
}
});

try
{
int workItemToUpdate = 142144;
var update = workItemClient.UpdateWorkItemAsync(json, workItemToUpdate).Result;
}
catch (Exception e)
{
var error = e.Message;
}

关于c# - 如何以编程方式链接 Azure DevOps 中的分支和工作项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60086163/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com