Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TFS Client API - Query to get work items linked to a specific file?

We are writing a custom tool using TFS client APIs, to connect to TFS, to fetch work items for a project etc.


We are querying the work item store, using WIQL.

Given a fully qualified filename, what is the easiest way to get a list of work items that have change sets which contain the specified file?

like image 686
amazedsaint Avatar asked Mar 06 '09 09:03

amazedsaint


2 Answers

I'm not sure that there is an easy way to do the query that you are requesting using the TFS API. I know that you definately cannot do it using WIQL. I think, using the API, you would have to iterate over all the work items - get the changeset links in them and then look in each changeset for the file path that you are after. This is obviously not much use.

You could get that data using the TFS Data Warehouse database however. This information will lag behind the live operational store information because the warehouse only gets updated periodically - but will allow you to track things by the folder/file dimension pretty easily.

like image 178
Martin Woodward Avatar answered Nov 05 '22 02:11

Martin Woodward


This little code snippet will get you a collection of work items given a TFS server name and a project.. It also filters out work items in the deleted state.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

    namespace EngineTFSAutomation
    {
        class TFSHelper
        {
            static public WorkItemCollection QueryWorkItems(string server, string projectname)
            {
                TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(server);
                WorkItemStore workItemStore = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
                Project p = workItemStore.Projects[projectname];
                string wiqlQuery = "Select * from Issue where [System.TeamProject] = '"+projectname+"'";
                wiqlQuery += " and [System.State] <> 'Deleted'";
                wiqlQuery+= " order by ID";
                WorkItemCollection witCollection = workItemStore.Query(wiqlQuery);
                return witCollection;
            }
        }
    }
like image 28
Ivan Bohannon Avatar answered Nov 05 '22 02:11

Ivan Bohannon