コード例 #1
0
        static PullRequestReviewCommentViewModel CreateTarget(
            IPullRequestSession session           = null,
            ICommentService commentService        = null,
            ICommentThreadViewModel thread        = null,
            ActorModel currentUser                = null,
            PullRequestReviewModel review         = null,
            PullRequestReviewCommentModel comment = null)
        {
            session        = session ?? CreateSession();
            commentService = commentService ?? Substitute.For <ICommentService>();
            thread         = thread ?? CreateThread();
            currentUser    = currentUser ?? new ActorModel {
                Login = "******"
            };
            comment = comment ?? new PullRequestReviewCommentModel();
            review  = review ?? CreateReview(comment);

            return(new PullRequestReviewCommentViewModel(
                       session,
                       commentService,
                       thread,
                       new ActorViewModel(currentUser),
                       review,
                       comment));
        }
コード例 #2
0
        async Task <ICommentModel> DoPostComment(object parameter)
        {
            Guard.ArgumentNotNull(parameter, nameof(parameter));

            var body    = (string)parameter;
            var replyId = Comments[0].Id;
            var result  = await apiClient.CreatePullRequestReviewComment(
                Session.RepositoryOwner,
                Session.LocalRepository.Name,
                Session.PullRequest.Number,
                body,
                replyId);

            var model = 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             = Session.User,
            };

            await Session.AddComment(model);

            return(model);
        }
コード例 #3
0
            public async Task IsFalseWhenEditingExistingComment()
            {
                var session = CreateSession();
                var pullRequestReviewCommentModel = new PullRequestReviewCommentModel {
                    Id = "1"
                };
                var target = await CreateTarget(session, comment : pullRequestReviewCommentModel);

                Assert.That(target.CanStartReview, Is.False);
            }
コード例 #4
0
            public async Task IsUpdateCommentWhenEditingExistingComment()
            {
                var session = CreateSession();
                var pullRequestReviewCommentModel = new PullRequestReviewCommentModel {
                    Id = "1"
                };
                var target = await CreateTarget(session, comment : pullRequestReviewCommentModel);

                Assert.That(target.CommitCaption, Is.EqualTo("Update comment"));
            }
コード例 #5
0
        async Task AddComment(PullRequestReviewCommentModel comment)
        {
            var review = 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);
        }
コード例 #6
0
        /// <inheritdoc/>
        public async Task InitializeAsync(
            IPullRequestSession session,
            ICommentThreadViewModel thread,
            PullRequestReviewModel review,
            PullRequestReviewCommentModel comment,
            CommentEditState state)
        {
            Guard.ArgumentNotNull(session, nameof(session));

            await InitializeAsync(thread, session.User, comment, state).ConfigureAwait(true);

            this.session = session;
            IsPending    = review.State == PullRequestReviewState.Pending;
        }
コード例 #7
0
            public async Task CanBeExecutedForCommentsByTheSameAuthor()
            {
                var session = CreateSession();
                var thread  = CreateThread();

                var currentUser = new ActorModel {
                    Login = "******"
                };
                var comment = new PullRequestReviewCommentModel {
                    Author = currentUser
                };

                var target = await CreateTarget(session, null, thread, currentUser, null, comment);

                Assert.That(target.BeginEdit.CanExecute(new object()), Is.True);
            }
コード例 #8
0
        async Task <ICommentModel> DoPostComment(object parameter)
        {
            Guard.ArgumentNotNull(parameter, nameof(parameter));

            var diffPosition = File.Diff
                               .SelectMany(x => x.Lines)
                               .FirstOrDefault(x =>
            {
                var line = LeftComparisonBuffer ? x.OldLineNumber : x.NewLineNumber;
                return(line == LineNumber + 1);
            });

            if (diffPosition == null)
            {
                throw new InvalidOperationException("Unable to locate line in diff.");
            }

            var body   = (string)parameter;
            var result = await apiClient.CreatePullRequestReviewComment(
                Session.RepositoryOwner,
                Session.LocalRepository.Name,
                Session.PullRequest.Number,
                body,
                File.CommitSha,
                File.RelativePath.Replace("\\", "/"),
                diffPosition.DiffLineNumber);

            var model = 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             = Session.User,
            };

            await Session.AddComment(model);

            finished.OnNext(Unit.Default);

            return(model);
        }
        public PullRequestReviewCommentViewModel(
            IPullRequestEditorService editorService,
            IPullRequestSession session,
            string relativePath,
            PullRequestReviewCommentModel model)
        {
            Guard.ArgumentNotNull(editorService, nameof(editorService));
            Guard.ArgumentNotNull(session, nameof(session));
            Guard.ArgumentNotNull(model, nameof(model));

            this.editorService = editorService;
            this.session       = session;
            this.model         = model;
            RelativePath       = relativePath;

            Open = ReactiveCommand.CreateFromTask(DoOpen);
        }
コード例 #10
0
            public async Task CannotBeExecutedForCommentsByAnotherAuthor()
            {
                var session = CreateSession();
                var thread  = CreateThread();

                var currentUser = new ActorModel {
                    Login = "******"
                };
                var otherUser = new ActorModel {
                    Login = "******"
                };
                var comment = new PullRequestReviewCommentModel {
                    Author = otherUser
                };

                var target = await CreateTarget(session, null, thread, currentUser, null, comment);

                Assert.That(target.Delete.CanExecute(new object()), Is.False);
            }
コード例 #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PullRequestReviewCommentViewModel"/> class.
 /// </summary>
 /// <param name="session">The pull request session.</param>
 /// <param name="thread">The thread that the comment is a part of.</param>
 /// <param name="currentUser">The current user.</param>
 /// <param name="model">The comment model.</param>
 public PullRequestReviewCommentViewModel(
     IPullRequestSession session,
     ICommentThreadViewModel thread,
     IActorViewModel currentUser,
     PullRequestReviewModel review,
     PullRequestReviewCommentModel model)
     : this(
         session,
         thread,
         currentUser,
         model.Id,
         model.Body,
         CommentEditState.None,
         new ActorViewModel(model.Author),
         model.CreatedAt,
         review.State == PullRequestReviewState.Pending,
         model.Url != null ? new Uri(model.Url) : null)
 {
 }
コード例 #12
0
        static async Task <PullRequestReviewCommentViewModel> CreateTarget(
            IPullRequestSession session           = null,
            ICommentService commentService        = null,
            ICommentThreadViewModel thread        = null,
            ActorModel currentUser                = null,
            PullRequestReviewModel review         = null,
            PullRequestReviewCommentModel comment = null)
        {
            session        = session ?? CreateSession();
            commentService = commentService ?? Substitute.For <ICommentService>();
            thread         = thread ?? CreateThread();
            currentUser    = currentUser ?? new ActorModel {
                Login = "******"
            };
            comment = comment ?? new PullRequestReviewCommentModel();
            review  = review ?? CreateReview(PullRequestReviewState.Approved, comment);

            var result = new PullRequestReviewCommentViewModel(commentService);
            await result.InitializeAsync(session, thread, review, comment, CommentEditState.None);

            return(result);
        }