Exemplo n.º 1
0
        public async Task InvalidData_Doesnt_Trigger_Pipeline(GitHubEvent gitHubEvent)
        {
            var actionResult = await _function.RunAsync(gitHubEvent, NullLogger.Instance);

            actionResult.ShouldBeOfType(typeof(OkResult));
            _pipelineOperatorMock.Verify(op => op.TriggerPipelineAsync(It.IsAny <PipelineTriggerParameters>()),
                                         Times.Never);
        }
Exemplo n.º 2
0
        public ActionResult Post()
        {
            GitHubEvent evt = HttpContext.Request.GetGitHubEvent();

            Console.WriteLine(evt.GetType().Name + " received");

            return(Ok());
        }
Exemplo n.º 3
0
        public async Task Valid_Input_Triggers_Pipeline()
        {
            var gitHubEvent = new GitHubEvent
            {
                Ref      = "feature/abcd-123",
                Ref_Type = "branch"
            };
            var actionResult = await _function.RunAsync(gitHubEvent, NullLogger.Instance);

            actionResult.ShouldBeOfType(typeof(OkResult));

            _pipelineOperatorMock.Verify(op => op.TriggerPipelineAsync(It.Is <PipelineTriggerParameters>(
                                                                           parameters => parameters.PipelineName == "cleanup-resources" &&
                                                                           parameters.Parameters.Contains("feature-abcd-123")
                                                                           )), Times.Once);
        }
Exemplo n.º 4
0
        public async Task <IActionResult> RunAsync(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]
            GitHubEvent gitHubEvent, ILogger log)
        {
            if (gitHubEvent is null || gitHubEvent.Ref is null || !gitHubEvent.Ref.StartsWith("feature/") || gitHubEvent.Ref_Type != "branch")
            {
                log.LogInformation("unknown event payload, going to skip");
                return(new OkResult());
            }

            var branchName        = gitHubEvent.Ref.Replace('/', '-');
            var triggerParameters = new PipelineTriggerParameters
            {
                Parameters   = $"{{\"branchName\":\"{branchName}\"}}",
                PipelineName = PipelineName
            };

            await _pipelineOperator.TriggerPipelineAsync(triggerParameters).ConfigureAwait(false);

            return(new OkResult());
        }