public static List <CodeReviewComment> CountComments(int workItemid, IConfigurationRoot configuration) { Uri uri = new Uri(configuration["TfsApiUriTFS"]); TeamFoundationDiscussionService service = new TeamFoundationDiscussionService(); service.Initialize(new Microsoft.TeamFoundation.Client.TfsTeamProjectCollection(uri)); IDiscussionManager discussionManager = service.CreateDiscussionManager(); IAsyncResult result = discussionManager.BeginQueryByCodeReviewRequest(workItemid, QueryStoreOptions.ServerAndLocal, new AsyncCallback(CallCompletedCallback), null); var output = discussionManager.EndQueryByCodeReviewRequest(result); List <CodeReviewComment> comments = new List <CodeReviewComment>(); foreach (DiscussionThread thread in output) { if (thread.ItemPath != "") { CodeReviewComment comment = new CodeReviewComment(); comment.Author = thread.RootComment.Author.DisplayName; comment.AuthorUniqueName = thread.RootComment.Author.UniqueName; comment.Comment = thread.RootComment.Content; comment.PublishDate = thread.RootComment.PublishedDate.ToString("G"); comment.ItemName = thread.ItemPath; comments.Add(comment); } } return(comments); }
private static List <CodeReviewComment> GetCodeReviewComments(int workItemId) { List <CodeReviewComment> comments = new List <CodeReviewComment>(); Uri uri = new Uri(URL_TO_TFS_COLLECTION); TeamFoundationDiscussionService service = new TeamFoundationDiscussionService(); service.Initialize(new Microsoft.TeamFoundation.Client.TfsTeamProjectCollection(uri)); IDiscussionManager discussionManager = service.CreateDiscussionManager(); IAsyncResult result = discussionManager.BeginQueryByCodeReviewRequest(workItemId, QueryStoreOptions.ServerAndLocal, new AsyncCallback(CallCompletedCallback), null); var output = discussionManager.EndQueryByCodeReviewRequest(result); foreach (DiscussionThread thread in output) { if (thread.RootComment != null) { CodeReviewComment comment = new CodeReviewComment(); comment.Author = thread.RootComment.Author.DisplayName; comment.Comment = thread.RootComment.Content.Replace(",", " COMMA ").Replace(System.Environment.NewLine, " NEWLINE "); comment.PublishDate = thread.RootComment.PublishedDate.ToShortDateString(); comment.ItemName = thread.ItemPath; comments.Add(comment); } } return(comments); }
public List <CodeReviewComment> CountComments(string workItemid) { Uri uri = new Uri("http://tfs.cdbdx.biz:8080/tfs/DefaultCollection/"); TeamFoundationDiscussionService service = new TeamFoundationDiscussionService(); service.Initialize(new Microsoft.TeamFoundation.Client.TfsTeamProjectCollection(uri)); IDiscussionManager discussionManager = service.CreateDiscussionManager(); IAsyncResult result = discussionManager.BeginQueryByCodeReviewRequest(int.Parse(workItemid), QueryStoreOptions.ServerAndLocal, new AsyncCallback(CallCompletedCallback), null); result.AsyncWaitHandle.WaitOne(); var output = discussionManager.EndQueryByCodeReviewRequest(result); List <CodeReviewComment> comments = new List <CodeReviewComment>(); foreach (DiscussionThread thread in output) { if (thread.ItemPath != "") { CodeReviewComment comment = new CodeReviewComment(); comment.Author = thread.RootComment.Author.DisplayName; comment.AuthorUniqueName = thread.RootComment.Author.UniqueName; comment.ReplyComments = new List <CodeReviewComment>(); foreach (Comment childCom in thread.RootComment.GetChildComments()) { CodeReviewComment tmp = new CodeReviewComment(); tmp.Author = childCom.Author.DisplayName; tmp.AuthorUniqueName = childCom.Author.UniqueName; tmp.Comment = childCom.Content; tmp.PublishDate = childCom.PublishedDate.ToString("MMMM dd, yyyy hh:mm:ss"); //tmp.PublishDate = String.Format("{0:d/M/yyyy HH:mm:ss}", childCom.PublishedDate); comment.ReplyComments.Add(tmp); } comment.Comment = thread.RootComment.Content; comment.PublishDate = thread.RootComment.PublishedDate.ToString("MMMM dd, yyyy hh:mm:ss"); //comment.PublishDate = String.Format("{0:d/M/yyyy HH:mm:ss}", thread.RootComment.PublishedDate); comment.ItemName = thread.ItemPath; comments.Add(comment); } } return(comments); }
private void buttonSearch_Click(object sender, EventArgs e) { Uri uri = new Uri(TfsUri); TeamFoundationDiscussionService service = new TeamFoundationDiscussionService(); service.Initialize(new TfsTeamProjectCollection(uri)); TfsTeamProjectCollection projectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(uri); WorkItemStore store = projectCollection.GetService <WorkItemStore>(); WorkItemLinkInfo[] list = GetCodeReviewRequests(store); IDiscussionManager discussionManager = service.CreateDiscussionManager(); List <ResponseAnalysis> responseList = new List <ResponseAnalysis>(); List <WorkItemLinkInfo> filteredList = list.Where(p => p.SourceId != 0).ToList(); foreach (WorkItemLinkInfo item in filteredList) { ResponseAnalysis response = new ResponseAnalysis(); WorkItem Widemand = store.GetWorkItem(item.SourceId); WorkItem WiResponse = store.GetWorkItem(item.TargetId); string reviewer = WiResponse.Fields["Accepted By"].Value.ToString(); string date = Widemand.Fields["Created Date"].Value.ToString(); response.WorkiTemId = Widemand.Id; response.CommentNumber = CountComments(Widemand.Id, discussionManager, NormalizeName(reviewer)); response.OwnerName = Widemand.CreatedBy; response.CodeReviewStatus = WiResponse.Fields["Closed Status"].Value.ToString(); response.Direction = GetDirection(Widemand.CreatedBy); response.ReviewerName = reviewer; response.Team = GetTeam(Widemand.CreatedBy); //WorkItemType type = item.Links.WorkItem.Type; responseList.Add(response); } int nbConcernedLines = 0; }
static void Main(string[] args) { string projecturi = "https://xxx:8080/tfs/"; int changesetid = xxx; TfsTeamProjectCollection ttpc = new TfsTeamProjectCollection(new Uri(projecturi)); VersionControlServer vcs = ttpc.GetService <VersionControlServer>(); Changeset cset = vcs.GetChangeset(changesetid); TeamFoundationDiscussionService tfds = new TeamFoundationDiscussionService(); tfds.Initialize(ttpc); IDiscussionManager idm = tfds.CreateDiscussionManager(); IAsyncResult iar = idm.BeginQueryByVersion(cset.ArtifactUri, QueryStoreOptions.ServerOnly, new AsyncCallback(Callback), null); var threads = idm.EndQueryByVersion(iar); foreach (DiscussionThread dt in threads) { Console.WriteLine(dt.RootComment.Content); Console.WriteLine(dt.RootComment.Author.DisplayName); Console.ReadLine(); } }
public static IEnumerable <CodeReviewResponse> RetrieveCodeReviewResponsesByFilter(CodeReviewResponseFilter filter) { var server = new TfsTeamProjectCollection(new Uri(formCodeReviewStats.TeamProjectCollectionUrl), CredentialCache.DefaultNetworkCredentials); var _workItemStore = server.GetService <WorkItemStore>(); TeamFoundationDiscussionService service = new TeamFoundationDiscussionService(); service.Initialize(server); var discussionManager = service.CreateDiscussionManager(); var query = "SELECT * FROM workitems " + "WHERE [System.WorkItemType] = 'Code Review Response' " + "AND [Microsoft.VSTS.CodeReview.ClosedStatusCode] In (1, 2, 3) " + "AND [Microsoft.VSTS.Common.ClosedDate] >= '{0}' " + "AND [Microsoft.VSTS.Common.ClosedDate] <= '{1}' "; query = string.Format(query, filter.StartDate.ToString("MM/dd/yyyy"), filter.EndDate.ToString("MM/dd/yyyy")); if (!string.IsNullOrWhiteSpace(filter.Reviewer)) { query += "AND [Microsoft.VSTS.Common.ReviewedBy] Contains '{0}' "; query = string.Format(query, filter.Reviewer); } var codeReviews = _workItemStore.Query(query).OfType <WorkItem>() .Select(r => new CodeReviewResponse { Id = r.Id, CreatedBy = r.CreatedBy, ReviewedBy = r.Fields.OfType <Field>().First(x => x.ReferenceName == "Microsoft.VSTS.Common.ReviewedBy").Value.ToString(), Title = r.Title, CreatedDate = r.Fields.OfType <Field>().First(x => x.ReferenceName == "System.CreatedDate").Value.ToString(), ClosedDate = r.Fields.OfType <Field>().First(x => x.ReferenceName == "Microsoft.VSTS.Common.ClosedDate").Value.ToString(), ClosedStatus = r.Fields.OfType <Field>().First(x => x.ReferenceName == "Microsoft.VSTS.CodeReview.ClosedStatus").Value.ToString(), CodeReviewRequestId = r.WorkItemLinks.OfType <WorkItemLink>().First().TargetId, CodeReviewComments = RetrieveComments(discussionManager, r.WorkItemLinks.OfType <WorkItemLink>().First().TargetId, r.Fields.OfType <Field>().First(x => x.ReferenceName == "Microsoft.VSTS.Common.ReviewedBy").Value.ToString()) }); return(codeReviews); }
private static List<CodeReviewComment> GetCodeReviewComments(int workItemId) { List<CodeReviewComment> comments = new List<CodeReviewComment>(); Uri uri = new Uri(URL_TO_TFS_COLLECTION); TeamFoundationDiscussionService service = new TeamFoundationDiscussionService(); service.Initialize(new Microsoft.TeamFoundation.Client.TfsTeamProjectCollection(uri)); IDiscussionManager discussionManager = service.CreateDiscussionManager(); IAsyncResult result = discussionManager.BeginQueryByCodeReviewRequest(workItemId, QueryStoreOptions.ServerAndLocal, new AsyncCallback(CallCompletedCallback), null); var output = discussionManager.EndQueryByCodeReviewRequest(result); foreach (DiscussionThread thread in output) { if (thread.RootComment != null) { CodeReviewComment comment = new CodeReviewComment(); comment.Author = thread.RootComment.Author.DisplayName; comment.Comment = thread.RootComment.Content.Replace(",", " COMMA ").Replace(System.Environment.NewLine, " NEWLINE "); comment.PublishDate = thread.RootComment.PublishedDate.ToShortDateString(); comment.ItemName = thread.ItemPath; comments.Add(comment); } } return comments; }