簡體   English   中英

查找與工作項關聯的變更集或具有特定注釋的TFS Api

[英]Finding changesets associated with the work item or having specific comment TFS Api

我正在嘗試使用Microsoft.TeamFoundation.WorkItemTracking.Client查找與工作項關聯的所有變更集。 使用查詢,我可以獲得有關工作項的信息,但是我找不到要返回的對象的任何變更集信息。 除此之外,還有一些變更集沒有鏈接到特定的工作項目,但是可以通過注釋輕松識別。 有沒有使用tfs api查找這些文件的快速方法?

編輯:這不是如何使用tfs api如何獲取與變更集ID相關聯的工作項的重復項? 該問題中的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(它是一個字符串)進行過濾。

檢查REST API

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

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

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

您需要使用rel ==“ ArtifactLink”過濾掉“關系”數組

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM