Last active
August 29, 2015 14:07
-
-
Save mika76/d2b6defbf20d7cfc7800 to your computer and use it in GitHub Desktop.
TFS Changeset list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Easiest in Linqpad | |
// Add References: | |
//Microsoft.TeamFoundation.Client | |
//Microsoft.TeamFoundation.Common | |
//Microsoft.TeamFoundation.VersionControl.Client | |
//Microsoft.TeamFoundation.WorkItemTracking.Client | |
// Merged some stuff from http://pascallaurin42.blogspot.com/2012/07/tfs-queries-generating-changelog-from.html | |
// and http://stackoverflow.com/questions/8429040/tfs-2010-how-to-produce-a-changelog-ie-list-of-work-items-between-two-releas | |
var tfsServer = new Uri("http://server:8080/tfs"); | |
var branch = "$/System/Main"; | |
var fromVersion = new ChangesetVersionSpec(4372); | |
var toVersion = VersionSpec.Latest; | |
//---------------------- | |
var tfs = TfsTeamProjectCollectionFactory | |
.GetTeamProjectCollection(tfsServer); | |
tfs.EnsureAuthenticated(); | |
var versionControl = tfs.GetService<VersionControlServer>(); | |
var history = versionControl.QueryHistory(branch, VersionSpec.Latest, 0, | |
RecursionType.Full, null, fromVersion, toVersion, int.MaxValue, false, | |
false, false); | |
// Merged items | |
var mergedHistory = versionControl.GetItems(branch, RecursionType.Full).Items | |
.Select(x => versionControl.QueryMergesWithDetails( | |
null, | |
null, | |
0, | |
x.ServerItem, | |
VersionSpec.Latest, | |
0, | |
fromVersion, | |
toVersion, | |
RecursionType.Full | |
)) | |
.SelectMany(x => x.Changesets); | |
var union = history.OfType<Changeset>().Union(mergedHistory); | |
// changesets | |
union | |
.Select(x => new | |
{ | |
x.ChangesetId, | |
x.CreationDate, | |
x.Committer, | |
x.Comment, | |
WorkItems = x.WorkItems.Select(wi => new | |
{ | |
wi.Id, | |
wi.Title, | |
wi.Description, | |
wi.State, | |
wi.Reason | |
}) | |
}) | |
.Dump("Branch history of: " + branch + | |
" from " + fromVersion.DisplayString + " to " + toVersion.DisplayString); | |
// workitems | |
union | |
//.OrderBy(x => x.ChangesetId) | |
.SelectMany(x => x.WorkItems) | |
.OrderBy(x => x.Id) | |
.Select(wi => string.Format("[{0}] {1} #{2} - {3}\r\n{4}", | |
wi.Reason, wi.Type.Name, wi.Id, wi.Title, wi.Description)) | |
.GroupBy(x => x) | |
.Select(g => g.First()) | |
.Dump("Changelog of branch: " + branch + | |
" from " + fromVersion.DisplayString + " to " + toVersion.DisplayString); |
Hey, sorry didn't see your comment till now.
I found showing branch and merge history very hard as well. I think it also depends on what exactly you would like to show. Here I was wanting only work items linked to changesets, and I get those through merge history as well.
I'm using a different chunk of code and I'm having trouble at this point: tfs.EnsureAuthenticated();
I get the error below.
TeamFoundationServiceUnavailableException: TF31002: Unable to connect to this Team Foundation Server: http://optimus:8080/tfs.
Team Foundation Server Url: http://optimus:8080/tfs.
Possible reasons for failure include:
- The name, port number, or protocol for the Team Foundation Server is incorrect.
- The Team Foundation Server is offline.
- The password has expired or is incorrect.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great !.
What's about Branches and Merges?
I have create Branch
I can get Changeset list
I can do Checkout and Checkin about files in Branch, and then do Merges.
I can use GetBranchHistory and QueryPendingSets.
I'm confused how get good infor about branches history , merges history (maybe QueryMergesWithDetails), and differences with QueryPendingSets.