Class: Churn::GitAnalyzer

Inherits:
SourceControl show all
Defined in:
lib/churn/scm/git_analyzer.rb

Overview

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SourceControl

#get_updated_files_change_info, #get_updated_files_from_log, #initialize, set_source_control

Constructor Details

This class inherits a constructor from Churn::SourceControl

Class Method Details

.supported?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/churn/scm/git_analyzer.rb', line 6

def self.supported?
  !!(`git branch 2>&1` && $?.success?)
end

Instance Method Details

#generate_history(starting_point) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/churn/scm/git_analyzer.rb', line 18

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_logsObject



10
11
12
# File 'lib/churn/scm/git_analyzer.rb', line 10

def get_logs
  `git log #{date_range} --name-only --pretty=format:`.split(/\n/).reject{|line| line == ""}
end

#get_revisionsObject



14
15
16
# File 'lib/churn/scm/git_analyzer.rb', line 14

def get_revisions
  `git log #{date_range} --pretty=format:"%H"`.split(/\n/).reject{|line| line == ""}
end