Commit bb40d720 authored by Thong Kuah's avatar Thong Kuah

Merge branch '199442-explore-projects' into 'master'

Return nil license if Gitaly is down

Closes #199442

See merge request gitlab-org/gitlab!24310
parents 471b9888 64e39390
...@@ -381,6 +381,14 @@ module ProjectsHelper ...@@ -381,6 +381,14 @@ module ProjectsHelper
@project.grafana_integration&.enabled? @project.grafana_integration&.enabled?
end 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 private
def get_project_nav_tabs(project, current_user) def get_project_nav_tabs(project, current_user)
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
- updated_tooltip = time_ago_with_tooltip(project.last_activity_date) - updated_tooltip = time_ago_with_tooltip(project.last_activity_date)
- css_controls_class = compact_mode ? [] : ["flex-lg-row", "justify-content-lg-between"] - css_controls_class = compact_mode ? [] : ["flex-lg-row", "justify-content-lg-between"]
- avatar_container_class = project.creator && use_creator_avatar ? '' : 'rect-avatar' - avatar_container_class = project.creator && use_creator_avatar ? '' : 'rect-avatar'
- license_name = project_license_name(project)
%li.project-row.d-flex{ class: css_class } %li.project-row.d-flex{ class: css_class }
= cache(cache_key) do = cache(cache_key) do
...@@ -40,10 +41,10 @@ ...@@ -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) } %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) = 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 %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') = sprite_icon('scale', size: 14, css_class: 'append-right-4')
= project.repository.license.name = license_name
- if !explore_projects_tab? && access&.nonzero? - if !explore_projects_tab? && access&.nonzero?
-# haml-lint:disable UnnecessaryStringOutput -# haml-lint:disable UnnecessaryStringOutput
......
---
title: Handle Gitaly failure when fetching license
merge_request: 24310
author:
type: fixed
...@@ -994,4 +994,56 @@ describe ProjectsHelper do ...@@ -994,4 +994,56 @@ describe ProjectsHelper do
it { is_expected.to eq(grafana_integration.enabled) } it { is_expected.to eq(grafana_integration.enabled) }
end end
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 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