Class: Git

Inherits:
Object
  • Object
show all
Defined in:
lib/helpers/git.rb

Class Method Summary collapse

Class Method Details

.branchObject



15
16
17
# File 'lib/helpers/git.rb', line 15

def self.branch
  `git rev-parse --abbrev-ref HEAD`.strip
end

.clean_tag(tag = self.tag) ⇒ Object



21
22
23
# File 'lib/helpers/git.rb', line 21

def self.clean_tag(tag=self.tag)
  tag.strip.sub('v','').split(/[\.,-]/).select { |e| e.is_number?}.first(3).join('.')
end

.commit_countObject



24
25
26
# File 'lib/helpers/git.rb', line 24

def self.commit_count
  `git rev-list --count HEAD`.to_i
end

.commit_count_since_tag(tag) ⇒ Object



27
28
29
# File 'lib/helpers/git.rb', line 27

def self.commit_count_since_tag(tag)
  `git rev-list --count #{tag}.. 2>/dev/null`.to_i
end

.commit_shaObject



59
60
61
# File 'lib/helpers/git.rb', line 59

def self.commit_sha
  `git rev-parse HEAD`.strip
end

.commit_short_shaObject



62
63
64
# File 'lib/helpers/git.rb', line 62

def self.commit_short_sha
  `git rev-parse --short HEAD`.strip
end

.installed?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/helpers/git.rb', line 30

def self.installed?
  system 'git --version >>/dev/null 2>&1'
end

.parse_commit_message(commitMessage) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/helpers/git.rb', line 48

def self.parse_commit_message(commitMessage)
  h = Hash.new
  deploy, message = self.parse_deploy(commitMessage)
  sprintly_tickets = self.parse_sprintly(commitMessage)
  crashlytics_ids = self.parse_crashlytics(commitMessage)
  h["deploy?"] = deploy
  h["message"] = message
  h["sprintly"] = sprintly_tickets
  h["crashlytics"] = crashlytics_ids
  return h
end

.parse_crashlytics(commitMessage) ⇒ Object



39
40
41
# File 'lib/helpers/git.rb', line 39

def self.parse_crashlytics(commitMessage)
  return commitMessage.scan(/(c|C):(?<crashlytics>\d+)/).flatten.collect { |x| x.to_i }.uniq
end

.parse_deploy(commitMessage) ⇒ Object



33
34
35
36
37
38
# File 'lib/helpers/git.rb', line 33

def self.parse_deploy(commitMessage)
  commands = %w(deploy DEPLOY force_deploy FORCE_DEPLOY).collect{ |x| "\\b#{x}\\b" }.join("|")
  re = Regexp.new(/<(#{commands}):?\s*(.*?)(?:>)/)
  deploy = commitMessage.scan(re).flatten.compact
  return !deploy[0].nil? && !deploy[0].empty?, deploy[1] || ''
end

.parse_sprintly(commitMessage) ⇒ Object



42
43
44
45
46
47
# File 'lib/helpers/git.rb', line 42

def self.parse_sprintly(commitMessage)
  commands = %w(close closed closes finish finished finishes fix fixed fixes breaks unfixes reopen reopens re-open re-opens addresses re ref references refs start starts see).collect{ |x| "\\b#{x}\\b" }.join("|")
  prefixes = %w(task issue defect bug item ticket).collect{ |x| "\\b#{x}:\\b" }.join("|") + "|#"
  re = Regexp.new(/(?:#{commands})\s(?:#{prefixes})(\d+)/)
  return commitMessage.downcase.scan(re).flatten.collect{ |x| x.to_i }.uniq
end

.remoteObject



4
5
6
7
8
9
10
11
# File 'lib/helpers/git.rb', line 4

def self.remote
  begin
    `git remote -v show`.lines.first.strip.match(/github\.com[\/|:](.+)\.git/)[1]
  rescue
    $stderr.puts 'Unable to retrieve slug from >> git remote -v show'
    exit 1
  end
end

.repoObject



12
13
14
# File 'lib/helpers/git.rb', line 12

def self.repo
  remote
end

.tagObject



18
19
20
# File 'lib/helpers/git.rb', line 18

def self.tag
  (`git describe --tags --match 'v*' --abbrev=0 2>/dev/null` || 'HEAD').strip
end