コード例 #1
0
        public async Task Orchestrator(
            [OrchestrationTrigger] IDurableOrchestrationContext context)
        {
            var cIContext = context.GetInput <CIContext>();
            // Get issues
            SearchIssue issues = await context.CallActivityAsync <SearchIssue>(nameof(CreatePRReviewDecorator) + "_GetIssues", cIContext);

            // Get issues that already created
            var pullRequestState =
                await context.CallActivityAsync <PullRequestState>("PullRequestStateUtility_GetPullRequestState", new PullRequestStateKey
            {
                PartitionKey = _repositoryContext.GetFullNameWithUnderscore(),
                RowKey       = cIContext.PullRequestId
            });

            string entityId = pullRequestState?.EntityId ?? context.NewGuid().ToString();
            EntityStateResponse <PullRequestStateContext> response =
                await context.CallActivityAsync <EntityStateResponse <PullRequestStateContext> >(
                    nameof(CreatePRReviewDecorator) + "_GetPullRequestStateContext", entityId);

            var pullRequestDetailContext = response.EntityState;

            pullRequestDetailContext = pullRequestDetailContext ?? new PullRequestStateContext()
            {
                PullRequestNumber = int.Parse(cIContext.PullRequestId)
            };

            var unCommentedIssue = issues.issues.Where(issue => !pullRequestDetailContext.CreatedReviewComment.Contains(new CreatedReviewComment()
            {
                IssueId = issue.key
            })).ToList();


            foreach (var issue in unCommentedIssue)
            {
                var issueContext           = (cIContext, issue);
                var createdPrReviewComment = await context.CallActivityAsync <JObject>(nameof(CreatePRReviewDecorator) + "_CreatePRReviewComment", issueContext);

                if (createdPrReviewComment != null)
                {
                    pullRequestDetailContext.Add(new CreatedReviewComment()
                    {
                        IssueId = issue.key, CommentId = (int)createdPrReviewComment["Id"], ProjectKey = cIContext.ProjectKey
                    });
                }
            }


            await context.CallEntityAsync <PullRequestStateContext>(new EntityId(nameof(PullRequestEntity), entityId), "update", pullRequestDetailContext);

            pullRequestState              = pullRequestState ?? new PullRequestState();
            pullRequestState.EntityId     = entityId;
            pullRequestState.PartitionKey = pullRequestState.PartitionKey ??
                                            _repositoryContext.Owner + "_" + _repositoryContext.Name;
            pullRequestState.RowKey = pullRequestState.RowKey ?? cIContext.PullRequestId;

            await context.CallActivityAsync("PullRequestStateUtility_CreateOrUpdatePullRequestState", pullRequestState);
        }
コード例 #2
0
        private void buttonSearch_Click(object sender, EventArgs e)
        {
            TreeNodeWithServer node = filtersTree.SelectedNode as TreeNodeWithServer;

            if (node == null)
            {
                return;
            }
            SearchIssue dlg = new SearchIssue(node.Server, model, status);

            dlg.ShowDialog(this);
        }
コード例 #3
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"));
        }