Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2021-01-20 22:34:23 +0300
committerRobert Speicher <rspeicher@gmail.com>2021-01-20 22:34:23 +0300
commit6438df3a1e0fb944485cebf07976160184697d72 (patch)
tree00b09bfd170e77ae9391b1a2f5a93ef6839f2597 /lib/gitlab/checks
parent42bcd54d971da7ef2854b896a7b34f4ef8601067 (diff)
Add latest changes from gitlab-org/gitlab@13-8-stable-eev13.8.0-rc42
Diffstat (limited to 'lib/gitlab/checks')
-rw-r--r--lib/gitlab/checks/diff_check.rb58
1 files changed, 14 insertions, 44 deletions
diff --git a/lib/gitlab/checks/diff_check.rb b/lib/gitlab/checks/diff_check.rb
index c0b228dee59..b146fea66b9 100644
--- a/lib/gitlab/checks/diff_check.rb
+++ b/lib/gitlab/checks/diff_check.rb
@@ -6,37 +6,20 @@ module Gitlab
include Gitlab::Utils::StrongMemoize
LOG_MESSAGES = {
- validate_file_paths: "Validating diffs' file paths...",
- diff_content_check: "Validating diff contents..."
+ validate_file_paths: "Validating diffs' file paths..."
}.freeze
def validate!
return if deletion?
- return unless should_run_diff_validations?
+ return unless should_run_validations?
return if commits.empty?
- file_paths = []
-
- if ::Feature.enabled?(:diff_check_with_paths_changed_rpc, project, default_enabled: true)
- paths = project.repository.find_changed_paths(commits.map(&:sha))
- paths.each do |path|
- file_paths.concat([path.path])
-
- validate_diff(path)
- end
- else
- process_commits do |commit|
- validate_once(commit) do
- commit.raw_deltas.each do |diff|
- file_paths.concat([diff.new_path, diff.old_path].compact)
-
- validate_diff(diff)
- end
- end
- end
+ paths = project.repository.find_changed_paths(commits.map(&:sha))
+ paths.each do |path|
+ validate_path(path)
end
- validate_file_paths(file_paths.uniq)
+ validate_file_paths(paths.map(&:path).uniq)
end
private
@@ -47,43 +30,30 @@ module Gitlab
end
end
- def should_run_diff_validations?
- validations_for_diff.present? || path_validations.present?
+ def should_run_validations?
+ validations_for_path.present? || file_paths_validations.present?
end
- def validate_diff(diff)
- validations_for_diff.each do |validation|
- if error = validation.call(diff)
+ def validate_path(path)
+ validations_for_path.each do |validation|
+ if error = validation.call(path)
raise ::Gitlab::GitAccess::ForbiddenError, error
end
end
end
# Method overwritten in EE to inject custom validations
- def validations_for_diff
+ def validations_for_path
[]
end
- def path_validations
+ def file_paths_validations
validate_lfs_file_locks? ? [lfs_file_locks_validation] : []
end
- def process_commits
- logger.log_timed(LOG_MESSAGES[:diff_content_check]) do
- # n+1: https://gitlab.com/gitlab-org/gitlab/issues/3593
- ::Gitlab::GitalyClient.allow_n_plus_1_calls do
- commits.each do |commit|
- logger.check_timeout_reached
-
- yield(commit)
- end
- end
- end
- end
-
def validate_file_paths(file_paths)
logger.log_timed(LOG_MESSAGES[__method__]) do
- path_validations.each do |validation|
+ file_paths_validations.each do |validation|
if error = validation.call(file_paths)
raise ::Gitlab::GitAccess::ForbiddenError, error
end