Welcome to MSDN Blogs Sign in | Join | Help

Getting Changeset objects from associated work items

On internal mailing list, someone asked how to do this, and I thought it's worth sharing.  You can get a Changeset object using its artifact URI (aka link) via VersionControlServer.ArtifactProvider.  Here’s how that would look like, based on modifying code from James Manning’s blog posthttp://blogs.msdn.com/jmanning/archive/2005/09/21/472524.aspx.  Added/changed lines are hightlighted.

using System;
using System.Collections.Generic;

using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using Microsoft.TeamFoundation;
using Microsoft.TeamFoundation.VersionControl.Client;

class ChangesetsFromWorkItems
{
    static void Main(string[] args)
    {
        if (args.Length < 2)
        {
            Console.Error.Write("Usage: ChangesetsFromWorkItems <server> <workitemid> [workitemid...]");
            Environment.Exit(1);
        }

        TeamFoundationServer server = TeamFoundationServerFactory.GetServer(args[0]);
        WorkItemStore wiStore = (WorkItemStore)server.GetService(typeof(WorkItemStore));
        VersionControlServer vcs = (VersionControlServer) server.GetService(typeof(VersionControlServer));

        int workItemId;
        for (int i = 1; i < args.Length; i++)
        {
            if (!int.TryParse(args[i], out workItemId))
            {
                Console.Error.WriteLine("ignoring unparseable argument {0}", args[i]);
                continue;
            }

            WorkItem workItem = wiStore.GetWorkItem(workItemId);
            List<Changeset> associatedChangesets = new List<Changeset>();
            foreach (Link link in workItem.Links)
            {
                ExternalLink extLink = link as ExternalLink;
                if (extLink != null)
                {
                    ArtifactId artifact = LinkingUtilities.DecodeUri(extLink.LinkedArtifactUri);
                    if (String.Equals(artifact.ArtifactType, "Changeset", StringComparison.Ordinal))
                    {
                        // Convert the artifact URI to Changeset object.
                        associatedChangesets.Add(vcs.ArtifactProvider.GetChangeset(new Uri(extLink.LinkedArtifactUri);
                    }
                }
            }

            // Do something with the changesets.  Changes property is an array, each Change
            // has an Item object, each Item object has a path, download method, etc.
        }
    }
}

Published Saturday, August 12, 2006 12:15 AM by buckh

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Buck Hodges : Links to code samples

Saturday, August 12, 2006 10:53 AM by Buck Hodges : Links to code samples

# Catching up on Team System Blogs

After traveling most of June, and then some in July it&amp;rsquo;s been hard catching back up but almost...
Sunday, August 13, 2006 9:14 PM by MrDave's (David Yack) Blog!

# re: Getting Changeset objects from associated work items

I was tried your snip code above and get this error when I created new WorkItemStore Object.

WorkItemStore wiStore = (WorkItemStore)server.GetService(typeof(WorkItemStore));

Unhandled Exception: Microsoft.TeamFoundation.TeamFoundationServerUnauthorizedException: TF30063: You are not authorized to access server

Do you have any idea what it causes? I'm using TFS 2008

Thursday, July 24, 2008 7:30 PM by Andy Pham

# re: Getting Changeset objects from associated work items

Andy, are you doing this in a web service?  If so, be sure to set WorkItemTrackingCacheRoot in the web.config file.  See http://blogs.msdn.com/narend/archive/2006/07/29/682032.aspx for more info.

Buck

Wednesday, July 30, 2008 10:08 PM by buckh

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker