Blog by Ben Clark-Robinson

Technology

Twitter LinkedIn GitHub Download FreqPress

07 Jul 2014
TFS API - Track changeset merge in Branches

This is a quick and easy way to identify what TFS paths a changeset has been merged into. Simply pass in the changeset ID, source path (like: $/project/dev) and a list of branches to check (like: $/project/release/release-1.0).

// Track a changeset merged into a possible list of branches.
public ExtendedMerge[] TrackChangesetIn(int changesetId, string projectPath, IEnumerable branches)
{
  var projectCollection = _tfsServer.Connection(); // Get your connection to TFS
  if (projectCollection.HasAuthenticated == false)
    projectCollection.Authenticate();

  // Get the Changeset list from the TFS API.
  var source = projectCollection.GetService();

  var merges = source.TrackMerges(new int[] { changesetId },
    new ItemIdentifier(projectPath),
    branches.Select(b => new ItemIdentifier(b)).ToArray(),
    null);

  return merges;
}

You can use this method like this:

var mergeBranch = TrackChangesetIn(id, "$/project/dev", new List { "B1", "B2" });
if (mergeBranch.Any())
{
  var targetItems = mergeBranch.Select(mb => mb.TargetItem.Item);
}

Til next time,
Ben at 10:26

scribble

Twitter LinkedIn GitHub Download FreqPress