private async Task <WebhookResponse> HandleSynchronizeEvent(PullRequestEvent payload)
        {
            var owner           = payload.Repository.Owner.Login;
            var repo            = payload.Repository.Name;
            var prId            = payload.Number;
            var sha             = payload.PullRequest.Head.Sha;
            var extraLoggerData = new { owner, repo, prId, sha };


            var mergeRequest = await mergeRequestRepository.Get(owner, repo, prId);

            if (mergeRequest == null)
            {
                logger.WithExtraData(extraLoggerData).Information("Synchronize event on unknown Pull Request, ignore");
                return(new WebhookResponse(false, "Synchronize event on unknown Pull Request, ignore"));
            }

            var config = await repoConfigManager.GetConfig(owner, repo);

            logger.WithMergeRequestData(mergeRequest).Information("Handling synchronize event, updating sha");

            var updatedMergeRequest = await mergeRequestRepository.UpdateShaAndClearStatusChecks(mergeRequest.Owner, mergeRequest.Repo, mergeRequest.PrId, sha);

            if (config.IsWhitelistStrict() && updatedMergeRequest.ReceivedMergeCommand)
            {
                logger.WithMergeRequestData(updatedMergeRequest).Information("Repository has a whitelist-strict merge policy, resolving miro check on PR");
                await miroMergeCheck.ResolveMiroMergeCheck(updatedMergeRequest);
            }

            return(new WebhookResponse(true, "Handling synchronize event, sha updated"));
        }
Exemple #2
0
        private async Task <WebhookResponse> HandlePushOnPr(PushEvent payload, RepoConfig config)
        {
            var owner        = payload.Repository.Owner.Login;
            var repo         = payload.Repository.Name;
            var sha          = payload.After;
            var branch       = payload.Ref;
            var extraLogData = new { owner, repo, branch, sha };

            var strippedBranchName = branch.Substring("refs/heads/".Length);
            var mergeRequest       = await mergeRequestRepository.GetByBranchName(owner, repo, strippedBranchName);

            if (mergeRequest == null)
            {
                logger.WithExtraData(extraLogData).Information("Push on branch, does not exist in Miro DB, ignoring");
                return(new WebhookResponse(false, "Push on branch, does not exist in Miro DB, ignoring"));
            }

            logger.WithMergeRequestData(mergeRequest).Information($"Push on branch found in DB, Clearing status checks and updating sha");

            var updatedMergeRequest = await mergeRequestRepository.UpdateShaAndClearStatusChecks(mergeRequest.Owner, mergeRequest.Repo, mergeRequest.PrId, sha);

            if (config.IsWhitelistStrict() && updatedMergeRequest.ReceivedMergeCommand)
            {
                logger.WithMergeRequestData(updatedMergeRequest).Information("Repository has a whitelist-strict merge policy, resolving miro check on PR");
                await miroMergeCheck.ResolveMiroMergeCheck(updatedMergeRequest);
            }

            return(new WebhookResponse(true, $"Push on branch is a known PR, updated sha to {sha} and cleared status checks"));
        }