Class: CodeRepository

Inherits:
Object
  • Object
show all
Defined in:
lib/code_repository.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repository_path, from_commit, to_commit = nil) ⇒ CodeRepository

Returns a new instance of CodeRepository.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/code_repository.rb', line 5

def initialize(repository_path,from_commit,to_commit = nil)
  @commits  = []
  @repo = Rugged::Repository.new(repository_path)

  to_commit ||= get_head_ish
  walker = @repo.walk(to_commit)

  walker.each { |c|
    @commits << c
    break if c.oid == from_commit
  }
end

Instance Attribute Details

#commitsObject (readonly)

Returns the value of attribute commits.



4
5
6
# File 'lib/code_repository.rb', line 4

def commits
  @commits
end

Instance Method Details

#contributors(commit_list) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/code_repository.rb', line 18

def contributors(commit_list)

  return [] if commit_list.empty?
  author_names = []
  commit_list.each do |oid|
    c = @repo.lookup(oid)
    next unless @commits.map(&:oid).include?(c.oid)
    author = c.author
    names = author[:name]
    names = names.split("&")
    names.each{|n|
       n =n.strip
       author_names << n unless author_names.include?(n)
    }
  end
  author_names
end

#get_head_ishObject



36
37
38
# File 'lib/code_repository.rb', line 36

def get_head_ish
  @repo.head.target
end

#lookup(oid) ⇒ Object



40
41
42
# File 'lib/code_repository.rb', line 40

def lookup(oid)
  @repo.lookup(oid)
end