Sha256: 67f8506bd9ba95c19dd68f8befcf94a6c10561d214979e505e0afcfab8d216da

Contents?: true

Size: 902 Bytes

Versions: 2

Compression:

Stored size: 902 Bytes

Contents

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

require 'git'

module Danger
  class GitRepo
    attr_accessor :diff
    attr_accessor :log

    def diff_for_folder(folder, from: "master", to: 'HEAD')
      repo = Git.open folder
      self.diff = repo.diff(from, to)
      self.log = repo.log.between(from, to)
    end

    def exec(string)
      `git #{string}`.strip
    end

    def added_files
      Danger::FileList.new(@diff.select { |diff| diff.type == "new" }.map(&:path))
    end

    def deleted_files
      Danger::FileList.new(@diff.select { |diff| diff.type == "deleted" }.map(&:path))
    end

    def modified_files
      Danger::FileList.new(@diff.stats[:files].keys)
    end

    def lines_of_code
      @diff.lines
    end

    def deletions
      @diff.deletions
    end

    def insertions
      @diff.insertions
    end

    def commits
      log.to_a
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
danger-0.7.4 lib/danger/scm_source/git_repo.rb
danger-0.7.3 lib/danger/scm_source/git_repo.rb