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

lint.rb « command « bundler_checksum « lib « bundler-checksum « gems « vendor - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 01da04ce27cdf3c03c2fad8a8407edbe069f3c07 (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
# frozen_string_literal: true

require 'set'

module BundlerChecksum::Command
  module Lint
    extend self

    def execute
      linted = true

      Bundler.definition.resolve.sort_by(&:name).each do |spec|
        next unless spec.source.is_a?(Bundler::Source::Rubygems)

        unless checksum_for?(spec.name)
          $stderr.puts "ERROR: Missing checksum for gem `#{spec.name}`"
          linted = false
        end
      end

      unless linted
        $stderr.puts <<~MSG

          Please run `bundle exec bundler-checksum init` to add missing checksums.
        MSG
      end

      linted
    end

    private

    def checksum_for?(name)
      gems_with_checksums.include?(name)
    end

    def gems_with_checksums
      @gems_with_checksums ||= local_checksums.map { |hash| hash[:name] }.to_set
    end

    def local_checksums
      ::BundlerChecksum.checksums_from_file
    end
  end
end