Module: Wheelbarrow::Utils
- Defined in:
- lib/wheelbarrow/utils.rb
Class Method Summary collapse
- .current_branch ⇒ Object
- .ensure_within_git! ⇒ Object
- .git_remotes ⇒ Object
- .git_repository? ⇒ Boolean
- .last_commit_message ⇒ Object
- .remote_url ⇒ Object
- .repo_name ⇒ Object
- .repo_regex ⇒ Object
Class Method Details
.current_branch ⇒ Object
5 6 7 |
# File 'lib/wheelbarrow/utils.rb', line 5 def current_branch `git symbolic-ref HEAD`[%r{refs/heads/(.*)}, 1] end |
.ensure_within_git! ⇒ Object
13 14 15 |
# File 'lib/wheelbarrow/utils.rb', line 13 def ensure_within_git! git_repository? ? yield : fail('fatal: Not a git repository!') end |
.git_remotes ⇒ Object
17 18 19 |
# File 'lib/wheelbarrow/utils.rb', line 17 def git_remotes `git remote -v` end |
.git_repository? ⇒ Boolean
9 10 11 |
# File 'lib/wheelbarrow/utils.rb', line 9 def git_repository? system('git rev-parse') end |
.last_commit_message ⇒ Object
40 41 42 |
# File 'lib/wheelbarrow/utils.rb', line 40 def `git log -1 --pretty=%B`.strip end |
.remote_url ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/wheelbarrow/utils.rb', line 21 def remote_url origin = git_remotes.split("\n") .map(&:strip) .grep(/^origin.*\(push\)$/) .first.to_s URI.extract(origin).first.to_s end |
.repo_name ⇒ Object
30 31 32 33 34 |
# File 'lib/wheelbarrow/utils.rb', line 30 def repo_name repo_name = remote_url.match repo_regex fail 'Repository does not seem to be hosted in BitBucket!' if repo_name.nil? repo_name[1] end |
.repo_regex ⇒ Object
36 37 38 |
# File 'lib/wheelbarrow/utils.rb', line 36 def repo_regex /bitbucket\.org:(.*)\.git/ end |