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

repository_size_error_message.rb « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e7d527dd4ce5012f74af87c4a0b22f43b960cedb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# frozen_string_literal: true

module Gitlab
  class RepositorySizeErrorMessage
    include ActiveSupport::NumberHelper

    delegate :current_size, :limit, :exceeded_size, :additional_repo_storage_available?, to: :@checker

    # @param checker [RepositorySizeChecker]
    def initialize(checker, message_params = {})
      @message_params = message_params
      @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_warning
      _("##### WARNING ##### You have used %{usage_percentage} of the storage quota for %{namespace_name} " \
        "(%{current_size} of %{size_limit}). If %{namespace_name} exceeds the storage quota, " \
        "all projects in the namespace will be locked and actions will be restricted. " \
        "To manage storage, or purchase additional storage, see %{manage_storage_url}. " \
        "To learn more about restricted actions, see %{restricted_actions_url}") % push_message_params
    end

    def push_error(change_size = 0)
      "Your push has been rejected, #{base_message(change_size)}. #{more_info_message}"
    end

    def new_changes_error
      if additional_repo_storage_available?
        "Your push to this repository has been rejected because it would exceed storage limits. #{more_info_message}"
      else
        "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
    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

    attr_reader :message_params

    def push_message_params
      {
        namespace_name: message_params[:namespace_name],
        manage_storage_url: help_page_url('user/usage_quotas', 'manage-your-storage-usage'),
        restricted_actions_url: help_page_url('user/read_only_namespaces', 'restricted-actions'),
        current_size: formatted(current_size),
        size_limit: formatted(limit),
        usage_percentage: usage_percentage
      }
    end

    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

    def usage_percentage
      number_to_percentage(@checker.usage_ratio * 100, precision: 0)
    end

    def help_page_url(path, anchor = nil)
      ::Gitlab::Routing.url_helpers.help_page_url(path, anchor: anchor)
    end
  end
end