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

any_oversized_blob.rb « file_size_check « checks « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dcdcd0e64ad7c72354c2a6edd2098e568c4acaad (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
# frozen_string_literal: true

module Gitlab
  module Checks
    module FileSizeCheck
      class AnyOversizedBlob
        def initialize(project:, changes:, file_size_limit_megabytes:)
          @project = project
          @newrevs = changes.pluck(:newrev).compact # rubocop:disable CodeReuse/ActiveRecord just plucking from an array
          @file_size_limit_megabytes = file_size_limit_megabytes
        end
        attr_reader :project, :newrevs, :file_size_limit_megabytes

        def find!(timeout: nil)
          blobs = project.repository.new_blobs(newrevs, dynamic_timeout: timeout)

          blobs.find do |blob|
            ::Gitlab::Utils.bytes_to_megabytes(blob.size) > file_size_limit_megabytes
          end
        end
      end
    end
  end
end