Commit 4d41259a authored by James Lopez's avatar James Lopez

Merge branch '215190-add-sectional-parsing-of-codeowners' into 'master'

Add :sectional_codeowners feature flag

See merge request gitlab-org/gitlab!30311
parents ca720e7e 41538242
......@@ -40,6 +40,10 @@ module Gitlab
end
def get_parsed_data
if Feature.enabled?(:sectional_codeowners, default_enabled: false)
return get_parsed_sectional_data
end
parsed = {}
data.lines.each do |line|
......@@ -57,6 +61,10 @@ module Gitlab
parsed
end
def get_parsed_sectional_data
{}
end
def normalize_pattern(pattern)
# Remove `\` when escaping `\#`
pattern = pattern.sub(/\A\\#/, '#')
......
......@@ -32,6 +32,8 @@ describe 'Projects > Merge Requests > User edits a merge request' do
let(:ruby_owner) { create(:user, username: 'ruby-owner') }
before do
stub_feature_flags(sectional_codeowners: false)
project.add_developer(ruby_owner)
project.repository.create_file(user, 'ruby.rb', '# a ruby file',
message: 'Add a ruby file',
......
......@@ -22,6 +22,7 @@ describe 'File blob > Code owners', :js do
context 'when the feature is available' do
before do
stub_licensed_features(code_owners: true)
stub_feature_flags(sectional_codeowners: false)
end
it 'shows the code owners related to a file' do
......
......@@ -56,6 +56,10 @@ describe Gitlab::Checks::DiffCheck do
end
context 'and the user is not listed as a codeowner' do
before do
stub_feature_flags(sectional_codeowners: false)
end
it "returns an error message" do
expect { diff_check.validate! }.to raise_error do |error|
expect(error).to be_a(Gitlab::GitAccess::ForbiddenError)
......@@ -81,6 +85,10 @@ describe Gitlab::Checks::DiffCheck do
end
context "and the user is not listed as a code owner" do
before do
stub_feature_flags(sectional_codeowners: false)
end
it "returns an error message" do
expect(validation_result).to include("Pushes to protected branches")
end
......
......@@ -14,6 +14,10 @@ describe Gitlab::CodeOwners::File do
subject(:file) { described_class.new(blob) }
before do
stub_feature_flags(sectional_codeowners: false)
end
describe '#parsed_data' do
def owner_line(pattern)
file.parsed_data[pattern].owner_line
......@@ -32,6 +36,18 @@ describe Gitlab::CodeOwners::File do
it 'allows usernames and emails' do
expect(owner_line('/**/LICENSE')).to include('legal', 'janedoe@gitlab.com')
end
context "when feature flag `:sectional_codeowners` is enabled" do
before do
stub_feature_flags(sectional_codeowners: true)
end
it "passes the call to #get_parsed_sectional_data" do
expect(file).to receive(:get_parsed_sectional_data).and_return({})
expect(file.parsed_data).to be_empty
end
end
end
describe '#empty?' do
......
......@@ -39,6 +39,10 @@ describe Gitlab::CodeOwners::Loader do
let(:expected_entry) { Gitlab::CodeOwners::Entry.new('docs/CODEOWNERS', '@owner-1 owner2@gitlab.org @owner-3 @documentation-owner') }
let(:first_entry) { loader.entries.first }
before do
stub_feature_flags(sectional_codeowners: false)
end
it 'returns entries for the matched line' do
expect(loader.entries).to contain_exactly(expected_entry)
end
......@@ -121,6 +125,10 @@ describe Gitlab::CodeOwners::Loader do
end
describe '#members' do
before do
stub_feature_flags(sectional_codeowners: false)
end
it 'returns users mentioned for the passed path' do
expect(loader.members).to contain_exactly(owner_1, email_owner, documentation_owner)
end
......@@ -143,6 +151,10 @@ describe Gitlab::CodeOwners::Loader do
end
describe '#empty_code_owners?' do
before do
stub_feature_flags(sectional_codeowners: false)
end
context 'when file does not exist' do
let(:codeowner_blob) { nil }
......
......@@ -26,6 +26,7 @@ describe Gitlab::CodeOwners do
context 'when the feature is available' do
before do
stub_licensed_features(code_owners: true)
stub_feature_flags(sectional_codeowners: false)
end
it 'returns users for a blob' do
......@@ -59,6 +60,7 @@ describe Gitlab::CodeOwners do
before do
stub_licensed_features(code_owners: true)
stub_feature_flags(sectional_codeowners: false)
end
it "return equivalent results" do
......@@ -89,6 +91,7 @@ describe Gitlab::CodeOwners do
context 'when the feature is available' do
before do
stub_licensed_features(code_owners: true)
stub_feature_flags(sectional_codeowners: false)
end
it 'returns owners for merge request' do
......
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