Class: Overcommit::Hook::PreCommit::ChamberCompare

Inherits:
Base
  • Object
show all
Defined in:
lib/overcommit/hook/pre_commit/chamber_compare.rb

Overview

Runs ‘chamber compare` against a configurable set of namespaces.

rubocop:disable Metrics/MethodLength

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

#applicable_files, #command, #description, #enabled?, #excluded?, #execute, #execute_in_background, #flags, #in_path?, #included_files, #initialize, #name, #parallelize?, #processors, #quiet?, #required?, #required_executable, #required_libraries, #run?, #run_and_transform, #skip?

Constructor Details

This class inherits a constructor from Overcommit::Hook::Base

Instance Method Details

#runObject



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
# File 'lib/overcommit/hook/pre_commit/chamber_compare.rb', line 9

def run
  config['namespaces'].each_index do |index|
    first  = config['namespaces'][index]
    second = config['namespaces'][index + 1]

    next unless second

    result = execute(
      command,
      args: [
              "--first=#{first.join(' ')}",
              "--second=#{second.join(' ')}",
            ],
             )

    unless result.stdout.empty?
      trimmed_result = result.stdout.split("\n")
      5.times { trimmed_result.shift }
      trimmed_result = trimmed_result.join("\n")

      return [
               :warn,
               "It appears your namespace settings between #{first} and " \
               "#{second} are not in sync:\n\n#{trimmed_result}\n\n" \
               "Run: chamber compare --first=#{first.join(' ')} " \
               "--second=#{second.join(' ')}",
             ]
    end
  end

  :pass
end