Class: IssueBeaver::Models::Git
- Inherits:
-
Object
- Object
- IssueBeaver::Models::Git
- Defined in:
- lib/issue_beaver/models/git.rb
Instance Attribute Summary collapse
-
#root_dir ⇒ Object
readonly
Returns the value of attribute root_dir.
Instance Method Summary collapse
- #discover_github_repo(repo_name) ⇒ Object
- #files(dir) ⇒ Object
- #github_user ⇒ Object
- #head_commit ⇒ Object
-
#initialize(dir, repo_name) ⇒ Git
constructor
A new instance of Git.
- #is_ahead?(commit) ⇒ Boolean
- #labels ⇒ Object
- #slug ⇒ Object
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_dir ⇒ Object (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 40 41 |
# 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"] match = url.match(/git@github\.com:([^\.]+)\.git/) || url.match(/https?:\/\/github\.com\/([^\.]+)\/?/) github_repo = match[1] if url end github_repo end |
#files(dir) ⇒ Object
44 45 46 47 |
# File 'lib/issue_beaver/models/git.rb', line 44 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_user ⇒ Object
21 22 23 |
# File 'lib/issue_beaver/models/git.rb', line 21 def github_user @github_user ||= @git.config['github.user'] end |
#head_commit ⇒ Object
50 51 52 |
# File 'lib/issue_beaver/models/git.rb', line 50 def head_commit @head_commit ||= `git rev-parse HEAD`.chomp end |
#is_ahead?(commit) ⇒ Boolean
55 56 57 58 |
# File 'lib/issue_beaver/models/git.rb', line 55 def is_ahead?(commit) return false unless commit !`git rev-list "#{head_commit}" | grep $(git rev-parse "#{commit}")`.chomp.empty? end |
#labels ⇒ Object
25 26 27 |
# File 'lib/issue_beaver/models/git.rb', line 25 def labels @labels ||= (@git.config['issuebeaver.labels'] || "").split(',') end |
#slug ⇒ Object
16 17 18 |
# File 'lib/issue_beaver/models/git.rb', line 16 def slug @slug ||= discover_github_repo(@repo_name) end |