Commit d193b526 authored by Stan Hu's avatar Stan Hu

Revert CODEOWNERS validation of Web requests in diff check

This reverts commit 4d73ef61.

This was causing merges to fail when groups were used in CODEOWNERS:
https://gitlab.com/gitlab-org/gitlab/-/issues/216345.
parent 1035dddc
---
title: Revert CODEOWNERS validation of Web requests in diff check
merge_request: 30936
author:
type: fixed
......@@ -12,7 +12,7 @@ module EE
def path_validations
validations = [super].flatten
if project.branch_requires_code_owner_approval?(branch_name)
if !updated_from_web? && project.branch_requires_code_owner_approval?(branch_name)
validations << validate_code_owners
end
......@@ -34,13 +34,11 @@ module EE
matched_rules = loader.entries.collect { |e| "- #{e.pattern}" }
code_owner_path = project.repository.code_owners_blob(ref: branch_name).path || "CODEOWNERS"
msg = "Pushes to protected branches that contain changes to files that\n" \
"Pushes to protected branches that contain changes to files that\n" \
"match patterns defined in `#{code_owner_path}` are disabled for\n" \
"this project. Please submit these changes via a merge request.\n\n" \
"The following pattern(s) from `#{code_owner_path}` were matched:\n" \
"#{matched_rules.join('\n')}\n"
updated_from_web? ? msg.tr("\n", " ") : msg
end
def validate_path_locks?
......
......@@ -89,22 +89,8 @@ describe Gitlab::Checks::DiffCheck do
stub_feature_flags(sectional_codeowners: false)
end
context "for a non-web-based request" do
it "returns an error message" do
expect(validation_result).to include("Pushes to protected branches")
expect(validation_result).to include("\n")
end
end
context "for a web-based request" do
before do
expect(subject).to receive(:updated_from_web?).and_return(true)
end
it "returns an error message with newline chars removed" do
expect(validation_result).to include("Pushes to protected branches")
expect(validation_result).not_to include("\n")
end
it "returns an error message" do
expect(validation_result).to include("Pushes to protected branches")
end
end
......@@ -142,16 +128,30 @@ describe Gitlab::Checks::DiffCheck do
end
context "when the feature is enabled on the project" do
before do
expect(project).to receive(:branch_requires_code_owner_approval?)
.once.and_return(true)
context "updated_from_web? == false" do
before do
expect(subject).to receive(:updated_from_web?).and_return(false)
expect(project).to receive(:branch_requires_code_owner_approval?)
.once.and_return(true)
end
it "returns an array of Proc(s)" do
validations = subject.send(:path_validations)
expect(validations.any?).to be_truthy
expect(validations.any? { |v| !v.is_a? Proc }).to be_falsy
end
end
it "returns an array of Proc(s)" do
validations = subject.send(:path_validations)
context "updated_from_web? == true" do
before do
expect(subject).to receive(:updated_from_web?).and_return(true)
expect(project).not_to receive(:branch_requires_code_owner_approval?)
end
expect(validations.any?).to be_truthy
expect(validations.any? { |v| !v.is_a? Proc }).to be_falsy
it "returns an empty array" do
expect(subject.send(:path_validations)).to eq([])
end
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