diff options
-rw-r--r-- | app/serializers/build_details_entity.rb | 13 | ||||
-rw-r--r-- | spec/controllers/projects/jobs_controller_spec.rb | 4 | ||||
-rw-r--r-- | spec/serializers/build_details_entity_spec.rb | 2 | ||||
-rw-r--r-- | spec/serializers/build_entity_spec.rb | 4 |
4 files changed, 14 insertions, 9 deletions
diff --git a/app/serializers/build_details_entity.rb b/app/serializers/build_details_entity.rb index bd7ceceb2fa..0063920e603 100644 --- a/app/serializers/build_details_entity.rb +++ b/app/serializers/build_details_entity.rb @@ -23,10 +23,8 @@ class BuildDetailsEntity < BuildEntity end end - expose :build_failed_options do - expose :new_issue_path, if: -> (*) { can?(request.current_user, :create_issue, project) } do |build| - new_namespace_project_issue_path(project.namespace, project) - end + expose :new_issue_path, if: -> (*) { can?(request.current_user, :create_issue, project) && build.failed? } do |build| + new_namespace_project_issue_path(project.namespace, project, issue: build_failed_issue_options) end expose :raw_path do |build| @@ -35,6 +33,13 @@ class BuildDetailsEntity < BuildEntity private + def build_failed_issue_options + { + title: "Build Failed ##{build.id}", + description: namespace_project_job_url(project.namespace, project, build) + } + end + def current_user request.current_user end diff --git a/spec/controllers/projects/jobs_controller_spec.rb b/spec/controllers/projects/jobs_controller_spec.rb index 068c4ddf820..7211acc53dc 100644 --- a/spec/controllers/projects/jobs_controller_spec.rb +++ b/spec/controllers/projects/jobs_controller_spec.rb @@ -142,8 +142,8 @@ describe Projects::JobsController do expect(response).to have_http_status(:ok) expect(json_response['raw_path']).to match(/builds\/\d+\/raw\z/) expect(json_response.dig('merge_request', 'path')).to match(/merge_requests\/\d+\z/) - expect(json_response['build_failed_options']['new_issue_path']) - .to end_with('/issues/new') + expect(json_response['new_issue_path']) + .to include('/issues/new') end end diff --git a/spec/serializers/build_details_entity_spec.rb b/spec/serializers/build_details_entity_spec.rb index c372df7dd90..e2511e8968c 100644 --- a/spec/serializers/build_details_entity_spec.rb +++ b/spec/serializers/build_details_entity_spec.rb @@ -31,7 +31,7 @@ describe BuildDetailsEntity do expect(subject).to include(:coverage, :erased_at, :duration) expect(subject).to include(:artifacts, :runner, :pipeline) expect(subject).to include(:raw_path, :merge_request) - expect(subject[:build_failed_options]).to include(:new_issue_path) + expect(subject).to include(:new_issue_path) end it 'exposes details of the merge request' do diff --git a/spec/serializers/build_entity_spec.rb b/spec/serializers/build_entity_spec.rb index e48d558f33f..46d43a80ef7 100644 --- a/spec/serializers/build_entity_spec.rb +++ b/spec/serializers/build_entity_spec.rb @@ -17,8 +17,8 @@ describe BuildEntity do subject { entity.as_json } it 'contains paths to build page and retry action' do - expect(subject).to include(:build_path, :build_failed_options) - expect(subject.dig(:build_failed_options, :retry_path)).not_to be_nil + expect(subject).to include(:build_path, :retry_path) + expect(subject[:retry_path]).not_to be_nil end it 'does not contain sensitive information' do |