lib/helpers/git.rb in overview-0.0.4.17 vs lib/helpers/git.rb in overview-0.0.5.pre.22
- old
+ new
@@ -1,7 +1,7 @@
require_relative 'string.rb'
-
+module Helpers
class Git
def self.remote
begin
`git remote -v show`.lines.first.strip.match(/github\.com[\/|:](.+)\.git/)[1]
rescue
@@ -16,27 +16,46 @@
`git rev-parse --abbrev-ref HEAD`.strip
end
def self.tag
(`git describe --tags --match 'v*' --abbrev=0 2>/dev/null` || 'HEAD').strip
end
- def self.clean_tag(tag=self.tag)
- tag.strip.sub('v','').split(/[\.,-]/).select { |e| e.is_number?}.first(3).join('.')
+ def self.clean_tag(tag=self.tag, rubygem:false)
+ array = tag.strip.sub('v','').split(/[\.,-]/).select { |e| e.is_number? || (rubygem && e == 'pre') }
+ if rubygem then
+ array.join('.')
+ else
+ array.first(3).join('.')
+ end
end
def self.commit_count
`git rev-list --count HEAD`.to_i
end
def self.commit_count_since_tag(tag)
`git rev-list --count #{tag}.. 2>/dev/null`.to_i
end
+ def self.commit_author
+ `git --no-pager show -s --format='%an' -1`
+ end
+ def self.commit_email
+ `git --no-pager show -s --format='%ae' -1`
+ end
def self.installed?
system 'git --version >>/dev/null 2>&1'
end
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] || ''
+ deploy = {}
+ commands = %w(deploy DEPLOY force_deploy FORCE_DEPLOY).collect{ |command| "\\b#{command}\\b" }.join("|")
+ re_command_and_message = Regexp.new(/<(#{commands}):?\s*(.*?)(?:>)/)
+ result = commitMessage.scan(re_command_and_message).flatten.compact
+ deploy[:match] = !result[0].nil? && !result[0].empty?
+ re_channel = Regexp.new(/\s*([@#][A-z]+)\s*/)
+ deploy[:message] = result[1] ? result[1].gsub(re_channel, '') : ''
+ if result[1] && result[1].scan(re_channel) && result[1].scan(re_channel).first then
+ deploy[:channel] = result[1].scan(re_channel).first.first || ''
+ end
+ deploy[:author] = commit_author || ''
+ return deploy
end
def self.parse_crashlytics(commitMessage)
return commitMessage.scan(/(c|C):(?<crashlytics>\d+)/).flatten.collect { |x| x.to_i }.uniq
end
def self.parse_sprintly(commitMessage)
@@ -44,11 +63,11 @@
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
def self.parse_commit_message(commitMessage)
- h = Hash.new
+ h = {}
deploy, message = self.parse_deploy(commitMessage)
sprintly_tickets = self.parse_sprintly(commitMessage)
crashlytics_ids = self.parse_crashlytics(commitMessage)
h["deploy?"] = deploy
h["message"] = message
@@ -61,7 +80,7 @@
end
def self.commit_short_sha
`git rev-parse --short HEAD`.strip
end
end
-
+end