diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-31 21:07:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-31 21:07:42 +0300 |
commit | 580622bdb3c762a8e89facd8a3946881ee480442 (patch) | |
tree | 3ac9d759da23f78f95f50684bd238a9f76839538 /lib | |
parent | b211a4ea14d5e9ed9b0c248a4e8c5c1d85b542cb (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/repository_size_checker.rb | 44 | ||||
-rw-r--r-- | lib/gitlab/repository_size_error_message.rb | 48 | ||||
-rw-r--r-- | lib/gitlab/url_blocker.rb | 4 | ||||
-rw-r--r-- | lib/sentry/client.rb | 1 | ||||
-rw-r--r-- | lib/sentry/client/issue.rb | 1 |
5 files changed, 95 insertions, 3 deletions
diff --git a/lib/gitlab/repository_size_checker.rb b/lib/gitlab/repository_size_checker.rb new file mode 100644 index 00000000000..cf1af844439 --- /dev/null +++ b/lib/gitlab/repository_size_checker.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +module Gitlab + # Centralized class for repository size related calculations. + class RepositorySizeChecker + attr_reader :limit + + def initialize(current_size_proc:, limit:, enabled: true) + @current_size_proc = current_size_proc + @limit = limit + @enabled = enabled && limit != 0 + end + + def current_size + @current_size ||= @current_size_proc.call + end + + def enabled? + @enabled + end + + def above_size_limit? + return false unless enabled? + + current_size > limit + end + + # @param change_size [int] in bytes + def changes_will_exceed_size_limit?(change_size) + return false unless enabled? + + change_size > limit || exceeded_size(change_size) > 0 + end + + # @param change_size [int] in bytes + def exceeded_size(change_size = 0) + current_size + change_size - limit + end + + def error_message + @error_message_object ||= Gitlab::RepositorySizeErrorMessage.new(self) + end + end +end diff --git a/lib/gitlab/repository_size_error_message.rb b/lib/gitlab/repository_size_error_message.rb new file mode 100644 index 00000000000..556190453de --- /dev/null +++ b/lib/gitlab/repository_size_error_message.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +module Gitlab + class RepositorySizeErrorMessage + include ActiveSupport::NumberHelper + + delegate :current_size, :limit, :exceeded_size, to: :@checker + + # @param checher [RepositorySizeChecker] + def initialize(checker) + @checker = checker + end + + def commit_error + "Your changes could not be committed, #{base_message}" + end + + def merge_error + "This merge request cannot be merged, #{base_message}" + end + + def push_error(change_size = 0) + "Your push has been rejected, #{base_message(change_size)}. #{more_info_message}" + end + + def new_changes_error + "Your push to this repository would cause it to exceed the size limit of #{formatted(limit)} so it has been rejected. #{more_info_message}" + end + + def more_info_message + 'Please contact your GitLab administrator for more information.' + end + + def above_size_limit_message + "The size of this repository (#{formatted(current_size)}) exceeds the limit of #{formatted(limit)} by #{formatted(exceeded_size)}. You won't be able to push new code to this project. #{more_info_message}" + end + + private + + def base_message(change_size = 0) + "because this repository has exceeded its size limit of #{formatted(limit)} by #{formatted(exceeded_size(change_size))}" + end + + def formatted(number) + number_to_human_size(number, delimiter: ',', precision: 2) + end + end +end diff --git a/lib/gitlab/url_blocker.rb b/lib/gitlab/url_blocker.rb index 88094839062..9213b5ebab2 100644 --- a/lib/gitlab/url_blocker.rb +++ b/lib/gitlab/url_blocker.rb @@ -11,8 +11,8 @@ module Gitlab # Validates the given url according to the constraints specified by arguments. # # ports - Raises error if the given URL port does is not between given ports. - # allow_localhost - Raises error if URL resolves to a localhost IP address and argument is true. - # allow_local_network - Raises error if URL resolves to a link-local address and argument is true. + # allow_localhost - Raises error if URL resolves to a localhost IP address and argument is false. + # allow_local_network - Raises error if URL resolves to a link-local address and argument is false. # ascii_only - Raises error if URL has unicode characters and argument is true. # enforce_user - Raises error if URL user doesn't start with alphanumeric characters and argument is true. # enforce_sanitization - Raises error if URL includes any HTML/CSS/JS tags and argument is true. diff --git a/lib/sentry/client.rb b/lib/sentry/client.rb index 36ec1caf80c..dbf54a65081 100644 --- a/lib/sentry/client.rb +++ b/lib/sentry/client.rb @@ -10,7 +10,6 @@ module Sentry Error = Class.new(StandardError) MissingKeysError = Class.new(StandardError) - ResponseInvalidSizeError = Class.new(StandardError) attr_accessor :url, :token diff --git a/lib/sentry/client/issue.rb b/lib/sentry/client/issue.rb index 986311ab62a..4a62b73a349 100644 --- a/lib/sentry/client/issue.rb +++ b/lib/sentry/client/issue.rb @@ -4,6 +4,7 @@ module Sentry class Client module Issue BadRequestError = Class.new(StandardError) + ResponseInvalidSizeError = Class.new(StandardError) SENTRY_API_SORT_VALUE_MAP = { # <accepted_by_client> => <accepted_by_sentry_api> |