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:
Diffstat (limited to 'lib/gitlab/checks/push_file_count_check.rb')
-rw-r--r--lib/gitlab/checks/push_file_count_check.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/gitlab/checks/push_file_count_check.rb b/lib/gitlab/checks/push_file_count_check.rb
new file mode 100644
index 00000000000..288a7e0d41a
--- /dev/null
+++ b/lib/gitlab/checks/push_file_count_check.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Checks
+ class PushFileCountCheck < BaseChecker
+ attr_reader :repository, :newrev, :limit, :logger
+
+ LOG_MESSAGES = {
+ diff_content_check: "Validating diff contents being single file..."
+ }.freeze
+
+ ERROR_MESSAGES = {
+ upper_limit: "The repository can contain at most %{limit} file(s).",
+ lower_limit: "The repository must contain at least 1 file."
+ }.freeze
+
+ def initialize(change, repository:, limit:, logger:)
+ @repository = repository
+ @newrev = change[:newrev]
+ @limit = limit
+ @logger = logger
+ end
+
+ def validate!
+ file_count = repository.ls_files(newrev).size
+
+ if file_count > limit
+ raise ::Gitlab::GitAccess::ForbiddenError, ERROR_MESSAGES[:upper_limit] % { limit: limit }
+ end
+
+ if file_count == 0
+ raise ::Gitlab::GitAccess::ForbiddenError, ERROR_MESSAGES[:lower_limit]
+ end
+ end
+ end
+ end
+end