2016-05-24 39 views
1

我正在嘗試使用Microsoft.TeamFoundation.WorkItemTracking.Client查找與工作項關聯的所有變更集。使用查詢我能夠獲得關於有問題的工作項目的信息,但是我找不到有關我回來的對象的任何變更集信息。除此之外,還有一些變更集與特定工作項目沒有關聯,但可以通過評論輕鬆識別。有沒有一種快速的方法來找到這些使用tfs api?查找與工作項目相關的變更集或具有特定註釋TFS Api

編輯:這不是How to get work items associated with a changeset id using tfs api? b/c的重複在那個問題人有一個變更集,並希望找到相關的工作項目。在我的情況下,我有一個工作項目,我想找到與特定工作項目相關的所有變更集。除此之外,我需要查找註釋中具有特定字符串的所有變更集。

+0

的可能的複製[如何使用tfs api獲取與變更集ID相關聯的工作項?](http://stackoverflow.com/questions/1623355/how-to-get-work-items-associated-with-a-changeset-id-using -tfs-api) – DaveShaw

+0

你正在使用哪個版本的TFS? –

+0

@DaveShaw,這是另一種方式:我沒有變更集,但我有一個工作項目或評論。 – AlexanderM

回答

4

關於這個問題更多的谷歌搜索和探索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)); 
} 

如果需要通過評論來獲得,以及那麼你門的日期範圍和所有的變更n通過Changeset.Comment過濾出來,這是一個字符串。

+0

可以使用:var extLink = link作爲ExternalLink;如果(link == null)繼續;這樣你就不必使用「是ExternalLink」,然後在劇組中重複「ExternalLink」。見http://www.c-sharpcorner.com/uploadfile/abhikumarvatsa/the-is-and-as-operators-in-C-Sharp/ – JoelFan

1

檢查REST API

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