a·gen·tic a·gil·i·ty

List all files changed under an Iteration

TL;DR; Shows how to use TFS API calls to list all files changed in a specific iteration, including querying work items and extracting changesets to a text file.

Published on
2 minute read
Image
https://nkdagility.com/resources/M07b_KU6l8f
Subscribe

I was asked by a colleague to provide a list of all files that were changed under a particular iteration. Rather than delving into the data, I made a couple of API calls to TFS to output a text file with the list.

This is probably not the most efficient method and it is hard coded, but it does output the goods:

 1Dim tfs As New TeamFoundationServer("http://testtfs01:8080")
 2Dim store As WorkItemStore = tfs.GetService(GetType(WorkItemStore))
 3Dim version As VersionControlServer = tfs.GetService(GetType(VersionControlServer))
 4' Query for work items
 5Dim query As String = "SELECT [System.Id], [System.Title] " _
 6                     & "FROM WorkItems " _
 7                     & "WHERE [System.TeamProject] = @Project  " _
 8                     & "AND  [System.IterationPath] UNDER @IterationPath  " _
 9                     & "ORDER BY [System.Id]"
10Dim paramiters As New Hashtable
11paramiters.Add("Project", "TestProject1")
12paramiters.Add("IterationPath", "TestProject1TestIteration1")
13Dim y As WorkItemCollection = store.Query(query, paramiters)
14Console.WriteLine(String.Format("Found {0} work items", y.Count))
15' Query work items for attachments
16Dim wiats = From wi As WorkItem In y, l As Link In wi.Links Where l.BaseType = BaseLinkType.ExternalLink Select l, wi
17Console.WriteLine(String.Format("Loading {0} changesets...", wiats.Count))
18Dim ChangeSets As New List(Of Changeset)
19If Not wiats Is Nothing Then
20    Dim els = From i In wiats Where LinkingUtilities.DecodeUri(CType(i.l, ExternalLink).LinkedArtifactUri).ArtifactType = "Changeset"
21    For Each i In wiats
22        Dim el As ExternalLink = CType(i.l, ExternalLink)
23        Dim artifact As ArtifactId = LinkingUtilities.DecodeUri(el.LinkedArtifactUri)
24        If artifact.ArtifactType = "Changeset" Then
25            Dim cs As Changeset = version.ArtifactProvider.GetChangeset(New Uri(el.LinkedArtifactUri))
26            ChangeSets.Add(cs)
27        End If
28    Next
29    ' ------------------------------
30    Console.WriteLine(String.Format("{0} changesets loaded", ChangeSets.Count))
31    Dim files = From f In ChangeSets, c In f.Changes Select c.Item Distinct
32    Using x = System.IO.File.CreateText("c:Tempfiles.txt")
33        For Each f In files
34            x.WriteLine(f.ServerItem)
35        Next
36
37    End Using
38
39End If
40If Debugger.IsAttached Then
41    Console.ReadKey()
42End If

As you can see I have very bad naming and layout, but this is a one time use version of the code, so quick and dirty. If I am asked to do this again I would create a proper command line utility, or even a WPF interface to display the data prettily.

Technorati Tags: ALM   WIT   TFS Custom   TFBS   Version Control   WPF   TFS

Subscribe

Connect with Martin Hinshelwood

If you've made it this far, it's worth connecting with our principal consultant and coach, Martin Hinshelwood, for a 30-minute 'ask me anything' call.

Our Happy Clients​

We partner with businesses across diverse industries, including finance, insurance, healthcare, pharmaceuticals, technology, engineering, transportation, hospitality, entertainment, legal, government, and military sectors.​

Higher Education Statistics Agency Logo

Higher Education Statistics Agency

Microsoft Logo

Microsoft

Bistech Logo

Bistech

Alignment Healthcare Logo

Alignment Healthcare

Teleplan Logo

Teleplan

Flowmaster (a Mentor Graphics Company) Logo

Flowmaster (a Mentor Graphics Company)

Schlumberger Logo

Schlumberger

ProgramUtvikling Logo

ProgramUtvikling

Philips Logo

Philips

Big Data for Humans Logo

Big Data for Humans

Kongsberg Maritime Logo

Kongsberg Maritime

CR2

DFDS Logo

DFDS

Workday Logo

Workday

Slicedbread Logo

Slicedbread

Freadom Logo

Freadom

Healthgrades Logo

Healthgrades

ALS Life Sciences Logo

ALS Life Sciences

Department of Work and Pensions (UK) Logo

Department of Work and Pensions (UK)

Washington Department of Transport Logo

Washington Department of Transport

Ghana Police Service Logo

Ghana Police Service

Washington Department of Enterprise Services Logo

Washington Department of Enterprise Services

New Hampshire Supreme Court Logo

New Hampshire Supreme Court

Royal Air Force Logo

Royal Air Force

Ericson Logo

Ericson

YearUp.org Logo

YearUp.org

Jack Links Logo

Jack Links

MacDonald Humfrey (Automation) Ltd. Logo

MacDonald Humfrey (Automation) Ltd.

Xceptor - Process and Data Automation Logo

Xceptor - Process and Data Automation

Higher Education Statistics Agency Logo

Higher Education Statistics Agency