Commit 382ab43b authored by Kerri Miller's avatar Kerri Miller Committed by Igor Drozdov

Filter by section to support sectional codeowners

parent 1de11e5d
......@@ -66,8 +66,7 @@ class ApprovalMergeRequestRule < ApplicationRecord
scope :for_checks_that_can_be_refreshed, -> { license_compliance.open_merge_requests.with_head_pipeline }
def self.find_or_create_code_owner_rule(merge_request, entry)
merge_request.approval_rules.code_owner.where(name: entry.pattern).first_or_create do |rule|
rule.section = entry.section
merge_request.approval_rules.code_owner.where(name: entry.pattern).where(section: entry.section).first_or_create do |rule|
rule.rule_type = :code_owner
rule.code_owner = true # deprecated, replaced with `rule_type: :code_owner`
end
......
......@@ -11,6 +11,7 @@ FactoryBot.define do
rule_type { :code_owner }
code_owner { true } # deprecated, replaced with `rule_type: :code_owner`
sequence(:name) { |n| "*-#{n}.js" }
section { Gitlab::CodeOwners::Entry::DEFAULT_SECTION }
end
factory :report_approver_rule, parent: :approval_merge_request_rule do
......
......@@ -169,6 +169,14 @@ RSpec.describe ApprovalMergeRequestRule do
it 'finds the existing rule' do
expect(rule).to eq(existing_code_owner_rule)
end
context "when the existing rule matches name but not section" do
let(:entry) { Gitlab::CodeOwners::Entry.new("*.rb", "@user", "example_section") }
it "creates a new rule" do
expect(rule).not_to eq(existing_code_owner_rule)
end
end
end
it 'creates a new rule if it does not exist' do
......
......@@ -125,7 +125,7 @@ RSpec.describe MergeRequests::RefreshService do
end
it_behaves_like 'creates an approval rule based on current diff' do
let(:approval_rules_size) { 4 }
let(:approval_rules_size) { 5 }
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