class Churn::GitAnalyzer

Analyzes git SCM to find recently changed files, and what lines have been altered

Public Class Methods

supported?() click to toggle source

@return [Boolean]

# File lib/churn/scm/git_analyzer.rb, line 7
def self.supported?
  !!(`git branch 2>&1` && $?.success?)
end

Public Instance Methods

generate_history(starting_point) click to toggle source
# File lib/churn/scm/git_analyzer.rb, line 21
def generate_history(starting_point)
  get_commit_history.each do |commit|
    `git checkout #{commit}`
    commit_date = `git show -s --format="%ci"`
    commit_date = Time.parse(commit_date)
    next if commit_date < starting_point
    #7776000 == 3.months without adding active support depenancy
    start_date  = (commit_date - 7776000)
    `churn -s "#{start_date}"`
  end
ensure
  `git checkout master`
end
get_logs() click to toggle source

@return [Array]

# File lib/churn/scm/git_analyzer.rb, line 12
def get_logs
  `git log #{date_range} --name-only --pretty=format:`.split(/\n/).reject{|line| line == ""}
end
get_revisions() click to toggle source

@return [Array]

# File lib/churn/scm/git_analyzer.rb, line 17
def get_revisions
  `git log #{date_range} --pretty=format:"%H"`.split(/\n/).reject{|line| line == ""}
end

Private Instance Methods

date_range() click to toggle source
# File lib/churn/scm/git_analyzer.rb, line 45
def date_range
  if @start_date
    date = Chronic.parse(@start_date)
    "--after=#{date.strftime('%Y-%m-%d')}"
  end
end
get_commit_history() click to toggle source
# File lib/churn/scm/git_analyzer.rb, line 37
def get_commit_history
  `git log --reverse --pretty=format:"%H"`.split(/\n/).reject{|line| line == ""}
end
get_diff(revision, previous_revision) click to toggle source
# File lib/churn/scm/git_analyzer.rb, line 41
def get_diff(revision, previous_revision)
  `git diff #{revision} #{previous_revision} --no-ext-diff --unified=0`.split(/\n/).select{|line| /^@@|^---|^\+\+\+/ =~ line }
end