Sha256: 866a5ed2cfcc93648b7877837458421181e27caf00d6164683834f0f4b331870

Contents?: true

Size: 876 Bytes

Versions: 4

Compression:

Stored size: 876 Bytes

Contents

# For more info see: https://github.com/schacon/ruby-git

require 'grit'

module Danger
  class GitRepo
    attr_accessor :diff

    def diff_for_folder(folder, from: "master", to: 'HEAD')
      repo = Grit::Repo.new folder
      self.diff = repo.diff(from, to)
    end

    def files_added
      @diff.select(&:new_file).map(&:b_path)
    end

    def files_deleted
      @diff.select(&:deleted_file).map(&:a_path)
    end

    def files_modified
      @diff.reject(&:deleted_file).reject(&:new_file).map(&:a_path)
    end

    def lines_of_code
      @diff.map(&:diff).map(&:lines).flatten.count { |l| l.start_with?("+") || l.start_with?("-") }
    end

    def deletions
      @diff.map(&:diff).map(&:lines).flatten.count { |l| l.start_with?("-") }
    end

    def insertions
      @diff.map(&:diff).map(&:lines).flatten.count { |l| l.start_with?("+") }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
danger-0.6.0 lib/danger/scm_source/git_repo.rb
danger-0.5.2 lib/danger/scm_source/git_repo.rb
danger-0.5.1 lib/danger/scm_source/git_repo.rb
danger-0.5.0 lib/danger/scm_source/git_repo.rb