Esempio n. 1
0
        private void AddComment(PullRequestReviewComment reviewComment)
        {
            var comments = _comments.ToList();

            comments.Add(reviewComment);
            Comments = new ReadOnlyCollection <PullRequestReviewComment>(comments);
        }
Esempio n. 2
0
        public async Task <JObject> CreatePRReviewCommentAsync(
            [ActivityTrigger] IDurableActivityContext context)
        {
            var issueContext = context.GetInput <Tuple <CIContext, PullRequestLibrary.Generated.SonarCloud.SearchIssue.Issue> >();
            var cIContext    = issueContext.Item1;
            var issue        = issueContext.Item2;

            var path = issue.component.Replace($"{cIContext.ProjectKey}:", "");

            if (path != cIContext.ProjectKey)
            {
                PullRequestReviewComment result = await _gitHubRepository.CreatePullRequestReviewComment(
                    new PullRequestLibrary.Model.Comment
                {
                    Body            = $"**{issue.type}**\n> {issue.message}\n See [details](https://sonarcloud.io/project/issues?id={cIContext.ProjectKey}&open={issue.key}&pullRequest={cIContext.PullRequestId}&resolved=false)",
                    RepositoryOnwer = _repositoryContext.Owner,
                    RepositoryName  = _repositoryContext.Name,
                    CommitId        = cIContext.CommitId,
                    Path            = path,
                    Position        = 5,
                    PullRequestId   = cIContext.PullRequestId
                });

                var json = JsonConvert.SerializeObject(result);
                return(JObject.Parse(json));
            }

            return(null);
        }
Esempio n. 3
0
 public PullRequestReviewCommentCacheItem(PullRequestReviewComment comment)
 {
     Id               = comment.Id;
     Path             = comment.Path;
     Position         = comment.Position;
     OriginalPosition = comment.OriginalPosition;
     CommitId         = comment.CommitId;
     OriginalCommitId = comment.OriginalCommitId;
     DiffHunk         = comment.DiffHunk;
     User             = new AccountCacheItem(comment.User);
     Body             = comment.Body;
     CreatedAt        = comment.CreatedAt;
 }
Esempio n. 4
0
 public static Comment FromPullRequestReviewComment(this PullRequestReviewComment prComment)
 {
     return(new Comment
     {
         Id = prComment.Id,
         HtmlUrl = prComment.HtmlUrl,
         Text = prComment.Body,
         CreatedAt = prComment.CreatedAt,
         UpdatedAt = prComment.UpdatedAt,
         User = new User
         {
             Id = prComment.User.Id.ToString(),
             Login = prComment.User.Login,
         },
     });
 }
Esempio n. 5
0
        public async Task <CreatedReviewComment> CreateCommentsAsync([ActivityTrigger] IDurableActivityContext context, ILogger logger)
        {
            var commentContext = context.GetInput <CreateReviewCommentContext>();


            if (commentContext.Issue.Path != null)
            {
                PullRequestReviewComment result = await _repository.CreatePullRequestReviewComment(
                    new Comment
                {
                    Body            = $"**{commentContext.Issue.Type}**\n> {commentContext.Issue.Message}\n See [details]({commentContext.Issue.Url})",
                    RepositoryOnwer = _context.Owner,
                    RepositoryName  = _context.Name,
                    CommitId        = commentContext.DecoratorContext.CommitId,
                    Path            = commentContext.Issue.Path,
                    Position        = 5,
                    PullRequestId   = commentContext.DecoratorContext.PullRequestId
                });

                return(new CreatedReviewComment()
                {
                    IssueId = commentContext.Issue.Id,
                    CommentId = result.Id.ToString(),
                    ScanProvider = commentContext.Issue.Provider,
                    Tag = commentContext.DecoratorContext.Tag
                });
            }
            else
            {
                // GitHub, Pull Request Comment without Code is issue comment.
                IssueComment result = await _repository.CreatePullRequestIssueComment(
                    int.Parse(commentContext.DecoratorContext.PullRequestId),
                    $"**{commentContext.Issue.Type}**\n> {commentContext.Issue.Message}\n See [details]({commentContext.Issue.Url})");

                return(new CreatedReviewComment()
                {
                    IssueId = commentContext.Issue.Id,
                    CommentId = "_issue_" + result.Id.ToString(),
                    ScanProvider = commentContext.Issue.Provider,
                    Tag = commentContext.DecoratorContext.Tag
                });
            }
        }
Esempio n. 6
0
 static void AssertComment(PullRequestReviewComment comment, string body, int position)
 {
     Assert.NotNull(comment);
     Assert.Equal(body, comment.Body);
     Assert.Equal(position, comment.Position);
 }
Esempio n. 7
0
        public static JObject ToJObject(this PullRequestReviewComment comment)
        {
            var json = JsonConvert.SerializeObject(comment);

            return(JObject.Parse(json));
        }