Class: BBNW::GitRepos

Inherits:
Object
  • Object
show all
Includes:
Commits
Defined in:
lib/adapters/git.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Commits

included

Constructor Details

#initialize(working_dir, committer = nil, start_date = nil, end_date = nil, debug = false) ⇒ GitRepos

Returns a new instance of GitRepos.



12
13
14
15
16
17
18
# File 'lib/adapters/git.rb', line 12

def initialize(working_dir, committer = nil, start_date = nil, end_date = nil, debug = false)
  @git = Grit::Repo.new(working_dir)

  @committer  = committer
  @start_date = start_date
  @end_date   = end_date
end

Instance Attribute Details

#commitsObject

Returns the value of attribute commits.



10
11
12
# File 'lib/adapters/git.rb', line 10

def commits
  @commits
end

Instance Method Details

#get_commitsObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/adapters/git.rb', line 33

def get_commits
  user_commits = []
  commits      = @git.commits_since('master',@start_date.strftime("%Y-%m-%d"))
  start_date   =  Time.new(@start_date.year, @start_date.month, @start_date.day, 0, 0, 0)
  end_date     =  Time.new(@end_date.year, @end_date.month, @end_date.day, 23, 59, 59)

  commits.each do |commit|
    if (commit.author.to_s =~ /#{@committer}/i || @committer.nil?) &&
       (start_date.nil? || commit.committed_date >= start_date) &&
       (end_date.nil? || commit.committed_date <= end_date)
      user_commits << BBNW::Commit.new(commit.id, commit.message, commit.committer.to_s, commit.committed_date, total_changes(commit))
    end
  end

  user_commits
end

#total_changes(commit) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/adapters/git.rb', line 24

def total_changes(commit)
  total = 0
  stats = commit.stats
  stats.files.each do |f|
    total+=f[3]
  end
  total
end