Sha256: 7484ec0a8ed0a6765f06499e395525567c4fa584adaccaebfaab8cd41230d17f

Contents?: true

Size: 1.13 KB

Versions: 30

Compression:

Stored size: 1.13 KB

Contents

module Overcommit::Hook::PostCommit
  # Calculates the change in blame since the last revision.
  #
  # @see https://www.npmjs.com/package/git-guilt
  class GitGuilt < Base
    PLUS_MINUS_REGEX = /^(.*?)(?:(\++)|(-+))$/
    GREEN = 32
    RED = 31

    def run
      return :pass if initial_commit?
      result = execute(command)
      return :fail, result.stderr unless result.success?

      return :pass if result.stdout.strip.empty?

      output = []
      result.stdout.scan(PLUS_MINUS_REGEX) do |user, plus, minus|
        plus = color(GREEN, plus)
        minus = color(RED, minus)
        output << "#{user}#{plus}#{minus}"
      end

      [:warn, output.join("\n")]
    end

    private

    # Returns text wrapped in ANSI escape code necessary to produce a given
    # color/text display.
    #
    # Taken from Overcommit::Logger as a temporary workaround.
    # TODO: expose logger instance to hooks for colorized output
    #
    # @param code [String] ANSI escape code, e.g. '1;33' for "bold yellow"
    # @param str [String] string to wrap
    def color(code, str)
      STDOUT.tty? ? "\033[#{code}m#{str}\033[0m" : str
    end
  end
end

Version data entries

30 entries across 28 versions & 2 rubygems

Version Path
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/overcommit-0.46.0/lib/overcommit/hook/post_commit/git_guilt.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/overcommit-0.46.0/lib/overcommit/hook/post_commit/git_guilt.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/overcommit-0.46.0/lib/overcommit/hook/post_commit/git_guilt.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/overcommit-0.46.0/lib/overcommit/hook/post_commit/git_guilt.rb
overcommit-0.46.0 lib/overcommit/hook/post_commit/git_guilt.rb
overcommit-0.45.0 lib/overcommit/hook/post_commit/git_guilt.rb
overcommit-0.44.0 lib/overcommit/hook/post_commit/git_guilt.rb
overcommit-0.43.0 lib/overcommit/hook/post_commit/git_guilt.rb
overcommit-0.42.0 lib/overcommit/hook/post_commit/git_guilt.rb
overcommit-0.41.0 lib/overcommit/hook/post_commit/git_guilt.rb
overcommit-0.40.0 lib/overcommit/hook/post_commit/git_guilt.rb
overcommit-0.39.1 lib/overcommit/hook/post_commit/git_guilt.rb
overcommit-0.39.0 lib/overcommit/hook/post_commit/git_guilt.rb
overcommit-0.38.0 lib/overcommit/hook/post_commit/git_guilt.rb
overcommit-0.37.0 lib/overcommit/hook/post_commit/git_guilt.rb
overcommit-0.36.0 lib/overcommit/hook/post_commit/git_guilt.rb
overcommit-0.35.0 lib/overcommit/hook/post_commit/git_guilt.rb
overcommit-0.34.2 lib/overcommit/hook/post_commit/git_guilt.rb
overcommit-0.34.1 lib/overcommit/hook/post_commit/git_guilt.rb
overcommit-0.34.0 lib/overcommit/hook/post_commit/git_guilt.rb