Class: Saddler::Reporter::Support::Git::Repository
- Inherits:
-
Object
- Object
- Saddler::Reporter::Support::Git::Repository
- Defined in:
- lib/saddler/reporter/support/git/repository.rb
Instance Method Summary collapse
- #current_branch ⇒ Object
- #github_api_endpoint ⇒ Object
-
#github_domain ⇒ Object
FIXME: if endpoint set, this return wrong result.
- #head ⇒ Object
-
#initialize(path) ⇒ Repository
constructor
A new instance of Repository.
- #remote_urls ⇒ Object
- #slug ⇒ Object
- #strip_git_extension(name) ⇒ Object
Constructor Details
#initialize(path) ⇒ Repository
Returns a new instance of Repository.
6 7 8 |
# File 'lib/saddler/reporter/support/git/repository.rb', line 6 def initialize(path) @git = ::Git.open(path) end |
Instance Method Details
#current_branch ⇒ Object
28 29 30 |
# File 'lib/saddler/reporter/support/git/repository.rb', line 28 def current_branch @git.current_branch end |
#github_api_endpoint ⇒ Object
49 50 51 |
# File 'lib/saddler/reporter/support/git/repository.rb', line 49 def github_api_endpoint ENV['GITHUB_API_ENDPOINT'] || 'api.github.com' end |
#github_domain ⇒ Object
FIXME: if endpoint set, this return wrong result
42 43 44 45 46 47 |
# File 'lib/saddler/reporter/support/git/repository.rb', line 42 def github_domain github_api_endpoint .split('.') .slice(-2, 2) .join('.') end |
#head ⇒ Object
32 33 34 |
# File 'lib/saddler/reporter/support/git/repository.rb', line 32 def head @git.object('HEAD') end |
#remote_urls ⇒ Object
21 22 23 24 25 26 |
# File 'lib/saddler/reporter/support/git/repository.rb', line 21 def remote_urls @git .branches .remote .map { |branch| branch.remote.url } end |
#slug ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/saddler/reporter/support/git/repository.rb', line 10 def slug name = /[[:alnum:]_\-\.]*/ repo = /[[:alnum:]_\-\.]*/ regex_slug = %r{#{name}/#{repo}} regex = /.*?#{Regexp.quote(github_domain)}.*?(?<slug>#{regex_slug})/ target = remote_urls.map do |url| match = regex.match(strip_git_extension(url)) match[:slug] if match end.compact.first end |
#strip_git_extension(name) ⇒ Object
36 37 38 39 |
# File 'lib/saddler/reporter/support/git/repository.rb', line 36 def strip_git_extension(name) match = /\A(?<identity>.*?)(?:\.git)?\z/.match(name) match[:identity] if match end |