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
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
......
......@@ -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
......
......@@ -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
......
......@@ -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
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
......@@ -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
......@@ -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
......
......@@ -102,7 +102,7 @@ constraints(ProjectUrlConstrainer.new) do
get :merge_widget_refresh
post :cancel_merge_when_pipeline_succeeds
get :ci_status
get :ci_cd_status
get :status
get :ci_environments_status
post :toggle_subscription
post :remove_wip
......@@ -153,7 +153,7 @@ constraints(ProjectUrlConstrainer.new) do
post :cancel
post :retry
get :builds
get :ci_cd_status
get :status
end
end
......@@ -205,7 +205,6 @@ constraints(ProjectUrlConstrainer.new) do
post :erase
get :trace
get :raw
get :ci_cd_status
end
resource :artifacts, only: [] do
......
......@@ -18,6 +18,10 @@ module Gitlab
raise NotImplementedError
end
def favicon
raise NotImplementedError
end
def label
raise NotImplementedError
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