diff --git a/app/helpers/ci/status_helper.rb b/app/helpers/ci/status_helper.rb index 965887c1074d4a95e276da8e098fd75afffe4a85..eb2e424afb9e78058ea048a83b54120080369c48 100644 --- a/app/helpers/ci/status_helper.rb +++ b/app/helpers/ci/status_helper.rb @@ -53,7 +53,7 @@ def ci_icon_for_status(status, size: 24) def render_commit_status(commit, status, ref: nil, tooltip_placement: 'left') project = commit.project - path = pipelines_project_commit_path(project, commit, ref: ref) + path = pipelines_project_commit_path(project, commit.id, ref: ref) render_ci_icon( status, diff --git a/app/views/projects/commits/_commit.html.haml b/app/views/projects/commits/_commit.html.haml index 24eb971943dc1eaf81cd6db590b4a25a197649ca..75b9fbb56fff33a17548ebf9803200317f54e5fa 100644 --- a/app/views/projects/commits/_commit.html.haml +++ b/app/views/projects/commits/_commit.html.haml @@ -13,11 +13,12 @@ - merge_request = local_assigns.fetch(:merge_request, nil) - project = local_assigns.fetch(:project) { merge_request&.project } - ref = local_assigns.fetch(:ref) { merge_request&.source_branch } +- is_commits_page = local_assigns.fetch(:is_commits_page, false) +- pipeline_ref = ref unless is_commits_page && !@ref_type && Commit.valid_hash?(ref) - commit = commit.present(current_user: current_user) -- commit_status = commit.detailed_status_for(ref) +- commit_status = commit.detailed_status_for(pipeline_ref) - show_legacy_ci_icon = local_assigns.fetch(:show_legacy_ci_icon, true) - is_blob_page = local_assigns.fetch(:is_blob_page, false) -- is_commits_page = local_assigns.fetch(:is_commits_page, false) - tags = commit.tags_for_display - collapsible = local_assigns.fetch(:collapsible, true) - link_data_attrs = local_assigns.fetch(:link_data_attrs, {}) @@ -79,8 +80,8 @@ - else = render partial: 'projects/commit/ajax_signature', locals: { commit: commit } - if show_legacy_ci_icon && commit_status - = render_commit_status(commit, commit_status, ref: ref) - .js-commit-pipeline-status{ data: { endpoint: pipelines_project_commit_path(project, commit.id, ref: ref) } } + = render_commit_status(commit, commit_status, ref: pipeline_ref) + .js-commit-pipeline-status{ data: { endpoint: pipelines_project_commit_path(project, commit.id, ref: pipeline_ref) } } .btn-group.gl-hidden{ class: '@sm/panel:gl-flex' } = render Pajamas::ButtonComponent.new(label: true, button_text_classes: 'gl-font-monospace', button_options: { class: 'dark:!gl-bg-neutral-800' }) do = commit.short_id diff --git a/spec/features/commits_spec.rb b/spec/features/commits_spec.rb index 6a6c497fa6d604fc4392e60f0f33609cd573af87..f3a8906fe7f4c900e888f4a424443cbe2e59f593 100644 --- a/spec/features/commits_spec.rb +++ b/spec/features/commits_spec.rb @@ -75,14 +75,80 @@ ) end - before do - visit project_commits_path(project, :master) + context 'while viewing a branch' do + before do + visit project_commits_path(project, :master) + end + + it 'shows correct build status from default branch' do + page.within("//li[@id='commit-#{pipeline.short_sha}']") do + expect(page).to have_css("[data-testid='ci-icon']") + expect(page).to have_css('[data-testid="status_success_borderless-icon"]') + end + end end - it 'shows correct build status from default branch' do - page.within("//li[@id='commit-#{pipeline.short_sha}']") do - expect(page).to have_css("[data-testid='ci-icon']") - expect(page).to have_css('[data-testid="status_success_borderless-icon"]') + context 'while viewing a commit' do + let_it_be(:sha) { project.commit.sha } + let_it_be(:short_sha) { sha[..7] } + + before_all do + project.repository.add_branch(user, sha, 'master', skip_ci: true) + project.repository.add_branch(user, short_sha, 'master', skip_ci: true) + end + + context 'when ref is a commit short sha' do + context 'without ref_type' do + before do + visit project_commits_path(project, short_sha) + end + + it 'shows latest build status for the commit sha' do + page.within("//li[@id='commit-#{short_sha}']") do + expect(page).to have_css("[data-testid='ci-icon']") + expect(page).to have_css('[data-testid="status_failed_borderless-icon"]') + end + end + end + + context 'with ref_type' do + before do + visit project_commits_path(project, short_sha, ref_type: 'heads') + end + + it 'does not show any build status' do + page.within("//li[@id='commit-#{short_sha}']") do + expect(page).not_to have_css("[data-testid='ci-icon']") + end + end + end + end + + context 'when ref is a commit sha' do + context 'without ref_type' do + before do + visit project_commits_path(project, sha) + end + + it 'shows latest build status for the commit sha' do + page.within("//li[@id='commit-#{short_sha}']") do + expect(page).to have_css("[data-testid='ci-icon']") + expect(page).to have_css('[data-testid="status_failed_borderless-icon"]') + end + end + end + + context 'with ref_type' do + before do + visit project_commits_path(project, sha, ref_type: 'heads') + end + + it 'does not show any build status' do + page.within("//li[@id='commit-#{short_sha}']") do + expect(page).not_to have_css("[data-testid='ci-icon']") + end + end + end end end end