示例#1
0
        public async Task <IActionResult> Post([FromBody] WebHookModel model)
        {
            var unityCloudBuildEvent = GetUnityCloudBuildEventHeaderValue();

            if (unityCloudBuildEvent == null)
            {
                return(BadRequest());
            }

            if (unityCloudBuildEvent != "ProjectBuildSuccess")
            {
                return(Ok());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                await _slackClient.PostStartedAsync(
                    model.ProjectName,
                    model.BuildTargetName,
                    model.BuildNumber,
                    model.StartedBy);

                await _buildService.HandleAsync(model, _environment.WebRootPath);

                await _slackClient.PostSuccessAsync(
                    model.ProjectName,
                    model.BuildTargetName,
                    model.BuildNumber,
                    model.StartedBy);
            }
            catch (Exception e)
            {
                _logger.LogError(e.ToString());

                await _slackClient.PostFailureAsync(
                    model.ProjectName,
                    model.BuildTargetName,
                    model.BuildNumber,
                    model.StartedBy);

                throw;
            }

            return(Ok());
        }