Class: Saddler::Reporter::Support::Git::Repository
- Inherits:
-
Object
- Object
- Saddler::Reporter::Support::Git::Repository
- Defined in:
- lib/saddler/reporter/support/git/repository.rb
Instance Attribute Summary collapse
-
#git ⇒ Object
readonly
Returns the value of attribute git.
Instance Method Summary collapse
- #current_branch ⇒ Object
- #env_current_branch ⇒ Object
-
#env_push_endpoint ⇒ Object
e.g.
- #head ⇒ Object
-
#initialize(path, options = {}) ⇒ Repository
constructor
A new instance of Repository.
- #master ⇒ Object
- #merge_commit?(commit) ⇒ Boolean
-
#merging_object ⇒ Object
This for GitHub pull request diff file.
- #merging_sha ⇒ Object
- #origin_master ⇒ Object
- #push_endpoint ⇒ Object
- #remote_urls ⇒ Object
- #slug ⇒ Object
Constructor Details
#initialize(path, options = {}) ⇒ Repository
Returns a new instance of Repository.
8 9 10 |
# File 'lib/saddler/reporter/support/git/repository.rb', line 8 def initialize(path, = {}) @git = ::Git.open(path, ) end |
Instance Attribute Details
#git ⇒ Object (readonly)
Returns the value of attribute git.
6 7 8 |
# File 'lib/saddler/reporter/support/git/repository.rb', line 6 def git @git end |
Instance Method Details
#current_branch ⇒ Object
27 28 29 |
# File 'lib/saddler/reporter/support/git/repository.rb', line 27 def current_branch env_current_branch || @git.current_branch end |
#env_current_branch ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/saddler/reporter/support/git/repository.rb', line 76 def env_current_branch if ENV['CURRENT_BRANCH'] ENV['CURRENT_BRANCH'] elsif ENV['TRAVIS_BRANCH'] ENV['TRAVIS_BRANCH'] elsif ENV['CIRCLE_BRANCH'] ENV['CIRCLE_BRANCH'] end end |
#env_push_endpoint ⇒ Object
e.g. ‘github.com’ [email protected]:packsaddle/ruby-saddler-reporter-support-git.git
70 71 72 73 74 |
# File 'lib/saddler/reporter/support/git/repository.rb', line 70 def env_push_endpoint if ENV['PUSH_ENDPOINT'] ENV['PUSH_ENDPOINT'] end end |
#head ⇒ Object
31 32 33 |
# File 'lib/saddler/reporter/support/git/repository.rb', line 31 def head @git.object('HEAD') end |
#master ⇒ Object
52 53 54 |
# File 'lib/saddler/reporter/support/git/repository.rb', line 52 def master @git.object('master') end |
#merge_commit?(commit) ⇒ Boolean
60 61 62 |
# File 'lib/saddler/reporter/support/git/repository.rb', line 60 def merge_commit?(commit) commit.parents.count == 2 end |
#merging_object ⇒ Object
This for GitHub pull request diff file. if head is commit which already merged, head’s parent objects include merging object and (master or origin/master)
43 44 45 46 47 48 49 50 |
# File 'lib/saddler/reporter/support/git/repository.rb', line 43 def merging_object return head unless merge_commit?(head) commit = head.parents.select do |parent| ![master.sha, origin_master.sha].include?(parent.sha) end return commit.last if commit.count == 1 head # fallback end |
#merging_sha ⇒ Object
35 36 37 |
# File 'lib/saddler/reporter/support/git/repository.rb', line 35 def merging_sha merging_object.sha end |
#origin_master ⇒ Object
56 57 58 |
# File 'lib/saddler/reporter/support/git/repository.rb', line 56 def origin_master @git.object('origin/master') end |
#push_endpoint ⇒ Object
64 65 66 |
# File 'lib/saddler/reporter/support/git/repository.rb', line 64 def push_endpoint (env_push_endpoint || 'github.com').chomp('/') end |
#remote_urls ⇒ Object
21 22 23 24 25 |
# File 'lib/saddler/reporter/support/git/repository.rb', line 21 def remote_urls @git .remotes .map(&:url) end |
#slug ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/saddler/reporter/support/git/repository.rb', line 12 def slug slug_regex = %r{\A/?(?<slug>.*?)(?:\.git)?\Z} remote_urls.map do |url| uri = Addressable::URI.parse(url) match = slug_regex.match(uri.path) match[:slug] if match end.compact.first end |