Sha256: 83135e620ac9a085fd4cfc48eec100fe978ee15213e8de33be59fcd2aea86d34

Contents?: true

Size: 1.33 KB

Versions: 19

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

module Overcommit::Hook::PreCommit
  # Runs `chamber compare` against a configurable set of namespaces.
  #
  # @see https://github.com/thekompanee/chamber/wiki/Git-Commit-Hooks#chamber-compare-pre-commit-hook
  # rubocop:disable Metrics/MethodLength
  class ChamberCompare < Base
    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
  end
  # rubocop:enable Metrics/MethodLength
end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
overcommit-0.58.0 lib/overcommit/hook/pre_commit/chamber_compare.rb
overcommit-0.57.0 lib/overcommit/hook/pre_commit/chamber_compare.rb
overcommit-0.56.0 lib/overcommit/hook/pre_commit/chamber_compare.rb
overcommit-0.55.0 lib/overcommit/hook/pre_commit/chamber_compare.rb
overcommit-0.54.1 lib/overcommit/hook/pre_commit/chamber_compare.rb
overcommit-0.54.0 lib/overcommit/hook/pre_commit/chamber_compare.rb
overcommit-jeygeethanmedia-0.53.1.2 lib/overcommit/hook/pre_commit/chamber_compare.rb
overcommit-jeygeethanmedia-0.53.1.1 lib/overcommit/hook/pre_commit/chamber_compare.rb
overcommit-jeygeethanmedia-0.53.1 lib/overcommit/hook/pre_commit/chamber_compare.rb
overcommit-0.53.0 lib/overcommit/hook/pre_commit/chamber_compare.rb
overcommit-0.52.1 lib/overcommit/hook/pre_commit/chamber_compare.rb
overcommit-0.52.0 lib/overcommit/hook/pre_commit/chamber_compare.rb
overcommit-0.51.0 lib/overcommit/hook/pre_commit/chamber_compare.rb
overcommit-0.50.0 lib/overcommit/hook/pre_commit/chamber_compare.rb
overcommit-0.49.1 lib/overcommit/hook/pre_commit/chamber_compare.rb
overcommit-0.49.0 lib/overcommit/hook/pre_commit/chamber_compare.rb
overcommit-0.48.1 lib/overcommit/hook/pre_commit/chamber_compare.rb
overcommit-0.48.0 lib/overcommit/hook/pre_commit/chamber_compare.rb
overcommit-0.47.0 lib/overcommit/hook/pre_commit/chamber_compare.rb