Commit 64e39390 authored by Michelle Gill's avatar Michelle Gill Committed by Thong Kuah

Return nil license if Gitaly is down

When exploring projects (/explore, /explore/projects/starred,
/explore/projects/trending), a small license icon is displayed for "MIT", "GNU,"
etc. That license requires a Gitaly call, so if Gitaly is unreachable or down,
the entire page will return a 503. This MR should return nil, or an empty
license so that the page doesn't require it in order to load.
parent e2fe1d7e
......@@ -381,6 +381,14 @@ module ProjectsHelper
@project.grafana_integration&.enabled?
end
def project_license_name(project)
project.repository.license&.name
rescue GRPC::Unavailable, GRPC::DeadlineExceeded, Gitlab::Git::CommandError => e
Gitlab::ErrorTracking.track_exception(e)
nil
end
private
def get_project_nav_tabs(project, current_user)
......
......@@ -14,6 +14,7 @@
- updated_tooltip = time_ago_with_tooltip(project.last_activity_date)
- css_controls_class = compact_mode ? [] : ["flex-lg-row", "justify-content-lg-between"]
- avatar_container_class = project.creator && use_creator_avatar ? '' : 'rect-avatar'
- license_name = project_license_name(project)
%li.project-row.d-flex{ class: css_class }
= cache(cache_key) do
......@@ -40,10 +41,10 @@
%span.metadata-info.visibility-icon.append-right-10.prepend-top-8.text-secondary.has-tooltip{ data: { container: 'body', placement: 'top' }, title: visibility_icon_description(project) }
= visibility_level_icon(project.visibility_level, fw: true)
- if explore_projects_tab? && project.repository.license
- if explore_projects_tab? && license_name
%span.metadata-info.d-inline-flex.align-items-center.append-right-10.prepend-top-8
= sprite_icon('scale', size: 14, css_class: 'append-right-4')
= project.repository.license.name
= license_name
- if !explore_projects_tab? && access&.nonzero?
-# haml-lint:disable UnnecessaryStringOutput
......
---
title: Handle Gitaly failure when fetching license
merge_request: 24310
author:
type: fixed
......@@ -994,4 +994,56 @@ describe ProjectsHelper do
it { is_expected.to eq(grafana_integration.enabled) }
end
end
describe '#project_license_name(project)' do
let_it_be(:project) { create(:project) }
let_it_be(:repository) { project.repository }
subject { project_license_name(project) }
context 'gitaly is working appropriately' do
it 'returns the license name' do
license = Licensee::License.new('mit')
allow(repository).to receive(:license).and_return(license)
expect(subject).to eq(license.name)
end
end
context 'gitaly is unreachable' do
shared_examples 'returns nil and tracks exception' do
it { is_expected.to be_nil }
it 'tracks the exception' do
expect(Gitlab::ErrorTracking).to receive(:track_exception).with(
an_instance_of(exception)
)
subject
end
end
before do
allow(repository).to receive(:license).and_raise(exception)
end
context "Gitlab::Git::CommandError" do
let(:exception) { Gitlab::Git::CommandError }
it_behaves_like 'returns nil and tracks exception'
end
context "GRPC::Unavailable" do
let(:exception) { GRPC::Unavailable }
it_behaves_like 'returns nil and tracks exception'
end
context "GRPC::DeadlineExceeded" do
let(:exception) { GRPC::DeadlineExceeded }
it_behaves_like 'returns nil and tracks exception'
end
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