Commit 4f3da9a5 authored by Robert Speicher's avatar Robert Speicher

Merge branch '219340-add-protected-branch-check-to-codeowners-validator' into 'master'

Confirm protected branch before running checks

Closes #219340

See merge request gitlab-org/gitlab!33310
parents d4524750 31c852ea
......@@ -10,6 +10,7 @@ module Gitlab
end
def execute
return unless @project.branch_requires_code_owner_approval?(@branch_name)
return if loader.entries.blank?
assemble_error_msg_for_codeowner_matches
......
......@@ -74,6 +74,11 @@ describe Gitlab::Checks::DiffCheck do
subject.send(:validate_code_owners).call(["docs/CODEOWNERS", "README"])
end
before do
expect(project).to receive(:branch_requires_code_owner_approval?)
.at_least(:once).and_return(true)
end
it_behaves_like "returns codeowners validation message"
end
......
......@@ -37,7 +37,36 @@ describe Gitlab::CodeOwners::Validator do
allow(project.repository).to receive(:code_owners_blob).and_return(codeowner_blob)
end
shared_examples_for "finds no errors" do
it "returns nil" do
expect(subject.execute).to be_nil
end
end
describe "#execute" do
context "when the branch does not require code owner approval" do
before do
expect(project).to receive(:branch_requires_code_owner_approval?)
.and_return(false)
end
context "when paths match entries in the codeowners file" do
it_behaves_like "finds no errors"
end
context "when paths do not match entries in the codeowners file" do
let(:paths) { "not/a/matching/path" }
it_behaves_like "finds no errors"
end
end
context "when the branch requires code owner approval" do
before do
expect(project).to receive(:branch_requires_code_owner_approval?)
.and_return(true)
end
context "when paths match entries in the codeowners file" do
it "returns an error message" do
expect(subject.execute).to include("Pushes to protected branches")
......@@ -47,8 +76,7 @@ describe Gitlab::CodeOwners::Validator do
context "when paths do not match entries in the codeowners file" do
let(:paths) { "not/a/matching/path" }
it "returns nil" do
expect(subject.execute).to be_nil
it_behaves_like "finds no errors"
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