gpt4 book ai didi

c# - 查找与工作项关联的变更集或具有特定注释的 TFS Api

转载 作者:行者123 更新时间:2023-11-30 20:20:08 25 4
gpt4 key购买 nike

我正在尝试使用 Microsoft.TeamFoundation.WorkItemTracking.Client 查找与工作项关联的所有变更集。使用查询我能够获得有关工作项的信息,但是我找不到关于我要返回的对象的任何变更集信息。除此之外,还有一些变更集没有链接到特定的工作项,但可以通过评论轻松识别。有没有使用 tfs api 快速找到这些的方法?

编辑:这不是 How to get work items associated with a changeset id using tfs api? 的副本该问题中的 b/c 人有一个变更集,并希望找到相关的工作项。在我的例子中,我有一个工作项,我想找到与特定工作项关联的所有变更集。除此之外,我需要找到所有在评论中具有特定字符串的变更集。

最佳答案

在对这个主题进行更多谷歌搜索并在这里探索 tfs API 之后,我最终得到了:

如果您所有的变更集都链接到工作项(不是我的情况,但这是我最初问的问题):

// based on https://etoptanci.wordpress.com/2011/05/04/seeing-all-code-changes-for-a-work-item/
private static void GetChangesForWorkItem()
{
var configurationServer = TfsConfigurationServerFactory.GetConfigurationServer(new Uri(@"http://myserver:8080/tfs"));
var tpcService = configurationServer.GetService<ITeamProjectCollectionService>();
var collectionNodes = configurationServer.CatalogNode.QueryChildren(
new[] { CatalogResourceTypes.ProjectCollection },
false, CatalogQueryOptions.None);

var collectionNode = collectionNodes.First(x => x.Resource.DisplayName == "<collection name>");

// Use the InstanceId property to get the team project collection
Guid collectionId = new Guid(collectionNode.Resource.Properties["InstanceId"]);
TfsTeamProjectCollection collection = configurationServer.GetTeamProjectCollection(collectionId);
var vcs = collection.GetService<VersionControlServer>();
var store = new WorkItemStore(collection);
var workItems = new List<WorkItem>()
{
store.GetWorkItem(1123),
store.GetWorkItem(1145),
};

var associatedChangesets = new List<Changeset>();

foreach (var workItem in workItems)
{
foreach (var link in workItem.Links)
{
if((link==null) || !(link is ExternalLink))
continue;

string externalLink = ((ExternalLink)link).LinkedArtifactUri;
var artifact =LinkingUtilities.DecodeUri(externalLink);

if (artifact.ArtifactType == "Changeset")
associatedChangesets.Add(vcs.ArtifactProvider.GetChangeset(new Uri(externalLink)));
}
}

Console.WriteLine(associatedChangesets.Select(x=>x.ChangesetId).OrderBy(x => x));
}

如果您还需要通过评论获取,那么您可以对日期范围的所有变更集进行门控,然后通过 Changeset.Comment 过滤掉,这是一个字符串。

关于c# - 查找与工作项关联的变更集或具有特定注释的 TFS Api,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37423721/

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