Ejemplo n.º 1
0
 public async Task ProcessPayload(CheckSuiteEventPayload payload, IGitHubManager gitHubManager, CancellationToken cancellationToken)
 {
     if (payload.Action != "requested" || payload.Action != "rerequested")
     {
         return;
     }
     if (payload.CheckSuite.PullRequests.Any())
     {
         foreach (var I in payload.CheckSuite.PullRequests)
         {
             backgroundJobClient.Enqueue(() => ScanPullRequest(payload.Repository.Id, I.Number, JobCancellationToken.Null));
         }
     }
     else
     {
         var now = DateTimeOffset.Now;
         var nmc = stringLocalizer[NaprLocalize];
         await gitHubManager.CreateCheckRun(payload.Repository.Id, new NewCheckRun
         {
             CompletedAt = now,
             StartedAt   = now,
             Conclusion  = CheckConclusion.Neutral,
             HeadBranch  = payload.CheckSuite.HeadBranch,
             HeadSha     = payload.CheckSuite.HeadSha,
             Name        = nmc,
             Output      = new CheckRunOutput(nmc, String.Empty, null, null, null),
             Status      = CheckStatus.Completed
         }, cancellationToken).ConfigureAwait(false);
     }
 }
Ejemplo n.º 2
0
        /// <inheritdoc />
        public void ProcessPayload(CheckSuiteEventPayload payload)
        {
            if (payload.Action != "rerequested")
            {
                return;
            }

            backgroundJobClient.Enqueue(() => ScanCheckSuite(payload.Repository.Id, payload.CheckSuite.Id, payload.CheckSuite.HeadSha, JobCancellationToken.Null));
        }
Ejemplo n.º 3
0
        /// <inheritdoc />
        public void ProcessPayload(CheckSuiteEventPayload payload)
        {
            if (payload.Action != "rerequested")
            {
                return;
            }

            //don't rely on CheckSuite.PullRequests, it doesn't include PRs from forks.
            backgroundJobClient.Enqueue(() => ScanCheckSuite(payload.Repository.Id, payload.Installation.Id, payload.CheckSuite.Id, payload.CheckSuite.HeadSha, JobCancellationToken.Null));
        }
Ejemplo n.º 4
0
        public CheckSuiteRequestHandler(CheckSuiteEventPayload payload, IPrivateKeySource keySource, Guid requestId)
        {
            if (payload == null)
            {
                throw new ArgumentNullException(nameof(payload));
            }

            if (keySource == null)
            {
                throw new ArgumentNullException(nameof(keySource));
            }

            GithubInstallationId = payload.Installation.Id;
            CurrentRepository    = payload.Repository;
            CommitSha            = payload.CheckSuite.HeadSha;
            IsPullRequest        = false;
            RequestId            = requestId;
            Init(keySource);
        }
Ejemplo n.º 5
0
        public ActionResult Default()
        {
            string actionName = Request.Headers.Get("X-GITHUB-EVENT");

            // Only the below events will be handled
            if (!actionName.Equals("check_suite", StringComparison.InvariantCultureIgnoreCase) &&
                !actionName.Equals("check_run", StringComparison.InvariantCultureIgnoreCase) &&
                !actionName.Equals("pull_request", StringComparison.InvariantCultureIgnoreCase))
            {
                return(new HttpStatusCodeResult(200));
            }

            // Obtain the body signature
            string messageSignature = Request.Headers.Get("X-HUB-Signature");

            if (string.IsNullOrEmpty(messageSignature))
            {
                return(new HttpStatusCodeResult(400));
            }

            // Read the body
            string body = GetRequestPostData(Request);

            // Validate message integrity
            if (!RequestPayloadHelper.ValidateSender(body, messageSignature, GitScanAppConfig.GetValue(Constants.GlobalSection, Constants.GitHubAppWebhookSecretKey)))
            {
                return(new HttpStatusCodeResult(400));
            }

            Guid requestId = Guid.NewGuid();

            if (actionName.Equals("check_run", StringComparison.InvariantCultureIgnoreCase))
            {
                CheckRunEventPayload checkRunPayload = RequestPayloadHelper.Parse <CheckRunEventPayload>(body);

                if (checkRunPayload.Action.Equals("rerequested", StringComparison.InvariantCultureIgnoreCase))
                {
                    CheckSuiteRequestHandler handler = new CheckSuiteRequestHandler(checkRunPayload, PrivateKeySource.Value, requestId);
                    handler.Go();
                    return(new HttpStatusCodeResult(200));
                }
                else
                {
                    return(new HttpStatusCodeResult(200));
                }
            }

            if (actionName.Equals("pull_request", StringComparison.InvariantCultureIgnoreCase))
            {
                PullRequestEventPayload pullPayload = RequestPayloadHelper.Parse <PullRequestEventPayload>(body);
                if (pullPayload.Action.Equals("opened", StringComparison.InvariantCultureIgnoreCase))
                {
                    CheckSuiteRequestHandler handler = new CheckSuiteRequestHandler(pullPayload, PrivateKeySource.Value, requestId);
                    handler.Go().Wait();
                    return(new HttpStatusCodeResult(200));
                }
                else
                {
                    return(new HttpStatusCodeResult(200));
                }
            }

            CheckSuiteEventPayload payload = RequestPayloadHelper.Parse(body);

            if (!payload.Action.Equals("rerequested", StringComparison.OrdinalIgnoreCase) &&
                (payload.CheckSuite.PullRequests == null || payload.CheckSuite.PullRequests.Count == 0))
            {
                return(new HttpStatusCodeResult(200));
            }

            if (!payload.Action.Equals("completed", StringComparison.OrdinalIgnoreCase))
            {
                CheckSuiteRequestHandler handler = new CheckSuiteRequestHandler(payload, PrivateKeySource.Value, requestId);
                handler.Go();
            }

            return(new HttpStatusCodeResult(200));
        }