From 421afe883d28c2334e543b0e8f9c6058af7e5a9c Mon Sep 17 00:00:00 2001 From: Miguel Rincon <mrincon@gitlab.com> Date: Fri, 15 Sep 2023 07:23:12 +0000 Subject: [PATCH] Migrate from ci_label_for_status in template This change migrates from ci_label_for_status to detailed_status in template and make the method private to prevent it from being reused. --- app/helpers/ci/status_helper.rb | 44 ++++++++++--------- .../projects/commit/_commit_box.html.haml | 3 +- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/app/helpers/ci/status_helper.rb b/app/helpers/ci/status_helper.rb index 73aec454f1d51..5d526a6abb674 100644 --- a/app/helpers/ci/status_helper.rb +++ b/app/helpers/ci/status_helper.rb @@ -9,27 +9,6 @@ # module Ci module StatusHelper - def ci_label_for_status(status) - if detailed_status?(status) - return status.label - end - - label = case status - when 'success' - 'passed' - when 'success-with-warnings' - 'passed with warnings' - when 'manual' - 'waiting for manual action' - when 'scheduled' - 'waiting for delayed job' - else - status - end - translation = "CiStatusLabel|#{label}" - s_(translation) - end - def ci_status_for_statuseable(subject) status = subject.try(:status) || 'not found' status.humanize @@ -110,11 +89,34 @@ def render_status_with_link(status, path = nil, type: _('pipeline'), tooltip_pla end end + private + def detailed_status?(status) status.respond_to?(:text) && status.respond_to?(:group) && status.respond_to?(:label) && status.respond_to?(:icon) end + + def ci_label_for_status(status) + if detailed_status?(status) + return status.label + end + + label = case status + when 'success' + 'passed' + when 'success-with-warnings' + 'passed with warnings' + when 'manual' + 'waiting for manual action' + when 'scheduled' + 'waiting for delayed job' + else + status + end + translation = "CiStatusLabel|#{label}" + s_(translation) + end end end diff --git a/app/views/projects/commit/_commit_box.html.haml b/app/views/projects/commit/_commit_box.html.haml index 24d063d3b4d0a..e79a91eddaf96 100644 --- a/app/views/projects/commit/_commit_box.html.haml +++ b/app/views/projects/commit/_commit_box.html.haml @@ -45,11 +45,12 @@ = gl_loading_icon(inline: true, css_class: 'gl-vertical-align-middle') - if can?(current_user, :read_pipeline, @last_pipeline) + - status = @last_pipeline.detailed_status(current_user) .well-segment.pipeline-info .js-commit-pipeline-status{ data: { full_path: @project.full_path, iid: @last_pipeline.iid, graphql_resource_etag: graphql_etag_pipeline_path(@last_pipeline) } } #{ _('Pipeline') } = link_to "##{@last_pipeline.id}", project_pipeline_path(@project, @last_pipeline.id) - = ci_label_for_status(@last_pipeline.status) + = status&.label - if @last_pipeline.stages_count.nonzero? #{ n_(s_('Pipeline|with stage'), s_('Pipeline|with stages'), @last_pipeline.stages_count) } .js-commit-pipeline-mini-graph{ data: { stages: @last_pipeline_stages.to_json.html_safe, full_path: @project.full_path, iid: @last_pipeline.iid, graphql_resource_etag: graphql_etag_pipeline_path(@last_pipeline) } } -- GitLab