コード例 #1
0
        protected override async Task HandleCoreAsync(HandlerContext <IssueCommentPayload> context, CancellationToken cancellationToken)
        {
            var payload        = context.Payload;
            var installationId = payload.Installation.Id;
            var repositoryId   = payload.Repository.Id;
            var comment        = payload.Comment.Body.ToLower().Trim();
            var issueId        = payload.Issue.Number;

            // Bail early if we aren't even a check enforcer comment. Reduces exception noise.
            if (!comment.StartsWith("/check-enforcer"))
            {
                return;
            }

            await Limiter.WaitForGitHubCapacityAsync();

            var pullRequest = await context.Client.PullRequest.Get(repositoryId, issueId);

            var sha = pullRequest.Head.Sha;

            switch (comment)
            {
            case "/check-enforcer override":
                await SetSuccessAsync(context.Client, repositoryId, sha, cancellationToken);

                break;

            case "/check-enforcer reset":
                await CreateCheckAsync(context.Client, installationId, repositoryId, sha, true, cancellationToken);
                await EvaluatePullRequestAsync(context.Client, installationId, repositoryId, sha, cancellationToken);

                break;

            case "/check-enforcer evaluate":
                await CreateCheckAsync(context.Client, installationId, repositoryId, sha, true, cancellationToken);
                await EvaluatePullRequestAsync(context.Client, installationId, repositoryId, sha, cancellationToken);

                break;

            default:
                this.Logger.LogInformation("Unrecognized command: {comment}", comment);
                break;
            }
        }