/// <inheritdoc/>
        public async Task <PullRequestDetailModel> PostReview(
            LocalRepositoryModel localRepository,
            string pullRequestId,
            string commitId,
            string body,
            PullRequestReviewEvent e)
        {
            var address = HostAddress.Create(localRepository.CloneUrl.Host);
            var graphql = await graphqlFactory.CreateConnection(address);

            var addReview = new AddPullRequestReviewInput
            {
                Body          = body,
                CommitOID     = commitId,
                Event         = ToGraphQl(e),
                PullRequestId = new ID(pullRequestId),
            };

            var mutation = new Mutation()
                           .AddPullRequestReview(addReview)
                           .Select(x => new
            {
                x.PullRequestReview.Repository.Owner.Login,
                x.PullRequestReview.PullRequest.Number
            });

            var result = await graphql.Run(mutation);

            await usageTracker.IncrementCounter(x => x.NumberOfPRReviewPosts);

            return(await ReadPullRequestDetail(address, result.Login, localRepository.Name, result.Number));
        }
        /// <inheritdoc/>
        public async Task <IPullRequestReviewModel> CreatePendingReview(
            ILocalRepositoryModel localRepository,
            IAccount user,
            string pullRequestId)
        {
            var address = HostAddress.Create(localRepository.CloneUrl.Host);
            var graphql = await graphqlFactory.CreateConnection(address);

            var review = new AddPullRequestReviewInput
            {
                PullRequestId = pullRequestId,
            };

            var addReview = new Mutation()
                            .AddPullRequestReview(review)
                            .Select(x => new PullRequestReviewModel
            {
                Id       = x.PullRequestReview.DatabaseId.Value,
                Body     = x.PullRequestReview.Body,
                CommitId = x.PullRequestReview.Commit.Oid,
                NodeId   = x.PullRequestReview.Id,
                State    = FromGraphQL(x.PullRequestReview.State),
                User     = user,
            });

            var result = await graphql.Run(addReview);

            await usageTracker.IncrementCounter(x => x.NumberOfPRReviewDiffViewInlineCommentStartReview);

            return(result);
        }
        /// <inheritdoc/>
        public async Task <PullRequestDetailModel> CreatePendingReview(
            ILocalRepositoryModel localRepository,
            string pullRequestId)
        {
            var address = HostAddress.Create(localRepository.CloneUrl.Host);
            var graphql = await graphqlFactory.CreateConnection(address);

            var review = new AddPullRequestReviewInput
            {
                PullRequestId = new ID(pullRequestId),
            };

            var mutation = new Mutation()
                           .AddPullRequestReview(review)
                           .Select(x => new
            {
                x.PullRequestReview.Repository.Owner.Login,
                x.PullRequestReview.PullRequest.Number
            });

            var result = await graphql.Run(mutation);

            await usageTracker.IncrementCounter(x => x.NumberOfPRReviewDiffViewInlineCommentStartReview);

            return(await ReadPullRequestDetail(address, result.Login, localRepository.Name, result.Number));
        }
Beispiel #4
0
        /// <inheritdoc/>
        public async Task <IPullRequestReviewCommentModel> PostStandaloneReviewComment(
            ILocalRepositoryModel localRepository,
            IAccount user,
            string pullRequestNodeId,
            string body,
            string commitId,
            string path,
            int position)
        {
            var address = HostAddress.Create(localRepository.CloneUrl.Host);
            var graphql = await graphqlFactory.CreateConnection(address);

            var addReview = new AddPullRequestReviewInput
            {
                Body          = body,
                CommitOID     = commitId,
                Event         = Octokit.GraphQL.Model.PullRequestReviewEvent.Comment,
                PullRequestId = pullRequestNodeId,
                Comments      = new[]
                {
                    new DraftPullRequestReviewComment
                    {
                        Body     = body,
                        Path     = path,
                        Position = position,
                    },
                },
            };

            var mutation = new Mutation()
                           .AddPullRequestReview(addReview)
                           .Select(payload =>
                                   payload.PullRequestReview
                                   .Comments(1, null, null, null)
                                   .Nodes.Select(x => new PullRequestReviewCommentModel
            {
                Id                  = x.DatabaseId.Value,
                NodeId              = x.Id,
                Body                = x.Body,
                CommitId            = x.Commit.Oid,
                Path                = x.Path,
                Position            = x.Position,
                CreatedAt           = x.CreatedAt.Value,
                DiffHunk            = x.DiffHunk,
                OriginalPosition    = x.OriginalPosition,
                OriginalCommitId    = x.OriginalCommit.Oid,
                PullRequestReviewId = x.PullRequestReview.DatabaseId.Value,
                User                = user,
                IsPending           = false
            }));

            var result = (await graphql.Run(mutation)).First();
            await usageTracker.IncrementCounter(x => x.NumberOfPRReviewDiffViewInlineCommentPost);

            return(result);
        }
Beispiel #5
0
        /// <inheritdoc/>
        public async Task <PullRequestDetailModel> PostStandaloneReviewComment(
            LocalRepositoryModel localRepository,
            string pullRequestId,
            string body,
            string commitId,
            string path,
            int position)
        {
            var address = HostAddress.Create(localRepository.CloneUrl.Host);
            var graphql = await graphqlFactory.CreateConnection(address);

            var addReview = new AddPullRequestReviewInput
            {
                Body          = body,
                CommitOID     = commitId,
                Event         = Octokit.GraphQL.Model.PullRequestReviewEvent.Comment,
                PullRequestId = new ID(pullRequestId),
                Comments      = new[]
                {
                    new DraftPullRequestReviewComment
                    {
                        Body     = body,
                        Path     = path,
                        Position = position,
                    },
                },
            };

            var mutation = new Mutation()
                           .AddPullRequestReview(addReview)
                           .Select(x => new
            {
                x.PullRequestReview.Repository.Owner.Login,
                x.PullRequestReview.PullRequest.Number
            });

            var result = await graphql.Run(mutation);

            await usageTracker.IncrementCounter(x => x.NumberOfPRReviewDiffViewInlineCommentPost);

            return(await ReadPullRequestDetail(address, result.Login, localRepository.Name, result.Number));
        }
Beispiel #6
0
        async Task <(string id, string owner, int number)> CreatePendingReviewCore(LocalRepositoryModel localRepository, string pullRequestId)
        {
            var address = HostAddress.Create(localRepository.CloneUrl.Host);
            var graphql = await graphqlFactory.CreateConnection(address);

            var input = new AddPullRequestReviewInput
            {
                PullRequestId = new ID(pullRequestId),
            };

            var mutation = new Mutation()
                           .AddPullRequestReview(input)
                           .Select(x => new
            {
                Id    = x.PullRequestReview.Id.Value,
                Owner = x.PullRequestReview.Repository.Owner.Login,
                x.PullRequestReview.PullRequest.Number
            });

            var result = await graphql.Run(mutation);

            return(result.Id, result.Owner, result.Number);
        }