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

时间:2016-05-24 20:56:19

标签: c# tfs

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

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

3 个答案:

答案 0 :(得分:5)

关于这个主题的更多搜索和探索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过滤掉这是一个字符串。

答案 1 :(得分:1)

检查REST API

GET https://{instance}/defaultcollection/_apis/tfvc/changesets/{id}?api-version={version}[&includedetails={boolean}&includeworkitems={boolean}&includesourcerenames={boolean}&maxchangecount={int}&maxcommentlength={int}]

答案 2 :(得分:0)

您也可以使用RestAPI(如第一个答案中所述)

https://www.visualstudio.com/en-us/docs/integrate/api/wit/work-items#with-links-and-attachments

您需要使用 rel ==“ArtifactLink”过滤掉“relations”数组

相关问题