Commit dff11db2 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch '201886-remove-ee-blob-codeowners' into 'master'

Don't indirect through Blob for codeowners data

See merge request gitlab-org/gitlab!29245
parents 5d49cc47 cf572f04
......@@ -254,5 +254,3 @@ class Blob < SimpleDelegator
classes.find { |viewer_class| viewer_class.can_render?(self, verify_binary: verify_binary) }
end
end
Blob.prepend_if_ee('EE::Blob')
# frozen_string_literal: true
module EE
module Blob
extend ActiveSupport::Concern
def owners
@owners ||= ::Gitlab::CodeOwners.for_blob(self)
end
end
end
- return if blob.owners.empty?
- owners = Gitlab::CodeOwners.for_blob(@project, blob)
- return if owners.empty?
.well-segment.blob-auxiliary-viewer.file-owner-content.qa-file-owner-content
= sprite_icon('users', size: 18, css_class: 'icon')
......@@ -6,4 +7,4 @@
= _("Code owners")
= link_to icon('question-circle'), help_page_path('user/project/code_owners'), title: 'About this feature', target: '_blank'
&#58;
= users_sentence(blob.owners, link_class: 'file-owner-link qa-link-file-owner')
= users_sentence(owners, link_class: 'file-owner-link qa-link-file-owner')
......@@ -5,9 +5,9 @@ module Gitlab
FILE_NAME = 'CODEOWNERS'
FILE_PATHS = [FILE_NAME, "docs/#{FILE_NAME}", ".gitlab/#{FILE_NAME}"].freeze
def self.for_blob(blob)
if blob.project.feature_available?(:code_owners)
Loader.new(blob.project, blob.commit_id, blob.path).members
def self.for_blob(project, blob)
if project.feature_available?(:code_owners)
Loader.new(project, blob.commit_id, blob.path).members
else
[]
end
......
......@@ -29,7 +29,7 @@ describe Gitlab::CodeOwners do
end
it 'returns users for a blob' do
expect(described_class.for_blob(blob)).to include(code_owner)
expect(described_class.for_blob(project, blob)).to include(code_owner)
end
end
......@@ -39,7 +39,7 @@ describe Gitlab::CodeOwners do
end
it 'returns no users' do
expect(described_class.for_blob(blob)).to be_empty
expect(described_class.for_blob(project, blob)).to be_empty
end
end
end
......
# frozen_string_literal: true
require 'spec_helper'
describe Blob do
let(:project) { create(:project, :repository) }
let(:blob) do
project.repository.blob_at(TestEnv::BRANCH_SHA['with-codeowners'], 'docs/CODEOWNERS')
end
let(:code_owner) { create(:user, username: 'documentation-owner') }
before do
project.add_developer(code_owner)
end
describe '#owners' do
context 'when the feature is available' do
before do
stub_licensed_features(code_owners: true)
end
it 'returns the owners from the file' do
expect(blob.owners).to include(code_owner)
end
end
context 'when the feature is not available' do
before do
stub_licensed_features(code_owners: false)
end
it 'returns no code owners' do
expect(blob.owners).to be_empty
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