public async Task <TfsChangeset[]> GetItemChangesets(string path) { if (string.IsNullOrWhiteSpace(path)) { throw new ArgumentOutOfRangeException(nameof(path)); } var criteria = new TfvcChangesetSearchCriteria { ItemPath = path }; var changesets = await _versionControlClient.GetChangesetsAsync(string.Empty, searchCriteria : criteria); return(changesets.Select(Mapper.Map <TfsChangeset>).ToArray()); }
public async Task GetTopChangedFiles() { //Criteria used to limit results var maxChangesToConsider = 1000; var maxResults = 10; var fromDate = DateTime.Now.AddDays(-182); var toDate = DateTime.Now; var maxResultsPerPath = 100; var fileExtensionToInclude = new List<string> { ".cs", ".js" }; var extensionExclusions = new List<string> { ".csproj", ".json", ".css" }; var fileExclusions = new List<string> { "AssemblyInfo.cs", "jquery-1.12.3.min.js", "config.js" }; //var pathExclusions = new List<string> { // "/subdirToForceExclude1/", // "/subdirToForceExclude2/", // "/subdirToForceExclude3/", //}; using (var collection = new TfsTeamProjectCollection(new Uri(tfsConfig.TfsUrl), new NetworkCredential(userName: tfsConfig.UserName, password: tfsConfig.Password , domain: tfsConfig.Domain ))) { collection.EnsureAuthenticated(); //Set up date-range criteria for query var criteria = new TfvcChangesetSearchCriteria { FromDate = fromDate.ToShortDateString(), ToDate = toDate.ToShortDateString(), //FromId = 48503, //ToId = 66416, //IncludeLinks = true, //ItemPath = @"$/GSP6.1/Dev/" ItemPath = @"$/GSP6/Dev/" }; var tfvc = collection.GetService(typeof(VersionControlServer)) as VersionControlServer; //Get changesets //Note: maxcount set to maxvalue since impact to server is minimized by linq query below var changeSets = tfvc.QueryHistory(path: criteria.ItemPath, version: VersionSpec.Latest, deletionId: 0, recursion: RecursionType.Full, user: null, versionFrom: new DateVersionSpec(fromDate), versionTo: new DateVersionSpec(toDate), maxCount: int.MaxValue, includeChanges: true, includeDownloadInfo: false, slotMode: true) as IEnumerable<Changeset>; Console.WriteLine("from{0} to {1} changeset count{2} from id:{3}to id:{4}", fromDate.ToShortDateString(), toDate.ToShortDateString(), changeSets.Count(), changeSets.First().ChangesetId, changeSets.Last().ChangesetId); //Filter changes contained in changesets var changes = changeSets.SelectMany(a => a.Changes) .Where(a => a.ChangeType != ChangeType.Lock || a.ChangeType != ChangeType.Delete || a.ChangeType != ChangeType.Property) //.Where(e => !e.Item.ServerItem.ContainsAny(pathExclusionspathExclusions)) .Where(e => e.Item.ServerItem.LastIndexOf('.') >= 0) .Where(e => !e.Item.ServerItem.Substring(e.Item.ServerItem.LastIndexOf('/') + 1).ContainsAny(fileExclusions)) .Where(e => !e.Item.ServerItem.Substring(e.Item.ServerItem.LastIndexOf('.')).ContainsAny(extensionExclusions)) .Where(e => e.Item.ServerItem.Substring(e.Item.ServerItem.LastIndexOf('.')).ContainsAny(fileExtensionToInclude)) .GroupBy(g => g.Item.ServerItem) .Select(d => new { File = d.Key, Count = d.Count() }) .OrderByDescending(o => o.Count) .Take(maxResultsPerPath) ; //Write top items for each path to the console Console.WriteLine(criteria.ItemPath); Console.WriteLine("->"); foreach (var change in changes) { Console.WriteLine("ChangeCount: {0} : File: {1}", change.Count, change.File); } Console.WriteLine(Environment.NewLine); } }
public async Task GetTopChangedFiles() { //Criteria used to limit results var maxChangesToConsider = 1000; var maxResults = 10; var fromDate = DateTime.Now.AddDays(-10); var toDate = DateTime.Now; var maxResultsPerPath = 100; var fileExtensionToInclude = new List <string> { ".cs", ".js" }; var extensionExclusions = new List <string> { ".csproj", ".json", ".css" }; var fileExclusions = new List <string> { "AssemblyInfo.cs", "jquery-1.12.3.min.js", "config.js" }; //var pathExclusions = new List<string> { // "/subdirToForceExclude1/", // "/subdirToForceExclude2/", // "/subdirToForceExclude3/", //}; using (var collection = new TfsTeamProjectCollection(new Uri(tfsConfig.TfsUrl), new NetworkCredential(userName: tfsConfig.UserName, password: tfsConfig.Password , domain: tfsConfig.Domain ))) { collection.EnsureAuthenticated(); //Set up date-range criteria for query var criteria = new TfvcChangesetSearchCriteria { FromDate = fromDate.ToShortDateString(), ToDate = toDate.ToShortDateString(), //FromId = 48503, //ToId = 66416, //IncludeLinks = true, //ItemPath = @"$/GSP6.1/Dev/" ItemPath = @"$/GSP6/Dev/" }; var tfvc = collection.GetService(typeof(VersionControlServer)) as VersionControlServer; //Get changesets //Note: maxcount set to maxvalue since impact to server is minimized by linq query below var changeSets = tfvc.QueryHistory(path: criteria.ItemPath, version: VersionSpec.Latest, deletionId: 0, recursion: RecursionType.Full, user: null, versionFrom: new DateVersionSpec(fromDate), versionTo: new DateVersionSpec(toDate), maxCount: int.MaxValue, includeChanges: true, includeDownloadInfo: false, slotMode: true) as IEnumerable <Changeset>; Console.WriteLine("from{0} to {1} changeset count{2} from id:{3}to id:{4}", fromDate.ToShortDateString(), toDate.ToShortDateString(), changeSets.Count(), changeSets.First().ChangesetId, changeSets.Last().ChangesetId); //Filter changes contained in changesets var changes = changeSets.SelectMany(a => a.Changes) .Where(a => a.ChangeType != ChangeType.Lock || a.ChangeType != ChangeType.Delete || a.ChangeType != ChangeType.Property) //.Where(e => !e.Item.ServerItem.ContainsAny(pathExclusionspathExclusions)) .Where(e => e.Item.ServerItem.LastIndexOf('.') >= 0) .Where(e => !e.Item.ServerItem.Substring(e.Item.ServerItem.LastIndexOf('/') + 1).ContainsAny(fileExclusions)) .Where(e => !e.Item.ServerItem.Substring(e.Item.ServerItem.LastIndexOf('.')).ContainsAny(extensionExclusions)) .Where(e => e.Item.ServerItem.Substring(e.Item.ServerItem.LastIndexOf('.')).ContainsAny(fileExtensionToInclude)) .GroupBy(g => g.Item.ServerItem) .Select(d => new { File = d.Key, Count = d.Count() }) .OrderByDescending(o => o.Count) .Take(maxResultsPerPath) ; //Write top items for each path to the console Console.WriteLine(criteria.ItemPath); Console.WriteLine("->"); foreach (var change in changes) { Console.WriteLine("ChangeCount: {0} : File: {1}", change.Count, change.File); } Console.WriteLine(Environment.NewLine); } }