Module: Wheelbarrow::Utils

Defined in:
lib/wheelbarrow/utils.rb

Class Method Summary collapse

Class Method Details

.current_branchObject



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_remotesObject



17
18
19
# File 'lib/wheelbarrow/utils.rb', line 17

def git_remotes
  `git remote -v`
end

.git_repository?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/wheelbarrow/utils.rb', line 9

def git_repository?
  system('git rev-parse')
end

.last_commit_messageObject



40
41
42
# File 'lib/wheelbarrow/utils.rb', line 40

def last_commit_message
  `git log -1 --pretty=%B`.strip
end

.remote_urlObject



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_nameObject



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_regexObject



36
37
38
# File 'lib/wheelbarrow/utils.rb', line 36

def repo_regex
  /bitbucket\.org:(.*)\.git/
end