summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/projects/builds_controller.rb14
-rw-r--r--app/controllers/projects/merge_requests_controller.rb5
-rw-r--r--app/controllers/projects/pipelines_controller.rb3
-rw-r--r--app/serializers/build_entity.rb14
-rw-r--r--app/serializers/build_serializer.rb12
-rw-r--r--app/serializers/pipeline_entity.rb12
-rw-r--r--app/serializers/pipeline_serializer.rb8
7 files changed, 49 insertions, 19 deletions
diff --git a/app/controllers/projects/builds_controller.rb b/app/controllers/projects/builds_controller.rb
index 54650bc37a2..8d00f2bf1b2 100644
--- a/app/controllers/projects/builds_controller.rb
+++ b/app/controllers/projects/builds_controller.rb
@@ -73,8 +73,14 @@ class Projects::BuildsController < Projects::ApplicationController
redirect_to build_path(@build)
end
+ # def status
+ # render json: @build.to_json(only: [:status, :id, :sha, :coverage], methods: :sha)
+ # end
def status
- render json: @build.to_json(only: [:status, :id, :sha, :coverage], methods: :sha)
+ render json: BuildSerializer
+ .new(project: @project, user: @current_user)
+ .with_status
+ .represent(@build)
end
def erase
@@ -91,12 +97,6 @@ class Projects::BuildsController < Projects::ApplicationController
end
end
- def ci_cd_status
- render json: BuildSerializer
- .new(project: @project, user: @current_user)
- .represent(@build)
- end
-
private
def build
diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb
index 18b1a5cb395..5087abedf40 100644
--- a/app/controllers/projects/merge_requests_controller.rb
+++ b/app/controllers/projects/merge_requests_controller.rb
@@ -10,7 +10,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
before_action :module_enabled
before_action :merge_request, only: [
:edit, :update, :show, :diffs, :commits, :conflicts, :conflict_for_path, :pipelines, :merge, :merge_check,
- :ci_status, :ci_cd_status, :ci_environments_status, :toggle_subscription, :cancel_merge_when_pipeline_succeeds, :remove_wip, :resolve_conflicts, :assign_related_issues
+ :ci_status, :status, :ci_environments_status, :toggle_subscription, :cancel_merge_when_pipeline_succeeds, :remove_wip, :resolve_conflicts, :assign_related_issues
]
before_action :validates_merge_request, only: [:show, :diffs, :commits, :pipelines]
before_action :define_show_vars, only: [:show, :diffs, :commits, :conflicts, :conflict_for_path, :builds, :pipelines]
@@ -473,9 +473,10 @@ class Projects::MergeRequestsController < Projects::ApplicationController
render json: response
end
- def ci_cd_status
+ def status
render json: PipelineSerializer
.new(project: @project, user: @current_user)
+ .with_status
.represent(@merge_request.head_pipeline)
end
diff --git a/app/controllers/projects/pipelines_controller.rb b/app/controllers/projects/pipelines_controller.rb
index 508d627889c..976827040ac 100644
--- a/app/controllers/projects/pipelines_controller.rb
+++ b/app/controllers/projects/pipelines_controller.rb
@@ -72,9 +72,10 @@ class Projects::PipelinesController < Projects::ApplicationController
end
end
- def ci_cd_status
+ def status
render json: PipelineSerializer
.new(project: @project, user: @current_user)
+ .with_status
.represent(@pipeline)
end
diff --git a/app/serializers/build_entity.rb b/app/serializers/build_entity.rb
index 531b3768da3..10151d94e68 100644
--- a/app/serializers/build_entity.rb
+++ b/app/serializers/build_entity.rb
@@ -19,15 +19,21 @@ class BuildEntity < Grape::Entity
expose :created_at
expose :updated_at
- expose :status do |build, options|
- StatusEntity.represent(
- build.detailed_status(request.user),
- options)
+ expose :details do
+ expose :detailed_status,
+ as: :status,
+ with: StatusEntity
end
private
+ alias_method :build, :object
+
def path_to(route, build)
send("#{route}_path", build.project.namespace, build.project, build)
end
+
+ def detailed_status
+ build.detailed_status(request.user)
+ end
end
diff --git a/app/serializers/build_serializer.rb b/app/serializers/build_serializer.rb
index 637aacc7be5..39460bbd092 100644
--- a/app/serializers/build_serializer.rb
+++ b/app/serializers/build_serializer.rb
@@ -1,3 +1,15 @@
class BuildSerializer < BaseSerializer
entity BuildEntity
+
+ def with_status
+ tap { @status_only = {only: [{details: [:status]}]} }
+ end
+
+ def represent(resource, opts = {})
+ if @status_only.present?
+ opts.merge!(@status_only)
+ end
+
+ super(resource, opts)
+ end
end
diff --git a/app/serializers/pipeline_entity.rb b/app/serializers/pipeline_entity.rb
index 61f0f11d7d2..1c1fa9e3dee 100644
--- a/app/serializers/pipeline_entity.rb
+++ b/app/serializers/pipeline_entity.rb
@@ -12,11 +12,9 @@ class PipelineEntity < Grape::Entity
end
expose :details do
- expose :status do |pipeline, options|
- StatusEntity.represent(
- pipeline.detailed_status(request.user),
- options)
- end
+ expose :detailed_status,
+ as: :status,
+ with: StatusEntity
expose :duration
expose :finished_at
@@ -82,4 +80,8 @@ class PipelineEntity < Grape::Entity
pipeline.cancelable? &&
can?(request.user, :update_pipeline, pipeline)
end
+
+ def detailed_status
+ pipeline.detailed_status(request.user)
+ end
end
diff --git a/app/serializers/pipeline_serializer.rb b/app/serializers/pipeline_serializer.rb
index ab2d3d5a3ec..4de9e620f64 100644
--- a/app/serializers/pipeline_serializer.rb
+++ b/app/serializers/pipeline_serializer.rb
@@ -11,11 +11,19 @@ class PipelineSerializer < BaseSerializer
@paginator.present?
end
+ def with_status
+ tap { @status_only = {only: [{details: [:status]}]} }
+ end
+
def represent(resource, opts = {})
if resource.is_a?(ActiveRecord::Relation)
resource = resource.includes(project: :namespace)
end
+ if @status_only.present?
+ opts.merge!(@status_only)
+ end
+
if paginated?
super(@paginator.paginate(resource), opts)
else