Class: Gitlab::Checks::PushFileCountCheck
- Inherits:
-
BaseSingleChecker
- Object
- BaseChecker
- BaseSingleChecker
- Gitlab::Checks::PushFileCountCheck
- Defined in:
- lib/gitlab/checks/push_file_count_check.rb
Constant Summary collapse
- 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
Instance Attribute Summary collapse
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#newrev ⇒ Object
readonly
Returns the value of attribute newrev.
-
#repository ⇒ Object
readonly
Returns the value of attribute repository.
Attributes inherited from BaseSingleChecker
Instance Method Summary collapse
-
#initialize(change, repository:, limit:, logger:) ⇒ PushFileCountCheck
constructor
A new instance of PushFileCountCheck.
- #validate! ⇒ Object
Constructor Details
#initialize(change, repository:, limit:, logger:) ⇒ PushFileCountCheck
Returns a new instance of PushFileCountCheck.
17 18 19 20 21 22 |
# File 'lib/gitlab/checks/push_file_count_check.rb', line 17 def initialize(change, repository:, limit:, logger:) @repository = repository @newrev = change[:newrev] @limit = limit @logger = logger end |
Instance Attribute Details
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
6 7 8 |
# File 'lib/gitlab/checks/push_file_count_check.rb', line 6 def limit @limit end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
6 7 8 |
# File 'lib/gitlab/checks/push_file_count_check.rb', line 6 def logger @logger end |
#newrev ⇒ Object (readonly)
Returns the value of attribute newrev.
6 7 8 |
# File 'lib/gitlab/checks/push_file_count_check.rb', line 6 def newrev @newrev end |
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
6 7 8 |
# File 'lib/gitlab/checks/push_file_count_check.rb', line 6 def repository @repository end |
Instance Method Details
#validate! ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/gitlab/checks/push_file_count_check.rb', line 24 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 |