private async Task <PullRequestReviewComment> CreateComment(string body, int position, string repoName, string pullRequestCommitId, int pullRequestNumber)
        {
            var comment = new PullRequestReviewCommentCreate(body, pullRequestCommitId, path, position);

            var createdComment = await _client.Create(Helper.UserName, repoName, pullRequestNumber, comment);

            AssertComment(createdComment, body, position);

            return(createdComment);
        }
示例#2
0
    async Task <PullRequestReviewComment> CreateComment(string body, int position, int repositoryId, string pullRequestCommitId, int pullRequestNumber)
    {
        var comment = new PullRequestReviewCommentCreate(body, pullRequestCommitId, path, position);

        var createdComment = await _client.Create(repositoryId, pullRequestNumber, comment);

        AssertComment(createdComment, body, position);

        return(createdComment);
    }
            public void PostsToCorrectUrl()
            {
                var gitHubClient = Substitute.For <IGitHubClient>();
                var client       = new ObservablePullRequestReviewCommentsClient(gitHubClient);

                var comment = new PullRequestReviewCommentCreate("Comment content", "qe3dsdsf6", "file.css", 7);

                client.Create("fakeOwner", "fakeRepoName", 13, comment);

                gitHubClient.PullRequest.Comment.Received().Create("fakeOwner", "fakeRepoName", 13, comment);
            }
