Commit 2aec8aa4 authored by Kerri Miller's avatar Kerri Miller

Skip section headers in legacy file parsing

If using the existing, legacy codeowners file parsing with a sectional
codeowners file, skip any headers. There is potential for this if
someone has a sectional codeowners file and the feature is disabled
(either they haven't enabled it yet, or have turned it off for some
reason..) With out this, we could potentially create new ApprovalRules
that would be meaningless.
parent d3eba34d
......@@ -80,7 +80,7 @@ module Gitlab
data.lines.each do |line|
line = line.strip
next if skip?(line)
next if skip?(line) || line.match?(SECTION_HEADER_REGEX)
extract_entry_and_populate_parsed_data(line, parsed)
end
......
......@@ -37,6 +37,21 @@ describe Gitlab::CodeOwners::File do
expect(owner_line('/**/LICENSE')).to include('legal', 'janedoe@gitlab.com')
end
context "when CODEOWNERS file contains multiple sections" do
let(:file_content) do
File.read(Rails.root.join("ee", "spec", "fixtures", "sectional_codeowners_example"))
end
let(:patterns) { ["[Documentation]", "[Database]"] }
let(:paths) { ["/**/[Documentation]", "/**/[Database]"] }
it "skips section headers when parsing" do
expect(file.parsed_data.keys).not_to include(*paths)
expect(file.parsed_data.values.any? { |e| patterns.include?(e.pattern) }).to be_falsey
expect(file.parsed_data.values.any? { |e| e.owner_line.blank? }).to be_falsey
end
end
context "when feature flag `:sectional_codeowners` is enabled" do
using RSpec::Parameterized::TableSyntax
......
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