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

前端 未结 3 1443
后悔当初
后悔当初 2021-01-15 11:53

I\'m trying to find all changesets associated with the work item using Microsoft.TeamFoundation.WorkItemTracking.Client. Using query I was able to get the information about

相关标签:
3条回答
  • 2021-01-15 12:28

    Check the REST API:

    GET https://{instance}/defaultcollection/_apis/tfvc/changesets/{id}?api-version={version}[&includedetails={boolean}&includeworkitems={boolean}&includesourcerenames={boolean}&maxchangecount={int}&maxcommentlength={int}]
    
    0 讨论(0)
  • 2021-01-15 12:48

    After more googling on the subject and exploring tfs API here is what I ended up with:

    If all you changesets are linked to the work items (not really my case but this is what I originally was asking about):

    // 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));
    }
    

    If you need to get by comment as well then you gate all changesets for the daterange and then filter out by Changeset.Comment which is a string.

    0 讨论(0)
  • 2021-01-15 12:48

    You can also use RestAPI (as stated in the first answer)

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

    You need to filter out "relations" array with rel == "ArtifactLink"

    0 讨论(0)
提交回复
热议问题