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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: