示例#1
0
        public async Task Orchestrator(
            [OrchestrationTrigger] IDurableOrchestrationContext context)
        {
            var commandHookContext = context.GetInput <CommandHookContext>();

            var response = await context.CallActivityAsync <EntityStateResponse <PullRequestStateContext> >(nameof(PullRequestEntity) + "_GetPullRequestStateContext", commandHookContext.PullRequestUri.GetEntityId());

            // Ignore if the Decoration has not finished.
            if (response.EntityExists)
            {
                PullRequestStateContext pullRequestStateContext = response.EntityState;
                switch (CommandRouter.GetValueOrDefault(commandHookContext.Command))
                {
                case CommandRouter.CreateWorkItemCommand:
                    // GetIssue that match Scan Provider. You can find the ScanProvider from response.
                    await CreateWorkItem(context, pullRequestStateContext, commandHookContext);

                    break;

                case CommandRouter.IssueTransitionCommand:
                    await TransitIssueAsync(context, pullRequestStateContext, commandHookContext);

                    break;

                default:
                    // Create Sorry Comment
                    await context.CallActivityAsync(nameof(CommandOrchestrator) + "_" + BotConfiguration.RepositoryProvider +
                                                    "_CreateSimpleReplyComment", new CreateSimpleReplyCommentContext()
                    {
                        Body          = $"Command [{commandHookContext.Command}] hasn't been supported. Ask bot administrator.",
                        InReplyTo     = commandHookContext.ReplyToId,
                        PullRequestId = commandHookContext.PullRequestId
                    });

                    break;
                }
                // Update the CurrentPullRequestStatus
                await context.CallEntityAsync <PullRequestStateContext>(
                    new EntityId(nameof(PullRequestEntity), commandHookContext.PullRequestUri.GetEntityId()), "update",
                    pullRequestStateContext);
            }
            else
            {
                await context.CallActivityAsync(nameof(CommandOrchestrator) + "_" + BotConfiguration.RepositoryProvider +
                                                "_CreateSimpleReplyComment", new CreateSimpleReplyCommentContext()
                {
                    Body          = "Security Decoration seems not finished. Wait until the PullRequest validation CI has done.",
                    InReplyTo     = commandHookContext.ReplyToId,
                    PullRequestId = commandHookContext.PullRequestId
                });
            }
        }
示例#2
0
        private async Task TransitIssueAsync(IDurableOrchestrationContext context,
                                             PullRequestStateContext pullRequestStateContext,
                                             CommandHookContext commandHookContext)
        {
            // GetIssue that match Scan Provider
            CreatedReviewComment parentReviewComment =
                GetParentReviewCommentAsync(pullRequestStateContext, commandHookContext);

            var issue = await GetIssueAsync(context, pullRequestStateContext, parentReviewComment);

            // Update the Issue state

            if (issue.Status == "OPEN" || issue.Status == "REOPEN")
            {
                await context.CallActivityAsync(nameof(CommandOrchestrator) + "_" + parentReviewComment.ScanProvider +
                                                "_TransitIssue", new TransitIssueContext()
                {
                    CreatedReviewComment = parentReviewComment,
                    Transition           = CommandRouter.GetTransition(commandHookContext.Command),
                    Issue = issue
                });

                // Create Comment that match Repository Provider

                await context.CallActivityAsync(
                    nameof(CommandOrchestrator) + "_" + BotConfiguration.RepositoryProvider +
                    "_CreateIssueTransitionReplyComment", new CreateIssueTransitionReplyCommentContext()
                {
                    PullRequestId = commandHookContext.PullRequestId,
                    InReplyTo     = commandHookContext.ReplyToId,
                    Command       = commandHookContext.Command,
                    Issue         = issue
                });
            }
            else // Issue is already resolved or confirmed
            {
                await context.CallActivityAsync(nameof(CommandOrchestrator) + "_" + BotConfiguration.RepositoryProvider +
                                                "_CreateSimpleReplyComment", new CreateSimpleReplyCommentContext()
                {
                    Body          = "The issue is already resolved or confirmed.",
                    InReplyTo     = commandHookContext.ReplyToId,
                    PullRequestId = commandHookContext.PullRequestId
                });
            }
        }