Class: Gitlab::Checks::GlobalFileSizeCheck

Inherits:
BaseBulkChecker show all
Defined in:
lib/gitlab/checks/global_file_size_check.rb

Constant Summary collapse

LOG_MESSAGE =
'Checking for blobs over the file size limit'

Instance Attribute Summary

Attributes inherited from BaseBulkChecker

#changes_access

Instance Method Summary collapse

Methods inherited from BaseBulkChecker

#initialize

Constructor Details

This class inherits a constructor from Gitlab::Checks::BaseBulkChecker

Instance Method Details

#validate!Object



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
# File 'lib/gitlab/checks/global_file_size_check.rb', line 8

def validate!
  return unless Feature.enabled?(:global_file_size_check, project)

  Gitlab::AppJsonLogger.info(LOG_MESSAGE)
  logger.log_timed(LOG_MESSAGE) do
    oversized_blobs = Gitlab::Checks::FileSizeCheck::HookEnvironmentAwareAnyOversizedBlobs.new(
      project: project,
      changes: changes,
      file_size_limit_megabytes: file_size_limit
    ).find

    if oversized_blobs.present?
      Gitlab::AppJsonLogger.info(
        message: 'Found blob over global limit',
        blob_sizes: oversized_blobs.map(&:size)
      )

      if enforce_global_file_size_limit?
        raise ::Gitlab::GitAccess::ForbiddenError,
          "Changes include a file that is larger than the allowed size of #{file_size_limit} MiB. " \
          "Use Git LFS to manage this file.)"
      end
    end
  end

  true
end