Commit ba27f1b9 authored by Shinya Maeda's avatar Shinya Maeda

Expose only status. ci_cd_status to status. Support abstract class.

parent 0e06cfc0
...@@ -73,8 +73,14 @@ class Projects::BuildsController < Projects::ApplicationController ...@@ -73,8 +73,14 @@ class Projects::BuildsController < Projects::ApplicationController
redirect_to build_path(@build) redirect_to build_path(@build)
end end
# def status
# render json: @build.to_json(only: [:status, :id, :sha, :coverage], methods: :sha)
# end
def status 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 end
def erase def erase
...@@ -91,12 +97,6 @@ class Projects::BuildsController < Projects::ApplicationController ...@@ -91,12 +97,6 @@ class Projects::BuildsController < Projects::ApplicationController
end end
end end
def ci_cd_status
render json: BuildSerializer
.new(project: @project, user: @current_user)
.represent(@build)
end
private private
def build def build
......
...@@ -10,7 +10,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -10,7 +10,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
before_action :module_enabled before_action :module_enabled
before_action :merge_request, only: [ before_action :merge_request, only: [
:edit, :update, :show, :diffs, :commits, :conflicts, :conflict_for_path, :pipelines, :merge, :merge_check, :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 :validates_merge_request, only: [:show, :diffs, :commits, :pipelines]
before_action :define_show_vars, only: [:show, :diffs, :commits, :conflicts, :conflict_for_path, :builds, :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 ...@@ -473,9 +473,10 @@ class Projects::MergeRequestsController < Projects::ApplicationController
render json: response render json: response
end end
def ci_cd_status def status
render json: PipelineSerializer render json: PipelineSerializer
.new(project: @project, user: @current_user) .new(project: @project, user: @current_user)
.with_status
.represent(@merge_request.head_pipeline) .represent(@merge_request.head_pipeline)
end end
......
...@@ -72,9 +72,10 @@ class Projects::PipelinesController < Projects::ApplicationController ...@@ -72,9 +72,10 @@ class Projects::PipelinesController < Projects::ApplicationController
end end
end end
def ci_cd_status def status
render json: PipelineSerializer render json: PipelineSerializer
.new(project: @project, user: @current_user) .new(project: @project, user: @current_user)
.with_status
.represent(@pipeline) .represent(@pipeline)
end end
......
...@@ -19,15 +19,21 @@ class BuildEntity < Grape::Entity ...@@ -19,15 +19,21 @@ class BuildEntity < Grape::Entity
expose :created_at expose :created_at
expose :updated_at expose :updated_at
expose :status do |build, options| expose :details do
StatusEntity.represent( expose :detailed_status,
build.detailed_status(request.user), as: :status,
options) with: StatusEntity
end end
private private
alias_method :build, :object
def path_to(route, build) def path_to(route, build)
send("#{route}_path", build.project.namespace, build.project, build) send("#{route}_path", build.project.namespace, build.project, build)
end end
def detailed_status
build.detailed_status(request.user)
end
end end
class BuildSerializer < BaseSerializer class BuildSerializer < BaseSerializer
entity BuildEntity 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 end
...@@ -12,11 +12,9 @@ class PipelineEntity < Grape::Entity ...@@ -12,11 +12,9 @@ class PipelineEntity < Grape::Entity
end end
expose :details do expose :details do
expose :status do |pipeline, options| expose :detailed_status,
StatusEntity.represent( as: :status,
pipeline.detailed_status(request.user), with: StatusEntity
options)
end
expose :duration expose :duration
expose :finished_at expose :finished_at
...@@ -82,4 +80,8 @@ class PipelineEntity < Grape::Entity ...@@ -82,4 +80,8 @@ class PipelineEntity < Grape::Entity
pipeline.cancelable? && pipeline.cancelable? &&
can?(request.user, :update_pipeline, pipeline) can?(request.user, :update_pipeline, pipeline)
end end
def detailed_status
pipeline.detailed_status(request.user)
end
end end
...@@ -11,11 +11,19 @@ class PipelineSerializer < BaseSerializer ...@@ -11,11 +11,19 @@ class PipelineSerializer < BaseSerializer
@paginator.present? @paginator.present?
end end
def with_status
tap { @status_only = {only: [{details: [:status]}]} }
end
def represent(resource, opts = {}) def represent(resource, opts = {})
if resource.is_a?(ActiveRecord::Relation) if resource.is_a?(ActiveRecord::Relation)
resource = resource.includes(project: :namespace) resource = resource.includes(project: :namespace)
end end
if @status_only.present?
opts.merge!(@status_only)
end
if paginated? if paginated?
super(@paginator.paginate(resource), opts) super(@paginator.paginate(resource), opts)
else else
......
...@@ -102,7 +102,7 @@ constraints(ProjectUrlConstrainer.new) do ...@@ -102,7 +102,7 @@ constraints(ProjectUrlConstrainer.new) do
get :merge_widget_refresh get :merge_widget_refresh
post :cancel_merge_when_pipeline_succeeds post :cancel_merge_when_pipeline_succeeds
get :ci_status get :ci_status
get :ci_cd_status get :status
get :ci_environments_status get :ci_environments_status
post :toggle_subscription post :toggle_subscription
post :remove_wip post :remove_wip
...@@ -153,7 +153,7 @@ constraints(ProjectUrlConstrainer.new) do ...@@ -153,7 +153,7 @@ constraints(ProjectUrlConstrainer.new) do
post :cancel post :cancel
post :retry post :retry
get :builds get :builds
get :ci_cd_status get :status
end end
end end
...@@ -205,7 +205,6 @@ constraints(ProjectUrlConstrainer.new) do ...@@ -205,7 +205,6 @@ constraints(ProjectUrlConstrainer.new) do
post :erase post :erase
get :trace get :trace
get :raw get :raw
get :ci_cd_status
end end
resource :artifacts, only: [] do resource :artifacts, only: [] do
......
...@@ -18,6 +18,10 @@ module Gitlab ...@@ -18,6 +18,10 @@ module Gitlab
raise NotImplementedError raise NotImplementedError
end end
def favicon
raise NotImplementedError
end
def label def label
raise NotImplementedError raise NotImplementedError
end end
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment