diff options
author | Z.J. van de Weg <git@zjvandeweg.nl> | 2017-05-29 09:58:20 +0200 |
---|---|---|
committer | Z.J. van de Weg <git@zjvandeweg.nl> | 2017-05-31 21:56:18 +0200 |
commit | 8a9a62e3294d92f4e70be6f427c17241a2b7a232 (patch) | |
tree | 2337d1455c8fb9ebadbe73e872dbdc388a627315 /app/serializers | |
parent | 68569584b728ac2dd5100593e9db302f362994f5 (diff) | |
download | gitlab-ce-8a9a62e3294d92f4e70be6f427c17241a2b7a232.tar.gz |
Incorporate review
Diffstat (limited to 'app/serializers')
-rw-r--r-- | app/serializers/build_artifact_entity.rb | 31 | ||||
-rw-r--r-- | app/serializers/build_details_entity.rb | 15 | ||||
-rw-r--r-- | app/serializers/build_serializer.rb | 2 | ||||
-rw-r--r-- | app/serializers/merge_request_entity.rb | 2 | ||||
-rw-r--r-- | app/serializers/pipeline_details_entity.rb | 14 | ||||
-rw-r--r-- | app/serializers/pipeline_entity.rb | 17 | ||||
-rw-r--r-- | app/serializers/runner_entity.rb | 6 |
7 files changed, 64 insertions, 23 deletions
diff --git a/app/serializers/build_artifact_entity.rb b/app/serializers/build_artifact_entity.rb index dde17aa68b8..091bc8d6742 100644 --- a/app/serializers/build_artifact_entity.rb +++ b/app/serializers/build_artifact_entity.rb @@ -1,14 +1,39 @@ class BuildArtifactEntity < Grape::Entity include RequestAwareEntity - expose :name do |build| - build.name + expose :name do |job| + job.name end - expose :path do |build| + expose :artifacts_expired?, as: :expired + expose :artifacts_expire_at, as: :expire_at + + expose :path do |job| download_namespace_project_job_artifacts_path( build.project.namespace, build.project, build) end + + expose :keep_path, if: -> (*) { job.has_expiring_artifacts? } do |job| + keep_namespace_project_job_artifacts_path( + project.namespace, + project, + build) + end + + expose :browse_path do |job| + browse_namespace_project_job_artifacts_path( + project.namespace, + project, + job) + end + + private + + alias_method :job, :object + + def project + job.project + end end diff --git a/app/serializers/build_details_entity.rb b/app/serializers/build_details_entity.rb index dd5b8388c22..2d76ce203b9 100644 --- a/app/serializers/build_details_entity.rb +++ b/app/serializers/build_details_entity.rb @@ -2,12 +2,23 @@ class BuildDetailsEntity < BuildEntity expose :coverage, :erased_at, :duration expose :tag_list, as: :tags + expose :erased_by, if: -> (*) { build.erased? }, using: UserEntity + expose :erase_path, if: -> (*) { build.erasable? && can?(current_user, :update_build, project) } do |build| + erase_namespace_project_build_path(project.namespace, project, build) + end + expose :artifacts, using: BuildArtifactEntity expose :runner, using: RunnerEntity expose :pipeline, using: PipelineEntity - 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) + expose :merge_request, if: -> (*) { can?(current_user, :read_merge_request, project) } do + expose :iid do |build| + build.merge_request.iid + end + + expose :path do |build| + namespace_project_merge_request_path(project.namespace, project, build.merge_request) + end end expose :new_issue_path, if: -> (*) { can?(request.current_user, :create_issue, project) } do |build| diff --git a/app/serializers/build_serializer.rb b/app/serializers/build_serializer.rb index 701706be05a..79b67001199 100644 --- a/app/serializers/build_serializer.rb +++ b/app/serializers/build_serializer.rb @@ -1,7 +1,7 @@ class BuildSerializer < BaseSerializer entity BuildEntity - def represent_status(resource, opts = {}, entity_class = nil) + def represent_status(resource) data = represent(resource, { only: [:status] }) data.fetch(:status, {}) end diff --git a/app/serializers/merge_request_entity.rb b/app/serializers/merge_request_entity.rb index f7eb75395b5..7bb981041cc 100644 --- a/app/serializers/merge_request_entity.rb +++ b/app/serializers/merge_request_entity.rb @@ -29,7 +29,7 @@ class MergeRequestEntity < IssuableEntity expose :merge_commit_sha expose :merge_commit_message - expose :head_pipeline, with: PipelineEntity, as: :pipeline + expose :head_pipeline, with: PipelineDetailsEntity, as: :pipeline # Booleans expose :work_in_progress?, as: :work_in_progress diff --git a/app/serializers/pipeline_details_entity.rb b/app/serializers/pipeline_details_entity.rb index e80685dd4e3..d58572a5f87 100644 --- a/app/serializers/pipeline_details_entity.rb +++ b/app/serializers/pipeline_details_entity.rb @@ -1,21 +1,7 @@ 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 4a19c2178f3..7670f02ca86 100644 --- a/app/serializers/pipeline_entity.rb +++ b/app/serializers/pipeline_entity.rb @@ -15,6 +15,21 @@ class PipelineEntity < Grape::Entity pipeline) 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 :details do + expose :detailed_status, as: :status, with: StatusEntity + expose :duration + expose :finished_at + end + expose :ref do expose :name do |pipeline| pipeline.ref @@ -44,6 +59,8 @@ class PipelineEntity < Grape::Entity pipeline.id) end + expose :yaml_errors, if: -> (pipeline, _) { pipeline.has_yaml_errors? } + private alias_method :pipeline, :object diff --git a/app/serializers/runner_entity.rb b/app/serializers/runner_entity.rb index 00d8bf9f59c..ed7dacc2dbd 100644 --- a/app/serializers/runner_entity.rb +++ b/app/serializers/runner_entity.rb @@ -3,13 +3,15 @@ class RunnerEntity < Grape::Entity expose :id, :description - expose :edit_runner_path, - if: -> (*) { can?(request.current_user, :admin_build, project) } do |runner| + expose :edit_path, + if: -> (*) { can?(request.current_user, :admin_build, project) && runner.specific? } do |runner| edit_namespace_project_runner_path(project.namespace, project, runner) end private + alias_method :runner, :object + def project request.project end |