Пример #1
0
        static void BuildPullRequestThreads(PullRequestDetailModel model)
        {
            var commentsByReplyId = new Dictionary <string, List <CommentAdapter> >();

            // Get all comments that are not replies.
            foreach (CommentAdapter comment in model.Reviews.SelectMany(x => x.Comments))
            {
                if (comment.ReplyTo == null)
                {
                    commentsByReplyId.Add(comment.Id, new List <CommentAdapter> {
                        comment
                    });
                }
            }

            // Get the comments that are replies and place them into the relevant list.
            foreach (CommentAdapter comment in model.Reviews.SelectMany(x => x.Comments).OrderBy(x => x.CreatedAt))
            {
                if (comment.ReplyTo != null)
                {
                    List <CommentAdapter> thread = null;

                    if (commentsByReplyId.TryGetValue(comment.ReplyTo, out thread))
                    {
                        thread.Add(comment);
                    }
                }
            }

            // Build a collection of threads for the information collected above.
            var threads = new List <PullRequestReviewThreadModel>();

            foreach (var threadSource in commentsByReplyId)
            {
                var adapter = threadSource.Value[0];

                var thread = new PullRequestReviewThreadModel
                {
                    Comments          = threadSource.Value,
                    CommitSha         = adapter.CommitSha,
                    DiffHunk          = adapter.DiffHunk,
                    Id                = adapter.Id,
                    IsOutdated        = adapter.Position == null,
                    OriginalCommitSha = adapter.OriginalCommitId,
                    OriginalPosition  = adapter.OriginalPosition,
                    Path              = adapter.Path,
                    Position          = adapter.Position,
                };

                // Set a reference to the thread in the comment.
                foreach (var comment in threadSource.Value)
                {
                    comment.Thread = thread;
                }

                threads.Add(thread);
            }

            model.Threads = threads;
        }
Пример #2
0
            static PullRequestReviewThreadModel CreateCommentThread(
                string diffHunk,
                string body     = "Comment",
                string filePath = FilePath)
            {
                var thread = new PullRequestReviewThreadModel
                {
                    DiffHunk          = diffHunk,
                    Path              = filePath,
                    OriginalCommitSha = "ORIG",
                    OriginalPosition  = 1,
                };

                thread.Comments = new[]
                {
                    new PullRequestReviewCommentModel
                    {
                        Body   = body,
                        Thread = thread,
                    },
                };

                return(thread);
            }
Пример #3
0
        private PullRequestDetailModel CreatePullRequest(
            int number        = 5,
            string title      = "Pull Request Title",
            string body       = "Pull Request Body",
            ActorModel author = null)
        {
            var thread1 = new PullRequestReviewThreadModel
            {
                Position = 10
            };

            return(new PullRequestDetailModel
            {
                Number = number,
                Title = title,
                Author = author ?? new ActorModel(),
                Body = body,
                Reviews = new[]
                {
                    new PullRequestReviewModel
                    {
                        Id = "1",
                        Body = "Looks good to me!",
                        State = PullRequestReviewState.Approved,
                        Comments = new[]
                        {
                            new PullRequestReviewCommentModel
                            {
                                Body = "I like this.",
                                Thread = new PullRequestReviewThreadModel {
                                    Position = 10
                                },
                            },
                            new PullRequestReviewCommentModel
                            {
                                Body = "This is good.",
                                Thread = new PullRequestReviewThreadModel {
                                    Position = 11
                                },
                            },
                            new PullRequestReviewCommentModel
                            {
                                Body = "Fine, but outdated.",
                                Thread = new PullRequestReviewThreadModel {
                                    Position = null
                                },
                            },
                        },
                    },
                    new PullRequestReviewModel
                    {
                        Id = "2",
                        Body = "Changes please.",
                        State = PullRequestReviewState.ChangesRequested,
                        Comments = new[]
                        {
                            new PullRequestReviewCommentModel
                            {
                                Body = "Not great.",
                                Thread = new PullRequestReviewThreadModel {
                                    Position = 20
                                },
                            },
                            new PullRequestReviewCommentModel
                            {
                                Body = "This sucks.",
                                Thread = new PullRequestReviewThreadModel {
                                    Position = 21
                                },
                            },
                            new PullRequestReviewCommentModel
                            {
                                Body = "Bad and old.",
                                Thread = new PullRequestReviewThreadModel {
                                    Position = null
                                },
                            },
                        },
                    },
                },
            });
        }