Class: Bugwatch::Repo

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

Constant Summary collapse

REPO_PATH =
'repos'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, url) ⇒ Repo

Returns a new instance of Repo.



43
44
45
46
# File 'lib/bugwatch/repo.rb', line 43

def initialize(name, url)
  @name = name
  @url = url
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



37
38
39
# File 'lib/bugwatch/repo.rb', line 37

def name
  @name
end

#urlObject (readonly)

Returns the value of attribute url.



37
38
39
# File 'lib/bugwatch/repo.rb', line 37

def url
  @url
end

Class Method Details

.discover(name, url) ⇒ Object



39
40
41
# File 'lib/bugwatch/repo.rb', line 39

def self.discover(name, url)
  new(name, url).tap {|repo| repo.discover! }
end

Instance Method Details

#analyze(caching_strategy, *analyzers) ⇒ Object



77
78
79
# File 'lib/bugwatch/repo.rb', line 77

def analyze(caching_strategy, *analyzers)
  Analysis.new(self, caching_strategy).analyze(*analyzers)
end

#analyze!(caching_strategy, analyzers, begin_sha = nil) ⇒ Object



68
69
70
71
# File 'lib/bugwatch/repo.rb', line 68

def analyze!(caching_strategy, analyzers, begin_sha=nil)
  import(caching_strategy, begin_sha)
  analyze(caching_strategy, *analyzers)
end

#clone!Object



56
57
58
# File 'lib/bugwatch/repo.rb', line 56

def clone!
  Kernel.system("cd #{REPO_PATH}; git clone #{url} #{name}")
end

#commit(sha) ⇒ Object



91
92
93
94
# File 'lib/bugwatch/repo.rb', line 91

def commit(sha)
  grit_commit = grit.commit(sha)
  Commit.from_grit(grit_commit) if grit_commit
end

#commit_shas(begin_sha = nil) ⇒ Object



96
97
98
# File 'lib/bugwatch/repo.rb', line 96

def commit_shas(begin_sha=nil)
  rugged_repo.walk(sha_or_head(begin_sha)).map(&:oid)
end

#commits(begin_sha = nil) ⇒ Object



85
86
87
88
89
# File 'lib/bugwatch/repo.rb', line 85

def commits(begin_sha=nil)
  rugged_repo.walk(sha_or_head(begin_sha)).map do |rugged_commit|
    self.commit(rugged_commit.oid)
  end
end

#discover!Object



48
49
50
51
52
53
54
# File 'lib/bugwatch/repo.rb', line 48

def discover!
  if exists?
    update!
  else
    clone!
  end
end

#exists?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/bugwatch/repo.rb', line 64

def exists?
  File.exists?(path_to_repo)
end

#gritObject



104
105
106
# File 'lib/bugwatch/repo.rb', line 104

def grit
  @grit ||= Grit::Repo.new(path_to_repo)
end

#headObject



81
82
83
# File 'lib/bugwatch/repo.rb', line 81

def head
  rugged_repo.head.target
end

#import(caching_strategy, begin_sha = nil) ⇒ Object



73
74
75
# File 'lib/bugwatch/repo.rb', line 73

def import(caching_strategy, begin_sha=nil)
  Import.new(self, caching_strategy).import(sha_or_head(begin_sha))
end

#tagsObject



108
109
110
111
112
# File 'lib/bugwatch/repo.rb', line 108

def tags
  grit_tags.map do |tag|
    Tag.new(tag)
  end
end

#treeObject



100
101
102
# File 'lib/bugwatch/repo.rb', line 100

def tree
  Tree.new(grit.tree)
end

#update!Object



60
61
62
# File 'lib/bugwatch/repo.rb', line 60

def update!
  Kernel.system("cd #{path_to_repo}; git fetch origin master; git reset --hard origin/master; git fetch --tags")
end