private IEnumerable <AzureDevOpsPullRequestCommentThread> CreateDiscussionThreads( IEnumerable <IIssue> issues, string commentSource) { // ReSharper disable once PossibleMultipleEnumeration issues.NotNull(nameof(issues)); this.Log.Verbose("Creating new discussion threads"); var result = new List <AzureDevOpsPullRequestCommentThread>(); // Code flow properties var iterationId = 0; IEnumerable <AzureDevOpsPullRequestIterationChange> changes = null; if (this.azureDevOpsPullRequest.CodeReviewId > 0) { iterationId = this.GetCodeFlowLatestIterationId(); changes = this.GetCodeFlowChanges(iterationId); } // Filter issues not related to a file. if (!this.settings.ReportIssuesNotRelatedToAFile) { issues = issues.Where(x => x.AffectedFileRelativePath != null); } // ReSharper disable once PossibleMultipleEnumeration foreach (var issue in issues) { this.Log.Information( "Creating a discussion comment for the issue at line {0} from {1}", issue.Line, issue.AffectedFileRelativePath); var newThread = new AzureDevOpsPullRequestCommentThread() { Status = AzureDevOpsCommentThreadStatus.Active, }; var discussionComment = new AzureDevOpsComment { CommentType = AzureDevOpsCommentType.System, IsDeleted = false, Content = ContentProvider.GetContent(issue), }; if (!this.AddThreadProperties(newThread, changes, issue, iterationId, commentSource)) { continue; } newThread.Comments = new List <AzureDevOpsComment> { discussionComment }; result.Add(newThread); } return(result); }
/// <summary> /// Converts a <see cref="AzureDevOpsComment"/> from Azure DevOps to a <see cref="IPullRequestDiscussionComment"/> as used in this addin. /// </summary> /// <param name="comment">Azure DevOps comment to convert.</param> /// <returns>Converted comment.</returns> public static IPullRequestDiscussionComment ToPullRequestDiscussionComment(this AzureDevOpsComment comment) { comment.NotNull(nameof(comment)); return(new PullRequestDiscussionComment() { Content = comment.Content, IsDeleted = comment.IsDeleted, }); }
public void Should_Return_Valid_Comment_With_Default_Comment_Type() { // Given, When var comment = new AzureDevOpsComment("Hello", false); // Then comment.ShouldNotBeNull(); comment.Content.ShouldBe("Hello"); comment.IsDeleted.ShouldBeFalse(); comment.CommentType.ShouldBe(default(AzureDevOpsCommentType)); }
public void Should_Return_Empty_Comment() { // Given, When var comment = new AzureDevOpsComment(); // Then comment.ShouldNotBeNull(); comment.Content.ShouldBe(default(string)); comment.IsDeleted.ShouldBe(default(bool)); comment.CommentType.ShouldBe(default(AzureDevOpsCommentType)); }
public void Should_Throw_If_Comment_Is_Null() { // Given AzureDevOpsComment comment = null; // When var result = Record.Exception(() => comment.ToPullRequestDiscussionComment()); // Then result.IsArgumentNullException("comment"); }
public void Should_Return_Valid_Comment_Via_Initializers() { // Given, When var comment = new AzureDevOpsComment { Content = "All good", IsDeleted = false, CommentType = AzureDevOpsCommentType.CodeChange }; // Then comment.ShouldNotBeNull(); comment.Content.ShouldBe("All good"); comment.IsDeleted.ShouldBeFalse(); comment.CommentType.ShouldBe(AzureDevOpsCommentType.CodeChange); }
public void Should_Set_Correct_IsDeleted(bool isDeleted) { // Given var comment = new AzureDevOpsComment { IsDeleted = isDeleted, }; // When var result = comment.ToPullRequestDiscussionComment(); // Then result.IsDeleted.ShouldBe(isDeleted); }
public void Should_Set_Correct_Content() { // Given var content = "foo"; var comment = new AzureDevOpsComment { Content = content, }; // When var result = comment.ToPullRequestDiscussionComment(); // Then result.Content.ShouldBe(content); }
public void Should_Return_Valid_Comment_Threads() { // Given var fixture = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsUrl, 44); var pullRequest = new AzureDevOpsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory); // When var threads = pullRequest.GetCommentThreads(); // Then threads.ShouldNotBeNull(); threads.ShouldNotBeEmpty(); threads.Count().ShouldBe(2); AzureDevOpsPullRequestCommentThread thread1 = threads.First(); thread1.Id.ShouldBe(11); thread1.Status.ShouldBe(AzureDevOpsCommentThreadStatus.Active); thread1.FilePath.ShouldNotBeNull(); thread1.FilePath.FullPath.ShouldBe("some/path/to/file.cs"); thread1.Comments.ShouldNotBeNull(); thread1.Comments.ShouldNotBeEmpty(); thread1.Comments.Count().ShouldBe(2); AzureDevOpsComment comment11 = thread1.Comments.First(); comment11.ShouldNotBeNull(); comment11.Content.ShouldBe("Hello"); comment11.IsDeleted.ShouldBe(false); comment11.CommentType.ShouldBe(AzureDevOpsCommentType.CodeChange); AzureDevOpsComment comment12 = thread1.Comments.Last(); comment12.ShouldNotBeNull(); comment12.Content.ShouldBe("Goodbye"); comment12.IsDeleted.ShouldBe(true); comment12.CommentType.ShouldBe(AzureDevOpsCommentType.Text); AzureDevOpsPullRequestCommentThread thread2 = threads.Last(); thread2.Id.ShouldBe(22); thread2.Status.ShouldBe(AzureDevOpsCommentThreadStatus.Fixed); thread2.FilePath.ShouldBeNull(); thread2.Comments.ShouldNotBeNull(); thread2.Comments.ShouldBeEmpty(); }