Class: IssueBeaver::Models::Git

Inherits:
Object
  • Object
show all
Defined in:
lib/issue_beaver/models/git.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir, repo_name) ⇒ Git

Returns a new instance of Git.



7
8
9
10
11
# File 'lib/issue_beaver/models/git.rb', line 7

def initialize(dir, repo_name)
  @root_dir = discover_root_dir(dir)
  @git = Grit::Repo.new(@root_dir)
  @repo_name = repo_name || @git.config['issuebeaver.repository'] || 'remote.origin'
end

Instance Attribute Details

#root_dirObject (readonly)

Returns the value of attribute root_dir.



13
14
15
# File 'lib/issue_beaver/models/git.rb', line 13

def root_dir
  @root_dir
end

Instance Method Details

#discover_github_repo(repo_name) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/issue_beaver/models/git.rb', line 30

def discover_github_repo(repo_name)
  github_repo = nil
  if repo_name.match(/[^\.]+\/[^\.]+/)
    github_repo = repo_name
  else
    url = @git.config["#{repo_name}.url"]
    github_repo = url.match(/git@github\.com:([^\.]+)\.git/)[1] if url
  end
  github_repo
end

#files(dir) ⇒ Object



42
43
44
45
# File 'lib/issue_beaver/models/git.rb', line 42

def files(dir)
  IO.popen(%Q{cd "#{@root_dir}" && git ls-files "#{dir}"}).lazy.memoizing.
    map(&:chomp).map{|file| File.absolute_path(file, @root_dir) }.lazy
end

#github_userObject



21
22
23
# File 'lib/issue_beaver/models/git.rb', line 21

def github_user
  @github_user ||= @git.config['github.user']
end

#labelsObject



25
26
27
# File 'lib/issue_beaver/models/git.rb', line 25

def labels
  @labels ||= (@git.config['issuebeaver.labels'] || "").split(',')
end

#slugObject



16
17
18
# File 'lib/issue_beaver/models/git.rb', line 16

def slug
  @slug ||= discover_github_repo(@repo_name)
end