From e254da811fcdde1e89d4cf9b1129537225505e68 Mon Sep 17 00:00:00 2001 From: Steve Azzopardi Date: Tue, 11 Sep 2018 17:13:24 +0000 Subject: Add empty state illustration information in job API --- app/serializers/detailed_status_entity.rb | 29 ++++++++++++++ app/serializers/job_entity.rb | 2 +- app/serializers/job_group_entity.rb | 2 +- app/serializers/pipeline_entity.rb | 2 +- app/serializers/stage_entity.rb | 2 +- app/serializers/status_entity.rb | 21 ---------- .../51112-add-status-illustration-in-job-api.yml | 5 +++ spec/controllers/projects/jobs_controller_spec.rb | 12 ++++++ spec/fixtures/api/schemas/ci_detailed_status.json | 46 ---------------------- spec/fixtures/api/schemas/job/job.json | 2 +- spec/fixtures/api/schemas/pipeline_stage.json | 2 +- spec/fixtures/api/schemas/status/action.json | 22 +++++++++++ .../api/schemas/status/ci_detailed_status.json | 26 ++++++++++++ spec/fixtures/api/schemas/status/illustration.json | 19 +++++++++ spec/serializers/detailed_status_entity_spec.rb | 24 +++++++++++ spec/serializers/status_entity_spec.rb | 24 ----------- 16 files changed, 143 insertions(+), 97 deletions(-) create mode 100644 app/serializers/detailed_status_entity.rb delete mode 100644 app/serializers/status_entity.rb create mode 100644 changelogs/unreleased/51112-add-status-illustration-in-job-api.yml delete mode 100644 spec/fixtures/api/schemas/ci_detailed_status.json create mode 100644 spec/fixtures/api/schemas/status/action.json create mode 100644 spec/fixtures/api/schemas/status/ci_detailed_status.json create mode 100644 spec/fixtures/api/schemas/status/illustration.json create mode 100644 spec/serializers/detailed_status_entity_spec.rb delete mode 100644 spec/serializers/status_entity_spec.rb diff --git a/app/serializers/detailed_status_entity.rb b/app/serializers/detailed_status_entity.rb new file mode 100644 index 00000000000..c772c807f76 --- /dev/null +++ b/app/serializers/detailed_status_entity.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +class DetailedStatusEntity < Grape::Entity + include RequestAwareEntity + + expose :icon, :text, :label, :group + expose :status_tooltip, as: :tooltip + expose :has_details?, as: :has_details + expose :details_path + + expose :illustration do |status| + begin + status.illustration + rescue NotImplementedError + # ignored + end + end + + expose :favicon do |status| + Gitlab::Favicon.status_overlay(status.favicon) + end + + expose :action, if: -> (status, _) { status.has_action? } do + expose :action_icon, as: :icon + expose :action_title, as: :title + expose :action_path, as: :path + expose :action_method, as: :method + end +end diff --git a/app/serializers/job_entity.rb b/app/serializers/job_entity.rb index 7bc1d87dea5..26b29993fec 100644 --- a/app/serializers/job_entity.rb +++ b/app/serializers/job_entity.rb @@ -27,7 +27,7 @@ class JobEntity < Grape::Entity expose :playable?, as: :playable expose :created_at expose :updated_at - expose :detailed_status, as: :status, with: StatusEntity + expose :detailed_status, as: :status, with: DetailedStatusEntity expose :callout_message, if: -> (*) { failed? && !build.script_failure? } expose :recoverable, if: -> (*) { failed? } diff --git a/app/serializers/job_group_entity.rb b/app/serializers/job_group_entity.rb index 0941a9d36be..0db7624b3f7 100644 --- a/app/serializers/job_group_entity.rb +++ b/app/serializers/job_group_entity.rb @@ -5,7 +5,7 @@ class JobGroupEntity < Grape::Entity expose :name expose :size - expose :detailed_status, as: :status, with: StatusEntity + expose :detailed_status, as: :status, with: DetailedStatusEntity expose :jobs, with: JobEntity private diff --git a/app/serializers/pipeline_entity.rb b/app/serializers/pipeline_entity.rb index 6cf1925adda..aef838409e0 100644 --- a/app/serializers/pipeline_entity.rb +++ b/app/serializers/pipeline_entity.rb @@ -30,7 +30,7 @@ class PipelineEntity < Grape::Entity end expose :details do - expose :detailed_status, as: :status, with: StatusEntity + expose :detailed_status, as: :status, with: DetailedStatusEntity expose :duration expose :finished_at end diff --git a/app/serializers/stage_entity.rb b/app/serializers/stage_entity.rb index 00e6d32ee3a..ca8fa7e7877 100644 --- a/app/serializers/stage_entity.rb +++ b/app/serializers/stage_entity.rb @@ -19,7 +19,7 @@ class StageEntity < Grape::Entity latest_statuses end - expose :detailed_status, as: :status, with: StatusEntity + expose :detailed_status, as: :status, with: DetailedStatusEntity expose :path do |stage| project_pipeline_path( diff --git a/app/serializers/status_entity.rb b/app/serializers/status_entity.rb deleted file mode 100644 index 306c30f0323..00000000000 --- a/app/serializers/status_entity.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -class StatusEntity < Grape::Entity - include RequestAwareEntity - - expose :icon, :text, :label, :group - expose :status_tooltip, as: :tooltip - expose :has_details?, as: :has_details - expose :details_path - - expose :favicon do |status| - Gitlab::Favicon.status_overlay(status.favicon) - end - - expose :action, if: -> (status, _) { status.has_action? } do - expose :action_icon, as: :icon - expose :action_title, as: :title - expose :action_path, as: :path - expose :action_method, as: :method - end -end diff --git a/changelogs/unreleased/51112-add-status-illustration-in-job-api.yml b/changelogs/unreleased/51112-add-status-illustration-in-job-api.yml new file mode 100644 index 00000000000..fdc75e28824 --- /dev/null +++ b/changelogs/unreleased/51112-add-status-illustration-in-job-api.yml @@ -0,0 +1,5 @@ +--- +title: Add empty state illustration information in job API +merge_request: 21532 +author: +type: other diff --git a/spec/controllers/projects/jobs_controller_spec.rb b/spec/controllers/projects/jobs_controller_spec.rb index 751919f9501..8b6903011c3 100644 --- a/spec/controllers/projects/jobs_controller_spec.rb +++ b/spec/controllers/projects/jobs_controller_spec.rb @@ -194,6 +194,18 @@ describe Projects::JobsController, :clean_gitlab_redis_shared_state do expect(json_response['terminal_path']).to match(%r{/terminal}) end end + + context 'when job passed with no trace' do + let(:job) { create(:ci_build, :success, :artifacts, pipeline: pipeline) } + + it 'exposes empty state illustrations' do + expect(response).to have_gitlab_http_status(:ok) + expect(response).to match_response_schema('job/job_details') + expect(json_response['status']['illustration']).to have_key('image') + expect(json_response['status']['illustration']).to have_key('size') + expect(json_response['status']['illustration']).to have_key('title') + end + end end def get_show(**extra_params) diff --git a/spec/fixtures/api/schemas/ci_detailed_status.json b/spec/fixtures/api/schemas/ci_detailed_status.json deleted file mode 100644 index d74248eabef..00000000000 --- a/spec/fixtures/api/schemas/ci_detailed_status.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "type": "object", - "required" : [ - "icon", - "text", - "label", - "group", - "tooltip", - "has_details", - "details_path", - "favicon" - ], - "properties": { - "icon": { "type": "string" }, - "text": { "type": "string" }, - "label": { "type": "string" }, - "group": { "type": "string" }, - "tooltip": { "type": "string" }, - "has_details": { "type": "boolean" }, - "details_path": { "type": "string" }, - "favicon": { "type": "string" }, - "action": { - "type": "object", - "required": [ - "icon", - "title", - "path", - "method" - ], - "properties": { - "icon": { - "type": "string", - "enum": [ - "retry", - "play", - "cancel" - ] - }, - "title": { "type": "string" }, - "path": { "type": "string" }, - "method": { "$ref": "http_method.json" } - } - } - }, - "additionalProperties": false -} diff --git a/spec/fixtures/api/schemas/job/job.json b/spec/fixtures/api/schemas/job/job.json index c793d93c0f6..f5d58b21e3d 100644 --- a/spec/fixtures/api/schemas/job/job.json +++ b/spec/fixtures/api/schemas/job/job.json @@ -25,7 +25,7 @@ "playable": { "type": "boolean" }, "created_at": { "type": "string" }, "updated_at": { "type": "string" }, - "status": { "$ref": "../ci_detailed_status.json" } + "status": { "$ref": "../status/ci_detailed_status.json" } }, "additionalProperties": true } diff --git a/spec/fixtures/api/schemas/pipeline_stage.json b/spec/fixtures/api/schemas/pipeline_stage.json index eb2667295f0..f72988a3d3d 100644 --- a/spec/fixtures/api/schemas/pipeline_stage.json +++ b/spec/fixtures/api/schemas/pipeline_stage.json @@ -16,7 +16,7 @@ "items": { "$ref": "job/job.json" }, "optional": true }, - "status": { "$ref": "ci_detailed_status.json" }, + "status": { "$ref": "status/ci_detailed_status.json" }, "path": { "type": "string" }, "dropdown_path": { "type": "string" } }, diff --git a/spec/fixtures/api/schemas/status/action.json b/spec/fixtures/api/schemas/status/action.json new file mode 100644 index 00000000000..99a576e6c5b --- /dev/null +++ b/spec/fixtures/api/schemas/status/action.json @@ -0,0 +1,22 @@ +{ + "type": "object", + "required": [ + "icon", + "title", + "path", + "method" + ], + "properties": { + "icon": { + "type": "string", + "enum": [ + "retry", + "play", + "cancel" + ] + }, + "title": { "type": "string" }, + "path": { "type": "string" }, + "method": { "$ref": "../http_method.json" } + } +} diff --git a/spec/fixtures/api/schemas/status/ci_detailed_status.json b/spec/fixtures/api/schemas/status/ci_detailed_status.json new file mode 100644 index 00000000000..8d0f1e4a6af --- /dev/null +++ b/spec/fixtures/api/schemas/status/ci_detailed_status.json @@ -0,0 +1,26 @@ +{ + "type": "object", + "required": [ + "icon", + "text", + "label", + "group", + "tooltip", + "has_details", + "details_path", + "favicon" + ], + "properties": { + "icon": { "type": "string" }, + "text": { "type": "string" }, + "label": { "type": "string" }, + "group": { "type": "string" }, + "tooltip": { "type": "string" }, + "has_details": { "type": "boolean" }, + "details_path": { "type": "string" }, + "favicon": { "type": "string" }, + "illustration": { "$ref": "illustration.json" }, + "action": { "$ref": "action.json" } + }, + "additionalProperties": false +} diff --git a/spec/fixtures/api/schemas/status/illustration.json b/spec/fixtures/api/schemas/status/illustration.json new file mode 100644 index 00000000000..9a085f5f1ee --- /dev/null +++ b/spec/fixtures/api/schemas/status/illustration.json @@ -0,0 +1,19 @@ +{ + "oneOf": [ + { "type": "null" }, + { + "type": "object", + "required": [ + "image", + "size", + "title" + ], + "properties": { + "image": { "type": "string" }, + "size": { "type": "string" }, + "title": { "type": "string" }, + "content": { "type": "string" } + } + } + ] +} diff --git a/spec/serializers/detailed_status_entity_spec.rb b/spec/serializers/detailed_status_entity_spec.rb new file mode 100644 index 00000000000..62f57ca8689 --- /dev/null +++ b/spec/serializers/detailed_status_entity_spec.rb @@ -0,0 +1,24 @@ +require 'spec_helper' + +describe DetailedStatusEntity do + let(:entity) { described_class.new(status) } + + let(:status) do + Gitlab::Ci::Status::Success.new(double('object'), double('user')) + end + + before do + allow(status).to receive(:has_details?).and_return(true) + allow(status).to receive(:details_path).and_return('some/path') + end + + describe '#as_json' do + subject { entity.as_json } + + it 'contains status details' do + expect(subject).to include :text, :icon, :favicon, :label, :group, :tooltip + expect(subject).to include :has_details, :details_path + expect(subject[:favicon]).to match_asset_path('/assets/ci_favicons/favicon_status_success.png') + end + end +end diff --git a/spec/serializers/status_entity_spec.rb b/spec/serializers/status_entity_spec.rb deleted file mode 100644 index 0b010ebd507..00000000000 --- a/spec/serializers/status_entity_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -require 'spec_helper' - -describe StatusEntity do - let(:entity) { described_class.new(status) } - - let(:status) do - Gitlab::Ci::Status::Success.new(double('object'), double('user')) - end - - before do - allow(status).to receive(:has_details?).and_return(true) - allow(status).to receive(:details_path).and_return('some/path') - end - - describe '#as_json' do - subject { entity.as_json } - - it 'contains status details' do - expect(subject).to include :text, :icon, :favicon, :label, :group, :tooltip - expect(subject).to include :has_details, :details_path - expect(subject[:favicon]).to match_asset_path('/assets/ci_favicons/favicon_status_success.png') - end - end -end -- cgit v1.2.1