示例#1
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);
        }
示例#2
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
                });
            }
        }