From d75be5a4521a739124e12ca3765677055a8b5a07 Mon Sep 17 00:00:00 2001 From: Joe Woodward Date: Tue, 21 Oct 2025 14:54:09 +0100 Subject: [PATCH 1/2] Fetch correct pipeline when viewing commits in detacted state If you are viewing the commits and have a branch or tag selected in the ref selector we can correctly fetch the pipeline using the ref.name. However, you can also view commits when you've checked out a commit i.e. instead of viewing commits/master you're viewing commits/SHA and viewing all of the commits in the history of SHA. When we are in this detatched state we need to remove the ref and rely on the SHA instead. We don't know which branch or tag we're on so we just find the most recent pipeline within any ref and show that one. Unfortunately we don't have ref_type available in the commits page so here we are checking if the ref looks like a SHA. This does have a caveat that any branches that look like SHAs will show the latest pipelines for the commit, not the commit within the current branch. This trade-off is much better than the current situation. It's highly unlikely for users to be naming branches with SHA values. It is much more likely for users to view the commits page while viewing a commit. --- app/views/projects/commits/_commit.html.haml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/views/projects/commits/_commit.html.haml b/app/views/projects/commits/_commit.html.haml index 24eb971943dc1e..a80b2db8bdec19 100644 --- a/app/views/projects/commits/_commit.html.haml +++ b/app/views/projects/commits/_commit.html.haml @@ -13,8 +13,9 @@ - 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 } +- pipeline_ref = ref unless /^([a-f0-9]{40})/.match?(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) @@ -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 -- GitLab From a795db3d0dc0f566529beb85d718ec51cd540fac Mon Sep 17 00:00:00 2001 From: Joe Woodward Date: Tue, 21 Oct 2025 20:22:08 +0100 Subject: [PATCH 2/2] Apply 1 suggestion(s) to 1 file(s) Co-authored-by: GitLab Duo --- app/views/projects/commits/_commit.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/projects/commits/_commit.html.haml b/app/views/projects/commits/_commit.html.haml index a80b2db8bdec19..fb4b2a388870bb 100644 --- a/app/views/projects/commits/_commit.html.haml +++ b/app/views/projects/commits/_commit.html.haml @@ -13,7 +13,7 @@ - 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 } -- pipeline_ref = ref unless /^([a-f0-9]{40})/.match?(ref) +- pipeline_ref = ref unless /^[a-f0-9]{7,40}$/.match?(ref) - commit = commit.present(current_user: current_user) - commit_status = commit.detailed_status_for(pipeline_ref) - show_legacy_ci_icon = local_assigns.fetch(:show_legacy_ci_icon, true) -- GitLab