Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZ.J. van de Weg <git@zjvandeweg.nl>2017-05-26 11:31:42 +0300
committerZ.J. van de Weg <git@zjvandeweg.nl>2017-05-31 22:44:53 +0300
commit68569584b728ac2dd5100593e9db302f362994f5 (patch)
tree1558a088e7aa5ad988e30cea791ec938a6d63ded /app/serializers
parent47a0276e53de4635df43124607ac1a101d6f1b70 (diff)
Create PipelineDetailsEntity
Now we have a PipelineEntity which is a bit smaller, mostly in bytes needing to send to the frontend. PipelineDetailsEntity is the default for the PipelineSerializer, limiting the changes needed. This commit also incorporates the review.
Diffstat (limited to 'app/serializers')
-rw-r--r--app/serializers/build_details_entity.rb32
-rw-r--r--app/serializers/build_serializer.rb2
-rw-r--r--app/serializers/pipeline_details_entity.rb21
-rw-r--r--app/serializers/pipeline_entity.rb23
-rw-r--r--app/serializers/pipeline_serializer.rb2
-rw-r--r--app/serializers/runner_entity.rb15
6 files changed, 52 insertions, 43 deletions
diff --git a/app/serializers/build_details_entity.rb b/app/serializers/build_details_entity.rb
index 08c5e69180c..dd5b8388c22 100644
--- a/app/serializers/build_details_entity.rb
+++ b/app/serializers/build_details_entity.rb
@@ -6,29 +6,25 @@ class BuildDetailsEntity < BuildEntity
expose :runner, using: RunnerEntity
expose :pipeline, using: PipelineEntity
- expose :merge_request_path do |build|
- merge_request = build.merge_request
- project = build.project
-
- if merge_request.nil? || !can?(request.current_user, :read_merge_request, project)
- nil
- else
- namespace_project_merge_request_path(project.namespace, project, merge_request)
- end
+ expose :merge_request_path, if: -> (*) { can?(current_user, :read_merge_request, project) } do |build|
+ namespace_project_merge_request_path(project.namespace, project, build.merge_request)
end
- expose :new_issue_path do |build|
- project = build.project
-
- unless build.failed? && can?(request.current_user, :create_issue, project)
- nil
- else
- new_namespace_project_issue_path(project.namespace, project)
- end
+ expose :new_issue_path, if: -> (*) { can?(request.current_user, :create_issue, project) } do |build|
+ new_namespace_project_issue_path(project.namespace, project)
end
expose :raw_path do |build|
- project = build.project
raw_namespace_project_build_path(project.namespace, project, build)
end
+
+ private
+
+ def current_user
+ request.current_user
+ end
+
+ def project
+ build.project
+ end
end
diff --git a/app/serializers/build_serializer.rb b/app/serializers/build_serializer.rb
index 7b501a52604..701706be05a 100644
--- a/app/serializers/build_serializer.rb
+++ b/app/serializers/build_serializer.rb
@@ -4,7 +4,5 @@ class BuildSerializer < BaseSerializer
def represent_status(resource, opts = {}, entity_class = nil)
data = represent(resource, { only: [:status] })
data.fetch(:status, {})
-
- represent(resource, opts, entity_class)
end
end
diff --git a/app/serializers/pipeline_details_entity.rb b/app/serializers/pipeline_details_entity.rb
new file mode 100644
index 00000000000..e80685dd4e3
--- /dev/null
+++ b/app/serializers/pipeline_details_entity.rb
@@ -0,0 +1,21 @@
+class PipelineDetailsEntity < PipelineEntity
+ expose :yaml_errors, if: -> (pipeline, _) { pipeline.has_yaml_errors? }
+
+ expose :details do
+ expose :detailed_status, as: :status, with: StatusEntity
+ expose :duration
+ expose :finished_at
+ expose :stages, using: StageEntity
+ expose :artifacts, using: BuildArtifactEntity
+ expose :manual_actions, using: BuildActionEntity
+ end
+
+ expose :flags do
+ expose :latest?, as: :latest
+ expose :triggered?, as: :triggered
+ expose :stuck?, as: :stuck
+ expose :has_yaml_errors?, as: :yaml_errors
+ expose :can_retry?, as: :retryable
+ expose :can_cancel?, as: :cancelable
+ end
+end
diff --git a/app/serializers/pipeline_entity.rb b/app/serializers/pipeline_entity.rb
index ea57cc97a7e..4a19c2178f3 100644
--- a/app/serializers/pipeline_entity.rb
+++ b/app/serializers/pipeline_entity.rb
@@ -6,6 +6,8 @@ class PipelineEntity < Grape::Entity
expose :active?, as: :active
expose :coverage
+ expose :created_at, :updated_at
+
expose :path do |pipeline|
namespace_project_pipeline_path(
pipeline.project.namespace,
@@ -13,24 +15,6 @@ class PipelineEntity < Grape::Entity
pipeline)
end
- expose :details do
- expose :detailed_status, as: :status, with: StatusEntity
- expose :duration
- expose :finished_at
- expose :stages, using: StageEntity
- expose :artifacts, using: BuildArtifactEntity
- expose :manual_actions, using: BuildActionEntity
- end
-
- expose :flags do
- expose :latest?, as: :latest
- expose :triggered?, as: :triggered
- expose :stuck?, as: :stuck
- expose :has_yaml_errors?, as: :yaml_errors
- expose :can_retry?, as: :retryable
- expose :can_cancel?, as: :cancelable
- end
-
expose :ref do
expose :name do |pipeline|
pipeline.ref
@@ -47,7 +31,6 @@ class PipelineEntity < Grape::Entity
end
expose :commit, using: CommitEntity
- expose :yaml_errors, if: -> (pipeline, _) { pipeline.has_yaml_errors? }
expose :retry_path, if: -> (*) { can_retry? } do |pipeline|
retry_namespace_project_pipeline_path(pipeline.project.namespace,
@@ -61,8 +44,6 @@ class PipelineEntity < Grape::Entity
pipeline.id)
end
- expose :created_at, :updated_at
-
private
alias_method :pipeline, :object
diff --git a/app/serializers/pipeline_serializer.rb b/app/serializers/pipeline_serializer.rb
index e37af63774c..b428ff69fe8 100644
--- a/app/serializers/pipeline_serializer.rb
+++ b/app/serializers/pipeline_serializer.rb
@@ -1,7 +1,7 @@
class PipelineSerializer < BaseSerializer
InvalidResourceError = Class.new(StandardError)
- entity PipelineEntity
+ entity PipelineDetailsEntity
def with_pagination(request, response)
tap { @paginator = Gitlab::Serializer::Pagination.new(request, response) }
diff --git a/app/serializers/runner_entity.rb b/app/serializers/runner_entity.rb
index 77d6de6e84c..00d8bf9f59c 100644
--- a/app/serializers/runner_entity.rb
+++ b/app/serializers/runner_entity.rb
@@ -1,3 +1,16 @@
class RunnerEntity < Grape::Entity
- expose :id, :name, :description
+ include RequestAwareEntity
+
+ expose :id, :description
+
+ expose :edit_runner_path,
+ if: -> (*) { can?(request.current_user, :admin_build, project) } do |runner|
+ edit_namespace_project_runner_path(project.namespace, project, runner)
+ end
+
+ private
+
+ def project
+ request.project
+ end
end