diff --git a/ee/lib/gitlab/code_owners/file.rb b/ee/lib/gitlab/code_owners/file.rb index aae9565e5a305c6545fd3c6efebcf72df7c3af0b..974357baaeeab97b4d8d346a5d817f982ea04bb2 100644 --- a/ee/lib/gitlab/code_owners/file.rb +++ b/ee/lib/gitlab/code_owners/file.rb @@ -65,7 +65,7 @@ def entries_for_path(path) matches = [] parsed_data.each do |_, section_entries| - if Feature.enabled?(:codeowners_file_exclusions, project) + if codeowners_file_exclusions_enabled? matching_patterns = section_entries.keys.reverse.select { |pattern| path_matches?(pattern, path) } matching_entries = matching_patterns.map { |pattern| section_entries[pattern] } @@ -93,6 +93,10 @@ def valid? private + def codeowners_file_exclusions_enabled? + Feature.enabled?(:codeowners_file_exclusions, project) + end + def project @blob&.repository&.project end @@ -150,32 +154,39 @@ def get_parsed_data end def parse_entry(line, parsed, section, line_number) + pattern, entry_owners, is_exclusion_pattern = extract_entry_info(line) + normalized_pattern = normalize_pattern(pattern) + owners = validate_and_get_owners(entry_owners, section, line_number) unless is_exclusion_pattern + + parsed[section.name][normalized_pattern] = Entry.new( + pattern, + owners, + section: section.name, + optional: section.optional, + approvals_required: section.approvals, + exclusion: is_exclusion_pattern, + line_number: line_number + ) + end + + def extract_entry_info(line) pattern, _separator, entry_owners = line.partition(/(?