Commit 937e0948 authored by Nick Thomas's avatar Nick Thomas

Merge branch 'sh-handle-no-latest-pipeline' into 'master'

Gracefully handle missing latest CI pipeline

Closes #212552

See merge request gitlab-org/gitlab!28263
parents f0f05d2d 0f362b13
...@@ -13,6 +13,7 @@ class Projects::PipelinesController < Projects::ApplicationController ...@@ -13,6 +13,7 @@ class Projects::PipelinesController < Projects::ApplicationController
before_action do before_action do
push_frontend_feature_flag(:junit_pipeline_view) push_frontend_feature_flag(:junit_pipeline_view)
end end
before_action :ensure_pipeline, only: [:show]
around_action :allow_gitaly_ref_name_caching, only: [:index, :show] around_action :allow_gitaly_ref_name_caching, only: [:index, :show]
...@@ -214,6 +215,10 @@ class Projects::PipelinesController < Projects::ApplicationController ...@@ -214,6 +215,10 @@ class Projects::PipelinesController < Projects::ApplicationController
params.require(:pipeline).permit(:ref, variables_attributes: %i[key variable_type secret_value]) params.require(:pipeline).permit(:ref, variables_attributes: %i[key variable_type secret_value])
end end
def ensure_pipeline
render_404 unless pipeline
end
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def pipeline def pipeline
@pipeline ||= if params[:id].blank? && params[:latest] @pipeline ||= if params[:id].blank? && params[:latest]
......
---
title: Gracefully handle missing latest CI pipeline
merge_request: 28263
author:
type: fixed
...@@ -923,10 +923,18 @@ describe Projects::PipelinesController do ...@@ -923,10 +923,18 @@ describe Projects::PipelinesController do
end end
context 'ref provided' do context 'ref provided' do
render_views
before do before do
create(:ci_pipeline, ref: 'master', project: project) create(:ci_pipeline, ref: 'master', project: project)
end end
it 'shows a 404 if no pipeline exists' do
get :show, params: { namespace_id: project.namespace, project_id: project, latest: true, ref: 'non-existence' }
expect(response).to have_gitlab_http_status(:not_found)
end
it 'shows the latest pipeline for the provided ref' do it 'shows the latest pipeline for the provided ref' do
get :show, params: { namespace_id: project.namespace, project_id: project, latest: true, ref: branch_secondary.name } get :show, params: { namespace_id: project.namespace, project_id: project, latest: true, ref: branch_secondary.name }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment