diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-17 06:09:21 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-17 06:09:21 +0000 |
commit | c8df22c555ab707a705e57c4257fd3ed1ce7c3b0 (patch) | |
tree | 009fb7c1ff12a6192921212cae404b790fd7d66b /lib/gitlab/checks | |
parent | 9345f69894862e02f3491ea3136c3ed2b23fd5b8 (diff) | |
download | gitlab-ce-c8df22c555ab707a705e57c4257fd3ed1ce7c3b0.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/checks')
-rw-r--r-- | lib/gitlab/checks/push_file_count_check.rb | 37 | ||||
-rw-r--r-- | lib/gitlab/checks/snippet_check.rb | 5 |
2 files changed, 38 insertions, 4 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 diff --git a/lib/gitlab/checks/snippet_check.rb b/lib/gitlab/checks/snippet_check.rb index 8bb6c576204..bcecd0fc251 100644 --- a/lib/gitlab/checks/snippet_check.rb +++ b/lib/gitlab/checks/snippet_check.rb @@ -20,14 +20,11 @@ module Gitlab @logger.append_message("Running checks for ref: #{@branch_name || @tag_name}") end - def exec + def validate! if creation? || deletion? raise GitAccess::ForbiddenError, ERROR_MESSAGES[:create_delete_branch] end - # TODO: https://gitlab.com/gitlab-org/gitlab/issues/205628 - # Check operation will not result in more than one file in the repository - true end |