Commit d1e1b1f3 authored by Jarka Košanová's avatar Jarka Košanová

Merge branch '340817_graceful_degradation' into 'master'

Graceful degradation for Branches controller

See merge request gitlab-org/gitlab!70970
parents 6b0b6f89 ac36712c
......@@ -33,6 +33,11 @@ class Projects::BranchesController < Projects::ApplicationController
Gitlab::GitalyClient.allow_n_plus_1_calls do
render
end
rescue Gitlab::Git::CommandError => e
Gitlab::ErrorTracking.track_exception(e)
@gitaly_unavailable = true
render
end
format.json do
branches = BranchesFinder.new(@repository, params).execute
......
......@@ -31,7 +31,10 @@
%h5
= s_('Branches|Protected branches can be managed in %{project_settings_link}.').html_safe % { project_settings_link: project_settings_link }
- if @mode == 'overview' && (@active_branches.any? || @stale_branches.any?)
- if @gitaly_unavailable
= render 'shared/errors/gitaly_unavailable', reason: s_('Branches|Unable to load branches')
- elsif @mode == 'overview' && (@active_branches.any? || @stale_branches.any?)
= render "projects/branches/panel", branches: @active_branches, state: 'active', panel_title: s_('Branches|Active branches'), show_more_text: s_('Branches|Show more active branches'), project: @project, overview_max_branches: @overview_max_branches
= render "projects/branches/panel", branches: @stale_branches, state: 'stale', panel_title: s_('Branches|Stale branches'), show_more_text: s_('Branches|Show more stale branches'), project: @project, overview_max_branches: @overview_max_branches
......
......@@ -5761,6 +5761,9 @@ msgstr ""
msgid "Branches|To discard the local changes and overwrite the branch with the upstream version, delete it here and choose 'Update Now' above."
msgstr ""
msgid "Branches|Unable to load branches"
msgstr ""
msgid "Branches|Yes, delete branch"
msgstr ""
......
......@@ -656,6 +656,26 @@ RSpec.describe Projects::BranchesController do
)
end
end
context 'when gitaly is not available' do
before do
allow_next_instance_of(Gitlab::GitalyClient::RefService) do |ref_service|
allow(ref_service).to receive(:local_branches).and_raise(GRPC::DeadlineExceeded)
end
get :index, format: :html, params: {
namespace_id: project.namespace, project_id: project
}
end
it 'returns with a status 200' do
expect(response).to have_gitlab_http_status(:ok)
end
it 'sets gitaly_unavailable variable' do
expect(assigns[:gitaly_unavailable]).to be_truthy
end
end
end
describe 'GET diverging_commit_counts' do
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'projects/branches/index.html.haml' do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:repository) { project.repository }
let(:branches) { repository.branches }
let(:active_branch) { branches.find { |b| b.name == 'master' } }
let(:stale_branch) { branches.find { |b| b.name == 'feature' } }
before do
assign(:project, project)
assign(:repository, repository)
assign(:mode, 'overview')
assign(:active_branches, [active_branch])
assign(:stale_branches, [stale_branch])
assign(:overview_max_branches, 5)
assign(:branch_pipeline_statuses, {})
assign(:refs_pipelines, {})
end
it 'renders list of active and stale branches' do
content = render
expect(content).to include(active_branch.name)
expect(content).to include(stale_branch.name)
end
context 'when Gitaly is unavailable' do
it 'renders an error' do
assign(:gitaly_unavailable, true)
content = render
expect(content).to include('Unable to load branches')
expect(content).to include(
'The git server, Gitaly, is not available at this time. Please contact your administrator.'
)
end
end
end
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