【问题标题】:Finding changesets associated with the work item or having specific comment TFS Api查找与工作项关联或具有特定注释 TFS Api 的变更集
【发布时间】:2016-10-20 21:37:46
【问题描述】:

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

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

【问题讨论】:

标签: c# tfs


【解决方案1】:

在对该主题进行了更多谷歌搜索并探索了 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 过滤掉,这是一个字符串。

【讨论】:

【解决方案2】:

查看REST API

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

【讨论】:

    【解决方案3】:

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

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

    您需要使用 rel == "ArtifactLink"

    过滤掉“关系”数组

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-30
      • 2019-01-06
      • 1970-01-01
      • 1970-01-01
      • 2017-01-24
      • 2016-01-14
      • 2011-10-07
      • 2015-05-21
      相关资源
      最近更新 更多