Commit 0f362b13 authored by Stan Hu's avatar Stan Hu

Gracefully handle missing latest CI pipeline

If a user attempted to retrieve the latest CI pipeline but no such
pipeline existed, the user would see a 500 error.

We should handle this case gracefully with a 404.

Closes https://gitlab.com/gitlab-org/gitlab/-/issues/212552
parent 8408c1bf
...@@ -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