private bool AddThreadProperties( GitPullRequestCommentThread thread, GitPullRequestIterationChanges changes, IIssue issue, int iterationId, string commentSource) { thread.NotNull(nameof(thread)); changes.NotNull(nameof(changes)); issue.NotNull(nameof(issue)); var properties = new PropertiesCollection(); if (issue.AffectedFileRelativePath != null) { if (this.tfsPullRequest.CodeReviewId > 0) { var changeTrackingId = this.TryGetCodeFlowChangeTrackingId(changes, issue.AffectedFileRelativePath); if (changeTrackingId < 0) { // Don't post comment if we couldn't determine the change. return(false); } AddCodeFlowProperties(issue, iterationId, changeTrackingId, properties); } else { throw new NotSupportedException("Legacy code reviews are not supported."); } } // A VSTS UI extension will recognize this and format the comments differently. properties.Add("CodeAnalysisThreadType", "CodeAnalysisIssue"); thread.Properties = properties; // Add a custom property to be able to distinguish all comments created this way. thread.SetCommentSource(commentSource); // Add a custom property to be able to return issue message from existing threads, // without any formatting done by this addin, back to Cake.Issues.PullRequests. thread.SetIssueMessage(issue.Message); return(true); }
private int TryGetCodeFlowChangeTrackingId(GitPullRequestIterationChanges changes, FilePath path) { changes.NotNull(nameof(changes)); path.NotNull(nameof(path)); var change = changes.ChangeEntries.Where(x => x.Item.Path == "/" + path.ToString()).ToList(); if (change.Count == 0) { this.Log.Error( "Cannot post a comment for the file {0} because no changes on the pull request server could be found.", path); return(-1); } if (change.Count > 1) { this.Log.Error( "Cannot post a comment for the file {0} because more than one change has been found on the pull request server:" + Environment.NewLine + "{1}", path, string.Join( Environment.NewLine, change.Select( x => string.Format( CultureInfo.InvariantCulture, " ID: {0}, Path: {1}", x.ChangeId, x.Item.Path)))); return(-1); } var changeTrackingId = change.Single().ChangeTrackingId; this.Log.Verbose( "Determined ChangeTrackingId of {0} for {1}", changeTrackingId, path); return(changeTrackingId); }
private int TryGetCodeFlowChangeTrackingId(GitPullRequestIterationChanges changes, FilePath path) { changes.NotNull(nameof(changes)); path.NotNull(nameof(path)); var change = changes.ChangeEntries.Where(x => x.Item.Path == "/" + path.ToString()).ToList(); if (change.Count != 1) { this.Log.Error( "Cannot post a comment for the file {0} because no changes could be found.", path); return(-1); } var changeTrackingId = change.Single().ChangeTrackingId; this.Log.Verbose( "Determined ChangeTrackingId of {0} for {1}", changeTrackingId, path); return(changeTrackingId); }