diff --git a/lib/Octokit.GraphQL.0.0.2-alpha.nupkg b/lib/Octokit.GraphQL.0.0.2-alpha.nupkg deleted file mode 100644 index 88686b7729..0000000000 Binary files a/lib/Octokit.GraphQL.0.0.2-alpha.nupkg and /dev/null differ diff --git a/lib/Octokit.GraphQL.0.0.3-alpha.nupkg b/lib/Octokit.GraphQL.0.0.3-alpha.nupkg new file mode 100644 index 0000000000..34106964f3 Binary files /dev/null and b/lib/Octokit.GraphQL.0.0.3-alpha.nupkg differ diff --git a/src/GitHub.Api/GitHub.Api.csproj b/src/GitHub.Api/GitHub.Api.csproj index fc35dd136b..cdcc24a696 100644 --- a/src/GitHub.Api/GitHub.Api.csproj +++ b/src/GitHub.Api/GitHub.Api.csproj @@ -50,12 +50,12 @@ ..\..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll True - - ..\..\packages\Octokit.GraphQL.0.0.2-alpha\lib\netstandard1.1\Octokit.GraphQL.dll + + ..\..\packages\Octokit.GraphQL.0.0.3-alpha\lib\netstandard1.1\Octokit.GraphQL.dll True - - ..\..\packages\Octokit.GraphQL.0.0.2-alpha\lib\netstandard1.1\Octokit.GraphQL.Core.dll + + ..\..\packages\Octokit.GraphQL.0.0.3-alpha\lib\netstandard1.1\Octokit.GraphQL.Core.dll True diff --git a/src/GitHub.Api/packages.config b/src/GitHub.Api/packages.config index 6356b0e89c..65e80d2a86 100644 --- a/src/GitHub.Api/packages.config +++ b/src/GitHub.Api/packages.config @@ -1,6 +1,6 @@  - + \ No newline at end of file diff --git a/src/GitHub.App/GitHub.App.csproj b/src/GitHub.App/GitHub.App.csproj index 5a305566ea..17d5ef2731 100644 --- a/src/GitHub.App/GitHub.App.csproj +++ b/src/GitHub.App/GitHub.App.csproj @@ -144,12 +144,12 @@ ..\..\packages\Microsoft.VisualStudio.Utilities.14.3.25407\lib\net45\Microsoft.VisualStudio.Utilities.dll True - - ..\..\packages\Octokit.GraphQL.0.0.2-alpha\lib\netstandard1.1\Octokit.GraphQL.dll + + ..\..\packages\Octokit.GraphQL.0.0.3-alpha\lib\netstandard1.1\Octokit.GraphQL.dll True - - ..\..\packages\Octokit.GraphQL.0.0.2-alpha\lib\netstandard1.1\Octokit.GraphQL.Core.dll + + ..\..\packages\Octokit.GraphQL.0.0.3-alpha\lib\netstandard1.1\Octokit.GraphQL.Core.dll True diff --git a/src/GitHub.App/Models/PullRequestModel.cs b/src/GitHub.App/Models/PullRequestModel.cs index 8e9d6439d7..87e0c6d64a 100644 --- a/src/GitHub.App/Models/PullRequestModel.cs +++ b/src/GitHub.App/Models/PullRequestModel.cs @@ -177,18 +177,6 @@ public IReadOnlyList Reviews } } - IReadOnlyList reviewComments = new IPullRequestReviewCommentModel[0]; - public IReadOnlyList ReviewComments - { - get { return reviewComments; } - set - { - Guard.ArgumentNotNull(value, nameof(value)); - reviewComments = value; - this.RaisePropertyChange(); - } - } - IAccount assignee; public IAccount Assignee { diff --git a/src/GitHub.App/Models/PullRequestReviewModel.cs b/src/GitHub.App/Models/PullRequestReviewModel.cs index aab24ab076..e8503f5563 100644 --- a/src/GitHub.App/Models/PullRequestReviewModel.cs +++ b/src/GitHub.App/Models/PullRequestReviewModel.cs @@ -1,9 +1,13 @@ using System; +using System.Collections.Generic; +using GitHub.Extensions; namespace GitHub.Models { public class PullRequestReviewModel : IPullRequestReviewModel { + IReadOnlyList comments; + public long Id { get; set; } public string NodeId { get; set; } public IAccount User { get; set; } @@ -11,5 +15,15 @@ public class PullRequestReviewModel : IPullRequestReviewModel public PullRequestReviewState State { get; set; } public string CommitId { get; set; } public DateTimeOffset? SubmittedAt { get; set; } + + public IReadOnlyList Comments + { + get { return comments ?? Array.Empty(); } + set + { + Guard.ArgumentNotNull(value, nameof(value)); + comments = value; + } + } } } diff --git a/src/GitHub.App/Services/ModelService.cs b/src/GitHub.App/Services/ModelService.cs index 1928ac8cb8..7e934d65e5 100644 --- a/src/GitHub.App/Services/ModelService.cs +++ b/src/GitHub.App/Services/ModelService.cs @@ -223,21 +223,18 @@ public IObservable GetPullRequest(string owner, string name, ApiClient.GetPullRequestFiles(owner, name, number).ToList(), ApiClient.GetIssueComments(owner, name, number).ToList(), GetPullRequestReviews(owner, name, number).ToObservable(), - GetPullRequestReviewComments(owner, name, number).ToObservable(), - (pr, files, comments, reviews, reviewComments) => new + (pr, files, comments, reviews) => new { PullRequest = pr, Files = files, Comments = comments, Reviews = reviews, - ReviewComments = reviewComments }) .Select(x => PullRequestCacheItem.Create( x.PullRequest, (IReadOnlyList)x.Files, (IReadOnlyList)x.Comments, - (IReadOnlyList)x.Reviews, - (IReadOnlyList)x.ReviewComments)), + (IReadOnlyList)x.Reviews)), TimeSpan.Zero, TimeSpan.FromDays(7)) .Select(Create); @@ -394,150 +391,39 @@ async Task> GetPullRequestReviews(string owner, s string cursor = null; var result = new List(); - while (true) - { - var query = new Query() - .Repository(owner, name) - .PullRequest(number) - .Reviews(first: 30, after: cursor) - .Select(x => new - { - x.PageInfo.HasNextPage, - x.PageInfo.EndCursor, - Items = x.Nodes.Select(y => new PullRequestReviewModel - { - Id = y.DatabaseId.Value, - NodeId = y.Id, - Body = y.Body, - CommitId = y.Commit.Oid, - State = FromGraphQL(y.State), - SubmittedAt = y.SubmittedAt, - User = Create(y.Author.Login, y.Author.AvatarUrl(null)) - }).ToList() - }); - - var page = await graphql.Run(query); - result.AddRange(page.Items); - - if (page.HasNextPage) - cursor = page.EndCursor; - else - return result; - } - } - - async Task> GetPullRequestReviewComments(string owner, string name, int number) - { - var result = new List(); - - // Reads a single page of reviews and for each review the first page of review comments. + // TODO: We're only reading the first 100 reviews and comments here. Add paging. var query = new Query() .Repository(owner, name) .PullRequest(number) - .Reviews(first: 100, after: Var("cursor")) - .Select(x => new + .Reviews(first: 100, after: cursor).Nodes + .Select(review => new PullRequestReviewModel { - x.PageInfo.HasNextPage, - x.PageInfo.EndCursor, - Reviews = x.Nodes.Select(y => new + Id = review.DatabaseId.Value, + NodeId = review.Id.Value, + Body = review.Body, + CommitId = review.Commit.Oid, + State = FromGraphQL(review.State), + SubmittedAt = review.SubmittedAt, + User = Create(review.Author.Login, review.Author.AvatarUrl(null)), + Comments = review.Comments(100, null, null, null).Nodes.Select(comment => new PullRequestReviewCommentModel { - y.Id, - CommentPage = y.Comments(100, null, null, null).Select(z => new - { - z.PageInfo.HasNextPage, - z.PageInfo.EndCursor, - Items = z.Nodes.Select(a => new PullRequestReviewCommentModel - { - Id = a.DatabaseId.Value, - NodeId = a.Id, - Body = a.Body, - CommitId = a.Commit.Oid, - CreatedAt = a.CreatedAt.Value, - DiffHunk = a.DiffHunk, - OriginalCommitId = a.OriginalCommit.Oid, - OriginalPosition = a.OriginalPosition, - Path = a.Path, - Position = a.Position, - PullRequestReviewId = y.DatabaseId.Value, - User = Create(a.Author.Login, a.Author.AvatarUrl(null)), - IsPending = y.State == Octokit.GraphQL.Model.PullRequestReviewState.Pending, - }).ToList(), - }).Single() - }).ToList() - }).Compile(); - - var vars = new Dictionary - { - { "cursor", null } - }; - - // Read all pages of reviews. - while (true) - { - var reviewPage = await graphql.Run(query, vars); - - foreach (var review in reviewPage.Reviews) - { - result.AddRange(review.CommentPage.Items); - - // The the review has >1 page of review comments, read the remaining pages. - if (review.CommentPage.HasNextPage) - { - result.AddRange(await GetPullRequestReviewComments(review.Id, review.CommentPage.EndCursor)); - } - } - - if (reviewPage.HasNextPage) - vars["cursor"] = reviewPage.EndCursor; - else - return result; - } - } - - private async Task> GetPullRequestReviewComments(string reviewId, string commentCursor) - { - var result = new List(); - var query = new Query() - .Node(reviewId) - .Cast() - .Select(x => new - { - CommentPage = x.Comments(100, Var("cursor"), null, null).Select(z => new - { - z.PageInfo.HasNextPage, - z.PageInfo.EndCursor, - Items = z.Nodes.Select(a => new PullRequestReviewCommentModel - { - Id = a.DatabaseId.Value, - NodeId = a.Id, - Body = a.Body, - CommitId = a.Commit.Oid, - CreatedAt = a.CreatedAt.Value, - DiffHunk = a.DiffHunk, - OriginalCommitId = a.OriginalCommit.Oid, - OriginalPosition = a.OriginalPosition, - Path = a.Path, - Position = a.Position, - PullRequestReviewId = x.DatabaseId.Value, - User = Create(a.Author.Login, a.Author.AvatarUrl(null)), - }).ToList(), - }).Single() - }).Compile(); - var vars = new Dictionary - { - { "cursor", commentCursor } - }; - - while (true) - { - var page = await graphql.Run(query, vars); - result.AddRange(page.CommentPage.Items); + Id = comment.DatabaseId.Value, + NodeId = comment.Id.Value, + Body = comment.Body, + CommitId = comment.Commit.Oid, + CreatedAt = comment.CreatedAt, + DiffHunk = comment.DiffHunk, + OriginalCommitId = comment.OriginalCommit.Oid, + OriginalPosition = comment.OriginalPosition, + Path = comment.Path, + Position = comment.Position, + PullRequestReviewId = review.DatabaseId.Value, + User = Create(comment.Author.Login, comment.Author.AvatarUrl(null)), + IsPending = review.State == Octokit.GraphQL.Model.PullRequestReviewState.Pending, + }).ToList(), + }); - if (page.CommentPage.HasNextPage) - vars["cursor"] = page.CommentPage.EndCursor; - else - return result; - } + return (await graphql.Run(query)).ToList(); } #pragma warning restore CS0618 // Type or member is obsolete @@ -638,23 +524,23 @@ IPullRequestModel Create(PullRequestCacheItem prCacheItem) State = x.State, CommitId = x.CommitId, SubmittedAt = x.SubmittedAt, - }).ToList(), - ReviewComments = prCacheItem.ReviewComments.Select(x => - (IPullRequestReviewCommentModel)new PullRequestReviewCommentModel - { - Id = x.Id, - NodeId = x.NodeId, - PullRequestReviewId = x.PullRequestReviewId, - Path = x.Path, - Position = x.Position, - OriginalPosition = x.OriginalPosition, - CommitId = x.CommitId, - OriginalCommitId = x.OriginalCommitId, - DiffHunk = x.DiffHunk, - User = Create(x.User), - Body = x.Body, - CreatedAt = x.CreatedAt, - IsPending = x.IsPending, + Comments = x.Comments.Select(y => + (IPullRequestReviewCommentModel)new PullRequestReviewCommentModel + { + Id = y.Id, + NodeId = y.NodeId, + PullRequestReviewId = y.PullRequestReviewId, + Path = y.Path, + Position = y.Position, + OriginalPosition = y.OriginalPosition, + CommitId = y.CommitId, + OriginalCommitId = y.OriginalCommitId, + DiffHunk = y.DiffHunk, + User = Create(y.User), + Body = y.Body, + CreatedAt = y.CreatedAt, + IsPending = y.IsPending, + }).ToList(), }).ToList(), CommentCount = prCacheItem.CommentCount, CommitCount = prCacheItem.CommitCount, @@ -750,24 +636,22 @@ public static PullRequestCacheItem Create(PullRequest pr) pr, new PullRequestFile[0], new IssueComment[0], - new IPullRequestReviewModel[0], - new IPullRequestReviewCommentModel[0]); + new IPullRequestReviewModel[0]); } public static PullRequestCacheItem Create( PullRequest pr, IReadOnlyList files, IReadOnlyList comments, - IReadOnlyList reviews, - IReadOnlyList reviewComments) + IReadOnlyList reviews) { - return new PullRequestCacheItem(pr, files, comments, reviews, reviewComments); + return new PullRequestCacheItem(pr, files, comments, reviews); } public PullRequestCacheItem() {} public PullRequestCacheItem(PullRequest pr) - : this(pr, new PullRequestFile[0], new IssueComment[0], new IPullRequestReviewModel[0], new IPullRequestReviewCommentModel[0]) + : this(pr, new PullRequestFile[0], new IssueComment[0], new IPullRequestReviewModel[0]) { } @@ -775,8 +659,7 @@ public PullRequestCacheItem( PullRequest pr, IReadOnlyList files, IReadOnlyList comments, - IReadOnlyList reviews, - IReadOnlyList reviewComments) + IReadOnlyList reviews) { Title = pr.Title; Number = pr.Number; @@ -804,7 +687,6 @@ public PullRequestCacheItem( ChangedFiles = files.Select(x => new PullRequestFileCacheItem(x)).ToList(); Comments = comments.Select(x => new IssueCommentCacheItem(x)).ToList(); Reviews = reviews.Select(x => new PullRequestReviewCacheItem(x)).ToList(); - ReviewComments = reviewComments.Select(x => new PullRequestReviewCommentCacheItem(x)).ToList(); State = GetState(pr); IsOpen = pr.State == ItemState.Open; Merged = pr.Merged; @@ -826,8 +708,7 @@ public PullRequestCacheItem( public IList ChangedFiles { get; set; } = new PullRequestFileCacheItem[0]; public IList Comments { get; set; } = new IssueCommentCacheItem[0]; public IList Reviews { get; set; } = new PullRequestReviewCacheItem[0]; - public IList ReviewComments { get; set; } = new PullRequestReviewCommentCacheItem[0]; - + // Nullable for compatibility with old caches. public PullRequestStateEnum? State { get; set; } @@ -908,6 +789,7 @@ public PullRequestReviewCacheItem(IPullRequestReviewModel review) Body = review.Body; State = review.State; SubmittedAt = review.SubmittedAt; + Comments = review.Comments.Select(x => new PullRequestReviewCommentCacheItem(x)).ToList(); } public long Id { get; set; } @@ -917,6 +799,7 @@ public PullRequestReviewCacheItem(IPullRequestReviewModel review) public GitHub.Models.PullRequestReviewState State { get; set; } public string CommitId { get; set; } public DateTimeOffset? SubmittedAt { get; set; } + public IList Comments { get; set; } = new PullRequestReviewCommentCacheItem[0]; } public class PullRequestReviewCommentCacheItem diff --git a/src/GitHub.App/ViewModels/GitHubPane/PullRequestDetailViewModel.cs b/src/GitHub.App/ViewModels/GitHubPane/PullRequestDetailViewModel.cs index ac9a41980c..d3802f6a5b 100644 --- a/src/GitHub.App/ViewModels/GitHubPane/PullRequestDetailViewModel.cs +++ b/src/GitHub.App/ViewModels/GitHubPane/PullRequestDetailViewModel.cs @@ -373,7 +373,7 @@ public async Task Load(IPullRequestModel pullRequest) IsFromFork = !pullRequestsService.IsPullRequestFromRepository(LocalRepository, Model); SourceBranchDisplayName = GetBranchDisplayName(IsFromFork, pullRequest.Head?.Label); TargetBranchDisplayName = GetBranchDisplayName(IsFromFork, pullRequest.Base?.Label); - CommentCount = pullRequest.Comments.Count + pullRequest.ReviewComments.Count; + CommentCount = pullRequest.Comments.Count + pullRequest.Reviews.Sum(x => x.Comments.Count); Body = !string.IsNullOrWhiteSpace(pullRequest.Body) ? pullRequest.Body : Resources.NoDescriptionProvidedMarkdown; Reviews = PullRequestReviewSummaryViewModel.BuildByUser(Session.User, pullRequest).ToList(); diff --git a/src/GitHub.App/ViewModels/GitHubPane/PullRequestReviewSummaryViewModel.cs b/src/GitHub.App/ViewModels/GitHubPane/PullRequestReviewSummaryViewModel.cs index b321b35bbe..18abd8f96f 100644 --- a/src/GitHub.App/ViewModels/GitHubPane/PullRequestReviewSummaryViewModel.cs +++ b/src/GitHub.App/ViewModels/GitHubPane/PullRequestReviewSummaryViewModel.cs @@ -54,15 +54,12 @@ public static IEnumerable BuildByUser( if (reviewPriority >= previousPriority) { - var count = pullRequest.ReviewComments - .Where(x => x.PullRequestReviewId == review.Id) - .Count(); existing[review.User.Login] = new PullRequestReviewSummaryViewModel { Id = review.Id, User = review.User, State = review.State, - FileCommentCount = count + FileCommentCount = review.Comments.Count, }; } } diff --git a/src/GitHub.App/ViewModels/GitHubPane/PullRequestReviewViewModel.cs b/src/GitHub.App/ViewModels/GitHubPane/PullRequestReviewViewModel.cs index f84e2a9d8e..603bcac3f7 100644 --- a/src/GitHub.App/ViewModels/GitHubPane/PullRequestReviewViewModel.cs +++ b/src/GitHub.App/ViewModels/GitHubPane/PullRequestReviewViewModel.cs @@ -21,12 +21,10 @@ public class PullRequestReviewViewModel : ViewModelBase, IPullRequestReviewViewM /// /// The pull request editor service. /// The pull request session. - /// The pull request model. /// The pull request review model. public PullRequestReviewViewModel( IPullRequestEditorService editorService, IPullRequestSession session, - IPullRequestModel pullRequest, IPullRequestReviewModel model) { Guard.ArgumentNotNull(editorService, nameof(editorService)); @@ -40,20 +38,17 @@ public PullRequestReviewViewModel( var comments = new List(); var outdated = new List(); - foreach (var comment in pullRequest.ReviewComments) + foreach (var comment in model.Comments) { - if (comment.PullRequestReviewId == model.Id) - { - var vm = new PullRequestReviewFileCommentViewModel( - editorService, - session, - comment); - - if (comment.Position.HasValue) - comments.Add(vm); - else - outdated.Add(vm); - } + var vm = new PullRequestReviewFileCommentViewModel( + editorService, + session, + comment); + + if (comment.Position.HasValue) + comments.Add(vm); + else + outdated.Add(vm); } FileComments = comments; diff --git a/src/GitHub.App/ViewModels/GitHubPane/PullRequestUserReviewsViewModel.cs b/src/GitHub.App/ViewModels/GitHubPane/PullRequestUserReviewsViewModel.cs index 9bcb3b7905..f488ea68ba 100644 --- a/src/GitHub.App/ViewModels/GitHubPane/PullRequestUserReviewsViewModel.cs +++ b/src/GitHub.App/ViewModels/GitHubPane/PullRequestUserReviewsViewModel.cs @@ -157,7 +157,7 @@ async Task Load(IAccount author, IPullRequestModel pullRequest) if (review.User.Login == author.Login && review.State != PullRequestReviewState.Pending) { - var vm = new PullRequestReviewViewModel(editorService, session, pullRequest, review); + var vm = new PullRequestReviewViewModel(editorService, session, review); vm.IsExpanded = isFirst; reviews.Add(vm); isFirst = false; diff --git a/src/GitHub.App/packages.config b/src/GitHub.App/packages.config index aadd56f421..03d2e311f9 100644 --- a/src/GitHub.App/packages.config +++ b/src/GitHub.App/packages.config @@ -21,7 +21,7 @@ - + diff --git a/src/GitHub.Exports/Models/IPullRequestModel.cs b/src/GitHub.Exports/Models/IPullRequestModel.cs index 40996c78dc..e1c1729af5 100644 --- a/src/GitHub.Exports/Models/IPullRequestModel.cs +++ b/src/GitHub.Exports/Models/IPullRequestModel.cs @@ -34,6 +34,5 @@ public interface IPullRequestModel : ICopyable, IReadOnlyList ChangedFiles { get; } IReadOnlyList Comments { get; } IReadOnlyList Reviews { get; set; } - IReadOnlyList ReviewComments { get; set; } } } diff --git a/src/GitHub.Exports/Models/IPullRequestReviewModel.cs b/src/GitHub.Exports/Models/IPullRequestReviewModel.cs index 4e633ccb68..fac62cb64c 100644 --- a/src/GitHub.Exports/Models/IPullRequestReviewModel.cs +++ b/src/GitHub.Exports/Models/IPullRequestReviewModel.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; namespace GitHub.Models { @@ -72,5 +73,10 @@ public interface IPullRequestReviewModel /// Gets the date/time that the review was submitted. /// DateTimeOffset? SubmittedAt { get; } + + /// + /// Gets the comments for the review. + /// + IReadOnlyList Comments { get; } } } diff --git a/src/GitHub.InlineReviews/GitHub.InlineReviews.csproj b/src/GitHub.InlineReviews/GitHub.InlineReviews.csproj index ec6a0f63d9..43ca87c2d1 100644 --- a/src/GitHub.InlineReviews/GitHub.InlineReviews.csproj +++ b/src/GitHub.InlineReviews/GitHub.InlineReviews.csproj @@ -366,12 +366,12 @@ ..\..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll True - - ..\..\packages\Octokit.GraphQL.0.0.2-alpha\lib\netstandard1.1\Octokit.GraphQL.dll + + ..\..\packages\Octokit.GraphQL.0.0.3-alpha\lib\netstandard1.1\Octokit.GraphQL.dll True - - ..\..\packages\Octokit.GraphQL.0.0.2-alpha\lib\netstandard1.1\Octokit.GraphQL.Core.dll + + ..\..\packages\Octokit.GraphQL.0.0.3-alpha\lib\netstandard1.1\Octokit.GraphQL.Core.dll True diff --git a/src/GitHub.InlineReviews/Services/IPullRequestSessionService.cs b/src/GitHub.InlineReviews/Services/IPullRequestSessionService.cs index 8a12f9f7ac..ba75f05a27 100644 --- a/src/GitHub.InlineReviews/Services/IPullRequestSessionService.cs +++ b/src/GitHub.InlineReviews/Services/IPullRequestSessionService.cs @@ -265,12 +265,12 @@ Task PostPendingReviewCommentReply( /// THe SHA of the commit to comment on. /// The relative path of the file to comment on. /// The line index in the diff to comment on. - /// A model representing the posted comment. + /// A model representing the review for the posted comment. /// /// The method posts a new standalone pull request comment that is not attached to a pending /// pull request review. /// - Task PostStandaloneReviewComment( + Task PostStandaloneReviewComment( ILocalRepositoryModel localRepository, string remoteRepositoryOwner, IAccount user, @@ -289,8 +289,8 @@ Task PostStandaloneReviewComment( /// The pull request number. /// The comment body. /// The comment ID to reply to. - /// A model representing the posted comment. - Task PostStandaloneReviewCommentRepy( + /// A model representing the review for the posted comment. + Task PostStandaloneReviewCommentReply( ILocalRepositoryModel localRepository, string remoteRepositoryOwner, IAccount user, diff --git a/src/GitHub.InlineReviews/Services/PullRequestSession.cs b/src/GitHub.InlineReviews/Services/PullRequestSession.cs index 335f4b21d9..6e96ca288c 100644 --- a/src/GitHub.InlineReviews/Services/PullRequestSession.cs +++ b/src/GitHub.InlineReviews/Services/PullRequestSession.cs @@ -134,11 +134,9 @@ public async Task PostReviewComment( IReadOnlyList diff, int position) { - IPullRequestReviewCommentModel model; - if (!HasPendingReview) { - model = await service.PostStandaloneReviewComment( + var model = await service.PostStandaloneReviewComment( LocalRepository, RepositoryOwner, User, @@ -147,10 +145,12 @@ public async Task PostReviewComment( commitId, path, position); + await AddReview(model); + return model.Comments[0]; } else { - model = await service.PostPendingReviewComment( + var model = await service.PostPendingReviewComment( LocalRepository, User, pendingReviewNodeId, @@ -158,10 +158,9 @@ public async Task PostReviewComment( commitId, path, position); + await AddComment(model); + return model; } - - await AddComment(model); - return model; } /// @@ -170,30 +169,29 @@ public async Task PostReviewComment( int inReplyTo, string inReplyToNodeId) { - IPullRequestReviewCommentModel model; - if (!HasPendingReview) { - model = await service.PostStandaloneReviewCommentRepy( + var model = await service.PostStandaloneReviewCommentReply( LocalRepository, RepositoryOwner, User, PullRequest.Number, body, inReplyTo); + await AddReview(model); + return model.Comments[0]; } else { - model = await service.PostPendingReviewCommentReply( + var model = await service.PostPendingReviewCommentReply( LocalRepository, User, pendingReviewNodeId, body, inReplyToNodeId); + await AddComment(model); + return model; } - - await AddComment(model); - return model; } /// @@ -226,9 +224,6 @@ public async Task CancelReview() PullRequest.Reviews = PullRequest.Reviews .Where(x => x.NodeId != pendingReviewNodeId) .ToList(); - PullRequest.ReviewComments = PullRequest.ReviewComments - .Where(x => x.PullRequestReviewId != PendingReviewId) - .ToList(); await Update(PullRequest); } @@ -280,7 +275,15 @@ public async Task Update(IPullRequestModel pullRequestModel) async Task AddComment(IPullRequestReviewCommentModel comment) { - PullRequest.ReviewComments = PullRequest.ReviewComments + var review = (PullRequestReviewModel)PullRequest.Reviews + .FirstOrDefault(x => x.Id == PendingReviewId); + + if (review == null) + { + throw new KeyNotFoundException("Could not find pending review."); + } + + review.Comments = review.Comments .Concat(new[] { comment }) .ToList(); await Update(PullRequest); @@ -289,21 +292,10 @@ async Task AddComment(IPullRequestReviewCommentModel comment) async Task AddReview(IPullRequestReviewModel review) { PullRequest.Reviews = PullRequest.Reviews - .Where(x => x.NodeId != review.NodeId) + .Where(x => x.Id != review.Id) .Concat(new[] { review }) .ToList(); - if (review.State != PullRequestReviewState.Pending) - { - foreach (var comment in PullRequest.ReviewComments) - { - if (comment.PullRequestReviewId == review.Id) - { - comment.IsPending = false; - } - } - } - await Update(PullRequest); } diff --git a/src/GitHub.InlineReviews/Services/PullRequestSessionService.cs b/src/GitHub.InlineReviews/Services/PullRequestSessionService.cs index ad54647b22..92aa53c70c 100644 --- a/src/GitHub.InlineReviews/Services/PullRequestSessionService.cs +++ b/src/GitHub.InlineReviews/Services/PullRequestSessionService.cs @@ -42,6 +42,7 @@ public class PullRequestSessionService : IPullRequestSessionService readonly IApiClientFactory apiClientFactory; readonly IGraphQLClientFactory graphqlFactory; readonly IUsageTracker usageTracker; + readonly IAvatarProvider avatarProvider; readonly IDictionary, string> mergeBaseCache; @@ -52,7 +53,8 @@ public PullRequestSessionService( IDiffService diffService, IApiClientFactory apiClientFactory, IGraphQLClientFactory graphqlFactory, - IUsageTracker usageTracker) + IUsageTracker usageTracker, + IAvatarProvider avatarProvider) { this.gitService = gitService; this.gitClient = gitClient; @@ -60,6 +62,7 @@ public PullRequestSessionService( this.apiClientFactory = apiClientFactory; this.graphqlFactory = graphqlFactory; this.usageTracker = usageTracker; + this.avatarProvider = avatarProvider; mergeBaseCache = new Dictionary, string>(); } @@ -91,7 +94,7 @@ public IReadOnlyList BuildCommentThreads( { relativePath = relativePath.Replace("\\", "/"); - var commentsByPosition = pullRequest.ReviewComments + var commentsByPosition = pullRequest.Reviews.SelectMany(x => x.Comments) .Where(x => x.Path == relativePath && x.OriginalPosition.HasValue) .OrderBy(x => x.Id) .GroupBy(x => Tuple.Create(x.OriginalCommitId, x.OriginalPosition.Value)); @@ -272,7 +275,7 @@ public async Task GetGraphQLPullRequestId( .PullRequest(number) .Select(x => x.Id); - return await graphql.Run(query); + return (await graphql.Run(query)).Value; } /// @@ -329,7 +332,7 @@ public async Task CreatePendingReview( var review = new AddPullRequestReviewInput { - PullRequestId = pullRequestId, + PullRequestId = new ID(pullRequestId), }; var addReview = new Mutation() @@ -339,7 +342,7 @@ public async Task CreatePendingReview( Id = x.PullRequestReview.DatabaseId.Value, Body = x.PullRequestReview.Body, CommitId = x.PullRequestReview.Commit.Oid, - NodeId = x.PullRequestReview.Id, + NodeId = x.PullRequestReview.Id.Value, State = FromGraphQL(x.PullRequestReview.State), User = user, }); @@ -359,7 +362,7 @@ public async Task CancelPendingReview( var delete = new DeletePullRequestReviewInput { - PullRequestReviewId = reviewId, + PullRequestReviewId = new ID(reviewId), }; var deleteReview = new Mutation() @@ -416,18 +419,35 @@ public async Task SubmitPendingReview( { Body = body, Event = ToGraphQl(e), - PullRequestReviewId = pendingReviewId, + PullRequestReviewId = new ID(pendingReviewId), }; + // TODO: We're only reading the first 100 comments here. Add paging. var mutation = new Mutation() .SubmitPullRequestReview(submit) - .Select(x => new PullRequestReviewModel + .Select(review => new PullRequestReviewModel { Body = body, - CommitId = x.PullRequestReview.Commit.Oid, - Id = x.PullRequestReview.DatabaseId.Value, - NodeId = x.PullRequestReview.Id, - State = (GitHub.Models.PullRequestReviewState)x.PullRequestReview.State, + CommitId = review.PullRequestReview.Commit.Oid, + Comments = review.PullRequestReview.Comments(100, null, null, null).Nodes.Select(comment => new PullRequestReviewCommentModel + { + Id = comment.DatabaseId.Value, + NodeId = comment.Id.Value, + Body = comment.Body, + CommitId = comment.Commit.Oid, + CreatedAt = comment.CreatedAt, + DiffHunk = comment.DiffHunk, + OriginalCommitId = comment.OriginalCommit.Oid, + OriginalPosition = comment.OriginalPosition, + Path = comment.Path, + Position = comment.Position, + PullRequestReviewId = review.PullRequestReview.DatabaseId.Value, + User = Create(comment.Author.Login, comment.Author.AvatarUrl(null)), + IsPending = false, + }).ToList(), + Id = review.PullRequestReview.DatabaseId.Value, + NodeId = review.PullRequestReview.Id.Value, + State = (GitHub.Models.PullRequestReviewState)review.PullRequestReview.State, User = user, }); @@ -455,7 +475,7 @@ public async Task PostPendingReviewComment( CommitOID = commitId, Path = path, Position = position, - PullRequestReviewId = pendingReviewId, + PullRequestReviewId = new ID(pendingReviewId), }; var addComment = new Mutation() @@ -463,12 +483,12 @@ public async Task PostPendingReviewComment( .Select(x => new PullRequestReviewCommentModel { Id = x.Comment.DatabaseId.Value, - NodeId = x.Comment.Id, + NodeId = x.Comment.Id.Value, Body = x.Comment.Body, CommitId = x.Comment.Commit.Oid, Path = x.Comment.Path, Position = x.Comment.Position, - CreatedAt = x.Comment.CreatedAt.Value, + CreatedAt = x.Comment.CreatedAt, DiffHunk = x.Comment.DiffHunk, OriginalPosition = x.Comment.OriginalPosition, OriginalCommitId = x.Comment.OriginalCommit.Oid, @@ -496,8 +516,8 @@ public async Task PostPendingReviewCommentReply( var comment = new AddPullRequestReviewCommentInput { Body = body, - InReplyTo = inReplyTo, - PullRequestReviewId = pendingReviewId, + InReplyTo = new ID(inReplyTo), + PullRequestReviewId = new ID(pendingReviewId), }; var addComment = new Mutation() @@ -505,12 +525,12 @@ public async Task PostPendingReviewCommentReply( .Select(x => new PullRequestReviewCommentModel { Id = x.Comment.DatabaseId.Value, - NodeId = x.Comment.Id, + NodeId = x.Comment.Id.Value, Body = x.Comment.Body, CommitId = x.Comment.Commit.Oid, Path = x.Comment.Path, Position = x.Comment.Position, - CreatedAt = x.Comment.CreatedAt.Value, + CreatedAt = x.Comment.CreatedAt, DiffHunk = x.Comment.DiffHunk, OriginalPosition = x.Comment.OriginalPosition, OriginalCommitId = x.Comment.OriginalCommit.Oid, @@ -525,7 +545,7 @@ public async Task PostPendingReviewCommentReply( } /// - public async Task PostStandaloneReviewComment( + public async Task PostStandaloneReviewComment( ILocalRepositoryModel localRepository, string remoteRepositoryOwner, IAccount user, @@ -549,23 +569,34 @@ public async Task PostStandaloneReviewComment( await usageTracker.IncrementCounter(x => x.NumberOfPRReviewDiffViewInlineCommentPost); - return new PullRequestReviewCommentModel + return new PullRequestReviewModel { - Body = result.Body, - CommitId = result.CommitId, - DiffHunk = result.DiffHunk, - Id = result.Id, - OriginalCommitId = result.OriginalCommitId, - OriginalPosition = result.OriginalPosition, - Path = result.Path, - Position = result.Position, - CreatedAt = result.CreatedAt, + Id = result.PullRequestReviewId.Value, + CommitId = result.OriginalCommitId, + State = GitHub.Models.PullRequestReviewState.Commented, + SubmittedAt = DateTimeOffset.Now, User = user, + Comments = new[] + { + new PullRequestReviewCommentModel + { + Body = result.Body, + CommitId = result.CommitId, + DiffHunk = result.DiffHunk, + Id = result.Id, + OriginalCommitId = result.OriginalCommitId, + OriginalPosition = result.OriginalPosition, + Path = result.Path, + Position = result.Position, + CreatedAt = result.CreatedAt, + User = user, + } + } }; } /// - public async Task PostStandaloneReviewCommentRepy( + public async Task PostStandaloneReviewCommentReply( ILocalRepositoryModel localRepository, string remoteRepositoryOwner, IAccount user, @@ -585,18 +616,29 @@ public async Task PostStandaloneReviewCommentRep await usageTracker.IncrementCounter(x => x.NumberOfPRReviewDiffViewInlineCommentPost); - return new PullRequestReviewCommentModel + return new PullRequestReviewModel { - Body = result.Body, - CommitId = result.CommitId, - DiffHunk = result.DiffHunk, - Id = result.Id, - OriginalCommitId = result.OriginalCommitId, - OriginalPosition = result.OriginalPosition, - Path = result.Path, - Position = result.Position, - CreatedAt = result.CreatedAt, + Id = result.PullRequestReviewId.Value, + CommitId = result.OriginalCommitId, + State = GitHub.Models.PullRequestReviewState.Commented, + SubmittedAt = DateTimeOffset.Now, User = user, + Comments = new[] + { + new PullRequestReviewCommentModel + { + Body = result.Body, + CommitId = result.CommitId, + DiffHunk = result.DiffHunk, + Id = result.Id, + OriginalCommitId = result.OriginalCommitId, + OriginalPosition = result.OriginalPosition, + Path = result.Path, + Position = result.Position, + CreatedAt = result.CreatedAt, + User = user, + } + } }; } @@ -619,6 +661,17 @@ Task GetRepository(ILocalRepositoryModel repository) return Task.Factory.StartNew(() => gitService.GetRepository(repository.LocalPath)); } + IAccount Create(string login, string avatarUrl) + { + return new Account( + login, + true, + false, + 0, + 0, + avatarUrl, + avatarProvider.GetAvatar(avatarUrl)); + } static GitHub.Models.PullRequestReviewState FromGraphQL(Octokit.GraphQL.Model.PullRequestReviewState s) { diff --git a/src/GitHub.InlineReviews/packages.config b/src/GitHub.InlineReviews/packages.config index 9c2010990b..cb6f38408d 100644 --- a/src/GitHub.InlineReviews/packages.config +++ b/src/GitHub.InlineReviews/packages.config @@ -34,7 +34,7 @@ - + diff --git a/src/GitHub.VisualStudio/GitHub.VisualStudio.csproj b/src/GitHub.VisualStudio/GitHub.VisualStudio.csproj index a985af82ba..60ce6a4fb8 100644 --- a/src/GitHub.VisualStudio/GitHub.VisualStudio.csproj +++ b/src/GitHub.VisualStudio/GitHub.VisualStudio.csproj @@ -239,12 +239,12 @@ ..\..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll True - - ..\..\packages\Octokit.GraphQL.0.0.2-alpha\lib\netstandard1.1\Octokit.GraphQL.dll + + ..\..\packages\Octokit.GraphQL.0.0.3-alpha\lib\netstandard1.1\Octokit.GraphQL.dll True - - ..\..\packages\Octokit.GraphQL.0.0.2-alpha\lib\netstandard1.1\Octokit.GraphQL.Core.dll + + ..\..\packages\Octokit.GraphQL.0.0.3-alpha\lib\netstandard1.1\Octokit.GraphQL.Core.dll True diff --git a/src/GitHub.VisualStudio/packages.config b/src/GitHub.VisualStudio/packages.config index dfdd36c63a..ea59fe43a6 100644 --- a/src/GitHub.VisualStudio/packages.config +++ b/src/GitHub.VisualStudio/packages.config @@ -35,7 +35,7 @@ - + diff --git a/test/GitHub.InlineReviews.UnitTests/GitHub.InlineReviews.UnitTests.csproj b/test/GitHub.InlineReviews.UnitTests/GitHub.InlineReviews.UnitTests.csproj index 2dd110ce3f..255eab315e 100644 --- a/test/GitHub.InlineReviews.UnitTests/GitHub.InlineReviews.UnitTests.csproj +++ b/test/GitHub.InlineReviews.UnitTests/GitHub.InlineReviews.UnitTests.csproj @@ -141,6 +141,10 @@ {b389adaf-62cc-486e-85b4-2d8b078df763} GitHub.Api + + {1a1da411-8d1f-4578-80a6-04576bea2dc5} + GitHub.App + {e4ed0537-d1d9-44b6-9212-3096d7c3f7a1} GitHub.Exports.Reactive diff --git a/test/GitHub.InlineReviews.UnitTests/Services/PullRequestSessionManagerTests.cs b/test/GitHub.InlineReviews.UnitTests/Services/PullRequestSessionManagerTests.cs index 275bd74f10..8de41110b5 100644 --- a/test/GitHub.InlineReviews.UnitTests/Services/PullRequestSessionManagerTests.cs +++ b/test/GitHub.InlineReviews.UnitTests/Services/PullRequestSessionManagerTests.cs @@ -677,7 +677,8 @@ IPullRequestSessionService CreateRealSessionService(IDiffService diff) diff, Substitute.For(), Substitute.For(), - Substitute.For()); + Substitute.For(), + Substitute.For()); result.CreateRebuildSignal().Returns(new Subject()); result.GetPullRequestMergeBase(Arg.Any(), Arg.Any()) .Returns("MERGE_BASE"); @@ -861,7 +862,14 @@ IPullRequestModel CreatePullRequestModel( result.Number.Returns(number); result.Base.Returns(new GitReferenceModel("BASEREF", "pr", "BASESHA", cloneUrl)); result.Head.Returns(new GitReferenceModel("HEADREF", "pr", "HEADSHA", cloneUrl)); - result.ReviewComments.Returns(comments); + + if (comments.Length > 0) + { + var review = Substitute.For(); + review.Comments.Returns(comments); + result.Reviews.Returns(new[] { review }); + } + return result; } diff --git a/test/GitHub.InlineReviews.UnitTests/Services/PullRequestSessionServiceTests.cs b/test/GitHub.InlineReviews.UnitTests/Services/PullRequestSessionServiceTests.cs index 53d60fd5c7..261eec4018 100644 --- a/test/GitHub.InlineReviews.UnitTests/Services/PullRequestSessionServiceTests.cs +++ b/test/GitHub.InlineReviews.UnitTests/Services/PullRequestSessionServiceTests.cs @@ -298,7 +298,8 @@ static PullRequestSessionService CreateTarget(IDiffService diffService) diffService, Substitute.For(), Substitute.For(), - Substitute.For()); + Substitute.For(), + Substitute.For()); } static IPullRequestReviewCommentModel CreateComment( @@ -325,12 +326,15 @@ static IPullRequestModel CreatePullRequest( var changedFile2 = Substitute.For(); changedFile2.FileName.Returns("other.cs"); + var review = Substitute.For(); + review.Comments.Returns(comments); + var result = Substitute.For(); result.Number.Returns(PullRequestNumber); result.Base.Returns(new GitReferenceModel("BASE", "master", "BASE_SHA", RepoUrl)); result.Head.Returns(new GitReferenceModel("HEAD", "pr", "HEAD_SHA", RepoUrl)); result.ChangedFiles.Returns(new[] { changedFile1, changedFile2 }); - result.ReviewComments.Returns(comments); + result.Reviews.Returns(new[] { review }); return result; } diff --git a/test/GitHub.InlineReviews.UnitTests/Services/PullRequestSessionTests.cs b/test/GitHub.InlineReviews.UnitTests/Services/PullRequestSessionTests.cs index 56caf6cf76..bea0d8e46c 100644 --- a/test/GitHub.InlineReviews.UnitTests/Services/PullRequestSessionTests.cs +++ b/test/GitHub.InlineReviews.UnitTests/Services/PullRequestSessionTests.cs @@ -259,7 +259,7 @@ Line 2 using (var diffService = new FakeDiffService()) { - var pullRequest = CreatePullRequest(comment); + var pullRequest = CreatePullRequest(CreateReview(comment)); var service = CreateRealSessionService(diffService); diffService.AddFile(FilePath, baseContents, "MERGE_BASE"); @@ -352,17 +352,6 @@ public async Task RemovesReviewFromModel() Assert.IsEmpty(target.PullRequest.Reviews); } - [Test] - public async Task RemovesCommentsFromModel() - { - var service = Substitute.For(); - var target = CreateTargetWithPendingReview(service); - - await target.CancelReview(); - - Assert.IsEmpty(target.PullRequest.ReviewComments); - } - public static PullRequestSession CreateTargetWithPendingReview( IPullRequestSessionService service) { @@ -372,8 +361,8 @@ public static PullRequestSession CreateTargetWithPendingReview( var comment = Substitute.For(); comment.PullRequestReviewId.Returns(1); + review.Comments.Returns(new[] { comment }); pr.Reviews.Returns(new[] { review }); - pr.ReviewComments.Returns(new[] { comment }); return new PullRequestSession( service, @@ -455,23 +444,6 @@ public async Task ReplacesPendingReviewWithModel() Is.Zero); } - [Test] - public async Task MarksAssociatedCommentsAsNonPending() - { - var service = Substitute.For(); - var target = CreateTarget(service, "fork", "owner", true); - - Assert.That(target.PullRequest.ReviewComments[0].IsPending, Is.True); - - var submittedReview = CreatePullRequestReview(target.User, PullRequestReviewState.Approved); - submittedReview.NodeId.Returns("pendingReviewId"); - service.SubmitPendingReview(null, null, null, null, Octokit.PullRequestReviewEvent.Approve) - .ReturnsForAnyArgs(submittedReview); - var model = await target.PostReview("New Review", Octokit.PullRequestReviewEvent.RequestChanges); - - target.PullRequest.ReviewComments[0].Received(1).IsPending = false; - } - PullRequestSession CreateTarget( IPullRequestSessionService service, string localRepositoryOwner, @@ -492,10 +464,10 @@ PullRequestSession CreateTarget( var reviewComment = Substitute.For(); reviewComment.PullRequestReviewId.Returns(1); reviewComment.IsPending.Returns(true); - pr.ReviewComments.Returns(new[] { reviewComment }); var review = CreatePullRequestReview(user, PullRequestReviewState.Pending); review.NodeId.Returns("pendingReviewId"); + review.Comments.Returns(new[] { reviewComment }); pr.Reviews.Returns(new[] { review }); } @@ -538,7 +510,7 @@ public async Task PostsReplyToCorrectForkWithNoPendingReview() await target.PostReviewComment("New Comment", 1, "node1"); - await service.Received(1).PostStandaloneReviewCommentRepy( + await service.Received(1).PostStandaloneReviewCommentReply( target.LocalRepository, "owner", target.User, @@ -598,8 +570,13 @@ PullRequestSession CreateTarget( if (hasPendingReview) { - var review = CreatePullRequestReview(user, PullRequestReviewState.Pending); - review.NodeId.Returns("pendingReviewId"); + var review = new PullRequestReviewModel + { + NodeId = "pendingReviewId", + State = PullRequestReviewState.Pending, + User = user, + }; + pr.Reviews.Returns(new[] { review }); } @@ -659,7 +636,7 @@ Line 2 using (var diffService = new FakeDiffService()) { - var pullRequest = CreatePullRequest(comment1); + var pullRequest = CreatePullRequest(CreateReview(comment1)); var service = CreateRealSessionService(diffService); diffService.AddFile(FilePath, baseContents, "MERGE_BASE"); @@ -678,7 +655,7 @@ Line 2 Assert.That(file.InlineCommentThreads[0].Comments, Has.Count.EqualTo(1)); Assert.That(file.InlineCommentThreads[0].LineNumber, Is.EqualTo(2)); - pullRequest = CreatePullRequest(comment1, comment2); + pullRequest = CreatePullRequest(CreateReview(comment1, comment2)); await target.Update(pullRequest); Assert.That(file.InlineCommentThreads[0].Comments, Has.Count.EqualTo(2)); @@ -711,7 +688,7 @@ Line 2 using (var diffService = new FakeDiffService()) { - var pullRequest = CreatePullRequest(comment1); + var pullRequest = CreatePullRequest(CreateReview(comment1)); var service = CreateRealSessionService(diffService); diffService.AddFile(FilePath, baseContents, "MERGE_BASE"); @@ -730,7 +707,7 @@ Line 2 Assert.That(file.InlineCommentThreads[0].Comments, Has.Count.EqualTo(1)); Assert.That(file.InlineCommentThreads[0].LineNumber, Is.EqualTo(2)); - pullRequest = CreatePullRequest(comment1, comment2); + pullRequest = CreatePullRequest(CreateReview(comment1, comment2)); await target.Update(pullRequest); Assert.That(file.InlineCommentThreads[0].Comments, Has.Count.EqualTo(2)); @@ -749,7 +726,7 @@ Line 2 using (var diffService = new FakeDiffService()) { - var pullRequest = CreatePullRequest(comment); + var pullRequest = CreatePullRequest(CreateReview(comment)); var service = CreateRealSessionService(diffService); var target = new PullRequestSession( @@ -790,7 +767,14 @@ static IPullRequestReviewCommentModel CreateComment(string diffHunk, string body return result; } - static IPullRequestModel CreatePullRequest(params IPullRequestReviewCommentModel[] comments) + static IPullRequestReviewModel CreateReview(params IPullRequestReviewCommentModel[] comments) + { + var result = Substitute.For(); + result.Comments.Returns(comments); + return result; + } + + static IPullRequestModel CreatePullRequest(params IPullRequestReviewModel[] reviews) { var changedFile1 = Substitute.For(); changedFile1.FileName.Returns("test.cs"); @@ -802,7 +786,7 @@ static IPullRequestModel CreatePullRequest(params IPullRequestReviewCommentModel result.Base.Returns(new GitReferenceModel("BASE", "master", "BASE_SHA", RepoUrl)); result.Head.Returns(new GitReferenceModel("HEAD", "pr", "HEAD_SHA", RepoUrl)); result.ChangedFiles.Returns(new[] { changedFile1, changedFile2 }); - result.ReviewComments.Returns(comments); + result.Reviews.Returns(reviews); result.Equals(null).ReturnsForAnyArgs(x => { @@ -856,7 +840,8 @@ static IPullRequestSessionService CreateRealSessionService(IDiffService diffServ diffService ?? Substitute.For(), Substitute.For(), Substitute.For(), - Substitute.For()); + Substitute.For(), + Substitute.For()); result.GetTipSha(Arg.Any()).Returns("BRANCH_TIP"); result.GetPullRequestMergeBase(Arg.Any(), Arg.Any()) diff --git a/test/UnitTests/GitHub.App/ViewModels/GitHubPane/PullRequestReviewAuthoringViewModelTests.cs b/test/UnitTests/GitHub.App/ViewModels/GitHubPane/PullRequestReviewAuthoringViewModelTests.cs index 86e9f7efc7..1bcb1620c5 100644 --- a/test/UnitTests/GitHub.App/ViewModels/GitHubPane/PullRequestReviewAuthoringViewModelTests.cs +++ b/test/UnitTests/GitHub.App/ViewModels/GitHubPane/PullRequestReviewAuthoringViewModelTests.cs @@ -458,11 +458,9 @@ static PullRequestModel CreatePullRequest( static PullRequestModel CreatePullRequest( string authorLogin = "grokys", - IEnumerable reviews = null, - IEnumerable reviewComments = null) + IEnumerable reviews = null) { reviews = reviews ?? new IPullRequestReviewModel[0]; - reviewComments = reviewComments ?? new IPullRequestReviewCommentModel[0]; var author = Substitute.For(); author.Login.Returns(authorLogin); @@ -473,7 +471,6 @@ static PullRequestModel CreatePullRequest( author, DateTimeOffset.Now); result.Reviews = reviews.ToList(); - result.ReviewComments = reviewComments.ToList(); return result; } diff --git a/test/UnitTests/GitHub.App/ViewModels/GitHubPane/PullRequestReviewViewModelTests.cs b/test/UnitTests/GitHub.App/ViewModels/GitHubPane/PullRequestReviewViewModelTests.cs index f740ce9be2..8369583c5e 100644 --- a/test/UnitTests/GitHub.App/ViewModels/GitHubPane/PullRequestReviewViewModelTests.cs +++ b/test/UnitTests/GitHub.App/ViewModels/GitHubPane/PullRequestReviewViewModelTests.cs @@ -37,8 +37,6 @@ public void Creates_FileComments_And_OutdatedComments() public void HasDetails_True_When_Has_Body() { var pr = CreatePullRequest(); - pr.ReviewComments = new IPullRequestReviewCommentModel[0]; - var target = CreateTarget(pullRequest: pr); Assert.That(target.HasDetails, Is.True); @@ -59,8 +57,10 @@ public void HasDetails_True_When_Has_Comments() public void HasDetails_False_When_Has_No_Body_Or_Comments() { var pr = CreatePullRequest(); - ((PullRequestReviewModel)pr.Reviews[0]).Body = string.Empty; - pr.ReviewComments = new IPullRequestReviewCommentModel[0]; + var review = (PullRequestReviewModel)pr.Reviews[0]; + + review.Body = string.Empty; + review.Comments = new IPullRequestReviewCommentModel[0]; var target = CreateTarget(pullRequest: pr); @@ -81,7 +81,6 @@ PullRequestReviewViewModel CreateTarget( return new PullRequestReviewViewModel( editorService, session, - pullRequest, model); } @@ -105,53 +104,50 @@ private PullRequestModel CreatePullRequest( Id = 1, Body = "Looks good to me!", State = PullRequestReviewState.Approved, + Comments = new[] + { + new PullRequestReviewCommentModel + { + Body = "I like this.", + Position = 10, + }, + new PullRequestReviewCommentModel + { + Body = "This is good.", + Position = 11, + }, + new PullRequestReviewCommentModel + { + Body = "Fine, but outdated.", + Position = null, + }, + }, }, new PullRequestReviewModel { Id = 2, Body = "Changes please.", State = PullRequestReviewState.ChangesRequested, + Comments = new[] + { + new PullRequestReviewCommentModel + { + Body = "Not great.", + Position = 20, + }, + new PullRequestReviewCommentModel + { + Body = "This sucks.", + Position = 21, + }, + new PullRequestReviewCommentModel + { + Body = "Bad and old.", + Position = null, + }, + }, }, }, - ReviewComments = new[] - { - new PullRequestReviewCommentModel - { - Body = "I like this.", - PullRequestReviewId = 1, - Position = 10, - }, - new PullRequestReviewCommentModel - { - Body = "This is good.", - PullRequestReviewId = 1, - Position = 11, - }, - new PullRequestReviewCommentModel - { - Body = "Fine, but outdated.", - PullRequestReviewId = 1, - Position = null, - }, - new PullRequestReviewCommentModel - { - Body = "Not great.", - PullRequestReviewId = 2, - Position = 20, - }, - new PullRequestReviewCommentModel - { - Body = "This sucks.", - PullRequestReviewId = 2, - Position = 21, - }, - new PullRequestReviewCommentModel - { - Body = "Bad and old.", - PullRequestReviewId = 2, - Position = null, - }, - } }; } } diff --git a/test/UnitTests/GitHub.App/ViewModels/GitHubPane/PullRequestUserReviewsViewModelTests.cs b/test/UnitTests/GitHub.App/ViewModels/GitHubPane/PullRequestUserReviewsViewModelTests.cs index a757fa3dd7..5be070b5d6 100644 --- a/test/UnitTests/GitHub.App/ViewModels/GitHubPane/PullRequestUserReviewsViewModelTests.cs +++ b/test/UnitTests/GitHub.App/ViewModels/GitHubPane/PullRequestUserReviewsViewModelTests.cs @@ -69,7 +69,6 @@ public async Task InitializeAsync_Creates_Reviews() State = PullRequestReviewState.Pending, }, }, - ReviewComments = new IPullRequestReviewCommentModel[0], }; var modelSerivce = Substitute.For(); @@ -115,7 +114,6 @@ public async Task Orders_Reviews_Descending() SubmittedAt = DateTimeOffset.Now - TimeSpan.FromDays(1), }, }, - ReviewComments = new IPullRequestReviewCommentModel[0], }; var modelSerivce = Substitute.For(); @@ -162,7 +160,6 @@ public async Task First_Review_Is_Expanded() State = PullRequestReviewState.Dismissed, }, }, - ReviewComments = new IPullRequestReviewCommentModel[0], }; var modelSerivce = Substitute.For(); diff --git a/test/UnitTests/UnitTests.csproj b/test/UnitTests/UnitTests.csproj index 10382e15a0..c19d42add1 100644 --- a/test/UnitTests/UnitTests.csproj +++ b/test/UnitTests/UnitTests.csproj @@ -177,12 +177,12 @@ ..\..\packages\NUnit.3.9.0\lib\net45\nunit.framework.dll - - ..\..\packages\Octokit.GraphQL.0.0.2-alpha\lib\netstandard1.1\Octokit.GraphQL.dll + + ..\..\packages\Octokit.GraphQL.0.0.3-alpha\lib\netstandard1.1\Octokit.GraphQL.dll True - - ..\..\packages\Octokit.GraphQL.0.0.2-alpha\lib\netstandard1.1\Octokit.GraphQL.Core.dll + + ..\..\packages\Octokit.GraphQL.0.0.3-alpha\lib\netstandard1.1\Octokit.GraphQL.Core.dll True diff --git a/test/UnitTests/packages.config b/test/UnitTests/packages.config index 87bdee5b8d..74afc1344d 100644 --- a/test/UnitTests/packages.config +++ b/test/UnitTests/packages.config @@ -31,7 +31,7 @@ - +