Reputation: 825
I need to produce a list of Work Items from a production build, which is triggered by a merge. I use the below to get a list of changes, after pulling the Changeset Id from the build I care about
Uri tfsUri = new Uri("http://leecrp-tfs1:8080/tfs");
TfsTeamProjectCollection tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(tfsUri);
VersionControlServer vcs = tfs.GetService<VersionControlServer>();
List<String> changedThings = new List<String>();
Build bld = _builds.Where(x => x.BuildNumber == buildNumber).First();
if(bld != null)
{
int.TryParse(bld.SourceVersion, out int csId);
if (csId > 0)
{
Changeset changeset = vcs.GetChangeset(csId);
foreach(Microsoft.TeamFoundation.VersionControl.Client.Change change in changeset.Changes)
{
changedThings.Add(change.Item.ServerItem);
}
}
}
if(changedThings != null && changedThings.Count > 0)
{
lbChanges.DataSource = changedThings;
}
However, there does not appear to be anything in the object about the source of each check-in. As stated, I primarily need the Work Items so I can link back to our JIRA tickets later.
I have tried the following, but it returns nothing
IEnumerable<ExtendedMerge> mergeDetails = vcs.QueryMergesExtended(new ItemSpec(@"$/Project/Branch", RecursionType.Full), VersionSpec.Latest, VersionSpec.ParseSingleSpec(csId.ToString(), null), VersionSpec.ParseSingleSpec(csId.ToString(), null));
Upvotes: 0
Views: 105
Reputation: 825
As it turns out, I just had to slightly modify an earlier attempt. The below gets me the merge details
VersionSpec versionSpec = VersionSpec.ParseSingleSpec(csId.ToString(), null);
ChangesetMergeDetails results = vcs.QueryMergesWithDetails(@"$/Project/SourceBranch", VersionSpec.Latest, 0, @"$/Project/TargetBranch", VersionSpec.Latest, 0, versionSpec, versionSpec, RecursionType.Full);
From there I use an excessive amount of foreach
loops to get what I want:
foreach(Changeset thing in results.Changesets)
{
foreach(WorkItem workItem in thing.WorkItems.Distinct())
{
changedItems.Add(workItem.Id.ToString());
foreach (Revision revision in workItem.Revisions)
{
foreach (Field field in workItem.Fields)
{
if(field.Name == "History")
{
string thingICareAbout = revision.Fields[field.Name].Value.ToString();
if (thingICareAbout.Contains("TFS4JIRA"))
{
wiHistory.Add(ParseJIRT(thingICareAbout));
}
}
}
}
}
}
Upvotes: 1