Commit bc048d82 authored by Sean McGivern's avatar Sean McGivern

Merge branch '12137-ignore-section-headers-in-legacy-parsing-of-codeowners-file' into 'master'

Skip section headers in legacy file parsing

See merge request gitlab-org/gitlab!32270
parents b8be76f7 08e322a6
......@@ -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
......@@ -44,7 +59,7 @@ describe Gitlab::CodeOwners::File do
stub_feature_flags(sectional_codeowners: true)
end
shared_examples_for "creates expected parsed results" do
shared_examples_for "creates expected parsed sectional results" do
it "is a hash sorted by sections without duplicates" do
data = file.parsed_data
......@@ -102,7 +117,7 @@ describe Gitlab::CodeOwners::File do
File.read(Rails.root.join("ee", "spec", "fixtures", "sectional_codeowners_example"))
end
it_behaves_like "creates expected parsed results"
it_behaves_like "creates expected parsed sectional results"
end
context "when CODEOWNERS file contains multiple sections with mixed-case names" do
......@@ -110,7 +125,7 @@ describe Gitlab::CodeOwners::File do
File.read(Rails.root.join("ee", "spec", "fixtures", "mixed_case_sectional_codeowners_example"))
end
it_behaves_like "creates expected parsed results"
it_behaves_like "creates expected parsed sectional results"
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