diff options
Diffstat (limited to 'app/controllers/projects/pipelines_controller.rb')
-rw-r--r-- | app/controllers/projects/pipelines_controller.rb | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/app/controllers/projects/pipelines_controller.rb b/app/controllers/projects/pipelines_controller.rb index bfe23eb1035..c1734d2cd8a 100644 --- a/app/controllers/projects/pipelines_controller.rb +++ b/app/controllers/projects/pipelines_controller.rb @@ -63,10 +63,27 @@ class Projects::PipelinesController < Projects::ApplicationController .new(project, current_user, create_params) .execute(:web, ignore_skip_ci: true, save_on_errors: false) - if @pipeline.created_successfully? - redirect_to project_pipeline_path(project, @pipeline) - else - render 'new', status: :bad_request + respond_to do |format| + format.html do + if @pipeline.created_successfully? + redirect_to project_pipeline_path(project, @pipeline) + else + render 'new', status: :bad_request + end + end + format.json do + if @pipeline.created_successfully? + render json: PipelineSerializer + .new(project: project, current_user: current_user) + .represent(@pipeline), + status: :created + else + render json: { errors: @pipeline.error_messages.map(&:content), + warnings: @pipeline.warning_messages(limit: ::Gitlab::Ci::Warnings::MAX_LIMIT).map(&:content), + total_warnings: @pipeline.warning_messages.length }, + status: :bad_request + end + end end end @@ -247,7 +264,7 @@ class Projects::PipelinesController < Projects::ApplicationController end def latest_pipeline - @project.latest_pipeline_for_ref(params['ref']) + @project.latest_pipeline(params['ref']) &.present(current_user: current_user) end |