示例#4
0
        public void PostsToCorrectUrl()
        {
            var connection = Substitute.For <IApiConnection>();
            var client     = new PullRequestReviewCommentsClient(connection);

            var comment = new PullRequestReviewCommentCreate("Comment content", "qe3dsdsf6", "file.css", 7);

            client.Create("fakeOwner", "fakeRepoName", 13, comment);

            connection.Connection.Received().Post <PullRequestReviewComment>(Arg.Is <Uri>(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/13/comments"),
                                                                             comment, null, null);
        }
示例#5
0
        public IObservable <PullRequestReviewComment> CreatePullRequestReviewComment(
            string owner,
            string name,
            int number,
            string body,
            string commitId,
            string path,
            int position)
        {
            var comment = new PullRequestReviewCommentCreate(body, commitId, path, position);

            return(gitHubClient.PullRequest.Comment.Create(owner, name, number, comment));
        }
示例#6
0
        public void PullRequestReviewCommentCreateEnsuresArgumentsValue()
        {
            string body     = "body";
            string commitId = "sha";
            string path     = "path";
            int    position = 1;

            var comment = new PullRequestReviewCommentCreate(body, commitId, path, position);

            Assert.Equal(body, comment.Body);
            Assert.Equal(commitId, comment.CommitId);
            Assert.Equal(path, comment.Path);
            Assert.Equal(position, comment.Position);
        }
示例#7
0
        public async Task <PullRequestReviewComment> CreatePullRequestReviewComment(Comment comment)
        {
            try
            {
                var reviewComment =
                    new PullRequestReviewCommentCreate(comment.Body, comment.CommitId, comment.Path, comment.Position);
                var a = await client.PullRequest.ReviewComment.Create(comment.RepositoryOnwer, comment.RepositoryName,
                                                                      int.Parse(comment.PullRequestId), reviewComment);

                return(a);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public PullRequestDiffViewModel(ISessionService sessionService, IActionMenuFactory actionMenuFactory, IAlertDialogFactory alertDialogFactory)
        {
            var gotoCreateCommentCommand = ReactiveCommand.Create().WithSubscription(_ => {
                var vm = new ComposerViewModel(async s => {
                    var req     = new PullRequestReviewCommentCreate(s, ParentViewModel.HeadSha, Filename, SelectedPatchLine.Item1);
                    var comment = await sessionService.GitHubClient.PullRequest.Comment.Create(ParentViewModel.RepositoryOwner, ParentViewModel.RepositoryName, ParentViewModel.PullRequestId, req);
                    _commentCreatedObservable.OnNext(comment);
                }, alertDialogFactory);
                NavigateTo(vm);
            });

            GoToCommentCommand = ReactiveCommand.CreateAsyncTask(this.WhenAnyValue(x => x.SelectedPatchLine).Select(x => x != null),
                                                                 sender => {
                var sheet = actionMenuFactory.Create();
                sheet.AddButton(string.Format("Add Comment on Line {0}", SelectedPatchLine.Item2), gotoCreateCommentCommand);
                return(sheet.Show(sender));
            });

            this.WhenAnyValue(x => x.PullRequestFile.Patch)
            .IsNotNull()
            .ToProperty(this, x => x.Patch, out _patch);

            var comments = new ReactiveList <PullRequestReviewComment>();

            Comments = comments.CreateDerivedCollection(
                x => new FileDiffCommentViewModel(x.User.Login, x.User.AvatarUrl, x.Body, x.Position ?? 0));

            this.WhenAnyValue(x => x.ParentViewModel.Comments)
            .Merge(this.WhenAnyObservable(x => x.ParentViewModel.Comments.Changed).Select(_ => ParentViewModel.Comments))
            .Select(x => x.Where(y => string.Equals(y.Path, Filename, StringComparison.OrdinalIgnoreCase)).ToList())
            .Subscribe(x => comments.Reset(x));

            this.WhenAnyValue(x => x.PullRequestFile.FileName)
            .ToProperty(this, x => x.Filename, out _filename);

            this.WhenAnyValue(x => x.Filename)
            .Subscribe(x => {
                if (string.IsNullOrEmpty(x))
                {
                    Title = "Diff";
                }
                else
                {
                    Title = Path.GetFileName(Filename) ?? Filename.Substring(Filename.LastIndexOf('/') + 1);
                }
            });
        }
示例#9
0
        public IObservable<PullRequestReviewComment> CreatePullRequestReviewComment(
            string owner,
            string name,
            int number,
            string body,
            string commitId,
            string path,
            int position)
        {
            Guard.ArgumentNotEmptyString(owner, nameof(owner));
            Guard.ArgumentNotEmptyString(name, nameof(name));
            Guard.ArgumentNotEmptyString(body, nameof(body));
            Guard.ArgumentNotEmptyString(commitId, nameof(commitId));
            Guard.ArgumentNotEmptyString(path, nameof(path));

            var comment = new PullRequestReviewCommentCreate(body, commitId, path, position);
            return gitHubClient.PullRequest.ReviewComment.Create(owner, name, number, comment);
        }
            public async Task EnsuresArgumentsNotNull()
            {
                var gitHubClient = Substitute.For <IGitHubClient>();
                var client       = new ObservablePullRequestReviewCommentsClient(gitHubClient);

                string body     = "Comment content";
                string commitId = "qe3dsdsf6";
                string path     = "file.css";
                int    position = 7;

                var comment = new PullRequestReviewCommentCreate(body, commitId, path, position);

                await AssertEx.Throws <ArgumentNullException>(async() => await client.Create(null, "name", 1, comment));

                await AssertEx.Throws <ArgumentException>(async() => await client.Create("", "name", 1, comment));

                await AssertEx.Throws <ArgumentNullException>(async() => await client.Create("owner", null, 1, comment));

                await AssertEx.Throws <ArgumentException>(async() => await client.Create("owner", "", 1, comment));

                await AssertEx.Throws <ArgumentNullException>(async() => await client.Create("owner", "name", 1, null));
            }
示例#11
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
            ILogger log)
        {
            string pullRequestId = req.Query["pullRequestId"];
            string projectKey    = req.Query["projectKey"];
            string commitId      = req.Query["commitId"];

            log.LogInformation($"PullRequestId: {pullRequestId} ProjectKey: {projectKey}");

            SearchIssue issues = null;

            using (HttpResponseMessage response = await client.GetAsync(
                       $"https://sonarcloud.io/api/issues/search?pullRequest={pullRequestId}&projects=TsuyoshiUshio_VulnerableApp"))
            {
                response.EnsureSuccessStatusCode();
                string responseBody = await response.Content.ReadAsStringAsync();

                Console.WriteLine(responseBody);
                issues = JsonConvert.DeserializeObject <SearchIssue>(responseBody);
            }

            foreach (var issue in issues.issues)
            {
                var path = issue.component.Replace("TsuyoshiUshio_VulnerableApp:", "");

                if (path != "TsuyoshiUshio_VulnerableApp")
                {
                    var comment = new PullRequestReviewCommentCreate($"[{issue.type}] {issue.message}", commitId, path, 5);
                    await gitHubClient.PullRequest.ReviewComment.Create("TsuyoshiUshio", "VulnerableApp", int.Parse(pullRequestId), comment);
                }
                {
                    //  var comment = new PullRequestReviewCommentCreate(issue.message, commitId, "TsuyoshiUshio_VulnerableApp", issue.line);
                    //  await gitHubClient.PullRequest.ReviewComment.Create("TsuyoshiUshio", "VulnerableApp", int.Parse(pullRequestId), comment);
                }
            }

            return((ActionResult) new OkObjectResult($"Done"));
        }
示例#12
0
        public async Task EnsuresArgumentsNotNull()
        {
            var connection = Substitute.For <IApiConnection>();
            var client     = new PullRequestReviewCommentsClient(connection);

            string body     = "Comment content";
            string commitId = "qe3dsdsf6";
            string path     = "file.css";
            int    position = 7;

            var comment = new PullRequestReviewCommentCreate(body, commitId, path, position);

            await Assert.ThrowsAsync <ArgumentNullException>(() => client.Create(null, "fakeRepoName", 1, comment));

            await Assert.ThrowsAsync <ArgumentException>(() => client.Create("", "fakeRepoName", 1, comment));

            await Assert.ThrowsAsync <ArgumentNullException>(() => client.Create("fakeOwner", null, 1, comment));

            await Assert.ThrowsAsync <ArgumentException>(() => client.Create("fakeOwner", "", 1, comment));

            await Assert.ThrowsAsync <ArgumentNullException>(() => client.Create("fakeOwner", "fakeRepoName", 1, null));
        }
        /// <summary>
        /// Creates a comment on a pull request review.
        /// </summary>
        /// <remarks>http://developer.github.com/v3/pulls/comments/#create-a-comment</remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="number">The Pull Request number</param>
        /// <param name="comment">The comment</param>
        public IObservable <PullRequestReviewComment> Create(int repositoryId, int number, PullRequestReviewCommentCreate comment)
        {
            Ensure.ArgumentNotNull(comment, "comment");

            return(_client.Create(repositoryId, number, comment).ToObservable());
        }
            public async Task EnsuresNonNullArguments()
            {
                var gitHubClient = Substitute.For<IGitHubClient>();
                var client = new ObservablePullRequestReviewCommentsClient(gitHubClient);

                string body = "Comment content";
                string commitId = "qe3dsdsf6";
                string path = "file.css";
                int position = 7;

                var comment = new PullRequestReviewCommentCreate(body, commitId, path, position);

                Assert.Throws<ArgumentNullException>(() => client.Create(null, "name", 1, comment));
                Assert.Throws<ArgumentNullException>(() => client.Create("owner", null, 1, comment));
                Assert.Throws<ArgumentNullException>(() => client.Create("owner", "name", 1, null));

                Assert.Throws<ArgumentNullException>(() => client.Create(1, 1, null));

                Assert.Throws<ArgumentException>(() => client.Create("", "name", 1, comment));
                Assert.Throws<ArgumentException>(() => client.Create("owner", "", 1, comment));
            }
            public void PostsToCorrectUrlWithRepositoryId()
            {
                var gitHubClient = Substitute.For<IGitHubClient>();
                var client = new ObservablePullRequestReviewCommentsClient(gitHubClient);

                var comment = new PullRequestReviewCommentCreate("Comment content", "qe3dsdsf6", "file.css", 7);

                client.Create(1, 13, comment);

                gitHubClient.PullRequest.ReviewComment.Received().Create(1, 13, comment);
            }
示例#16
0
        public Task <PullRequestReviewComment> CreatePullRequestReviewComment(Comment comment)
        {
            var reviewComment = new PullRequestReviewCommentCreate(comment.Body, comment.CommitId, comment.Path, comment.Position);

            return(client.PullRequest.ReviewComment.Create(comment.RepositoryOnwer, comment.RepositoryName, int.Parse(comment.PullRequestId), reviewComment));
        }
        /// <summary>
        /// Creates a comment on a pull request review.
        /// </summary>
        /// <remarks>http://developer.github.com/v3/pulls/comments/#create-a-comment</remarks>
        /// <param name="owner">The owner of the repository</param>
        /// <param name="name">The name of the repository</param>
        /// <param name="number">The Pull Request number</param>
        /// <param name="comment">The comment</param>
        /// <returns>The created <see cref="PullRequestReviewComment"/></returns>
        public IObservable<PullRequestReviewComment> Create(string owner, string name, int number, PullRequestReviewCommentCreate comment)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "name");
            Ensure.ArgumentNotNull(comment, "comment");

            return _client.Create(owner, name, number, comment).ToObservable();
        }
        /// <summary>
        /// Creates a comment on a pull request review.
        /// </summary>
        /// <remarks>http://developer.github.com/v3/pulls/comments/#create-a-comment</remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="number">The Pull Request number</param>
        /// <param name="comment">The comment</param>
        public IObservable<PullRequestReviewComment> Create(long repositoryId, int number, PullRequestReviewCommentCreate comment)
        {
            Ensure.ArgumentNotNull(comment, "comment");

            return _client.Create(repositoryId, number, comment).ToObservable();
        }
        /// <summary>
        /// Creates a comment on a pull request review.
        /// </summary>
        /// <remarks>http://developer.github.com/v3/pulls/comments/#create-a-comment</remarks>
        /// <param name="owner">The owner of the repository</param>
        /// <param name="name">The name of the repository</param>
        /// <param name="number">The Pull Request number</param>
        /// <param name="comment">The comment</param>
        public IObservable <PullRequestReviewComment> Create(string owner, string name, int number, PullRequestReviewCommentCreate comment)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "name");
            Ensure.ArgumentNotNull(comment, "comment");

            return(_client.Create(owner, name, number, comment).ToObservable());
        }