lib/socialcast-git-extensions/git.rb in socialcast-git-extensions-3.0.0.pre4 vs lib/socialcast-git-extensions/git.rb in socialcast-git-extensions-3.0.0
- old
+ new
@@ -1,11 +1,12 @@
require 'grit'
module Socialcast
module Gitx
module Git
- RESERVED_BRANCHES = %w{ HEAD master staging prototype next_release }
+ AGGREGATE_BRANCHES = %w{ staging prototype }
+ RESERVED_BRANCHES = %w{ HEAD master next_release } + AGGREGATE_BRANCHES
private
def assert_not_protected_branch!(branch, action)
raise "Cannot #{action} reserved branch" if RESERVED_BRANCHES.include?(branch) || aggregate_branch?(branch)
end
@@ -36,11 +37,10 @@
branches << branch unless RESERVED_BRANCHES.include?(branch)
end
branches.uniq
end
- AGGREGATE_BRANCHES = %w{ staging prototype }
# reset the specified branch to the same set of commits as the destination branch
# used to revert commits on aggregate branches back to a known good state
def reset_branch(branch, head_branch)
raise "Can not reset #{branch} to #{head_branch}" if branch == head_branch
raise "Only aggregate branches are allowed to be reset: #{AGGREGATE_BRANCHES}" unless aggregate_branch?(branch)
@@ -75,12 +75,51 @@
run_cmd "git pull . #{branch}"
run_cmd "git push origin HEAD"
run_cmd "git checkout #{branch}"
end
- private
def aggregate_branch?(branch)
AGGREGATE_BRANCHES.include?(branch) || branch.starts_with?('last_known_good')
+ end
+
+ # build a summary of changes
+ def changelog_summary(branch)
+ changes = `git diff --stat origin/#{Socialcast::Gitx::BASE_BRANCH}...#{branch}`.split("\n")
+ stats = changes.pop
+ if changes.length > 5
+ dirs = changes.map do |file_change|
+ filename = "#{file_change.split.first}"
+ dir = filename.gsub(/\/[^\/]+$/, '')
+ dir
+ end
+ dir_counts = Hash.new(0)
+ dirs.each {|dir| dir_counts[dir] += 1 }
+ changes = dir_counts.to_a.sort_by {|k,v| v}.reverse.first(5).map {|k,v| "#{k} (#{v} file#{'s' if v > 1})"}
+ end
+ (changes + [stats]).join("\n")
+ end
+
+ # launch configured editor to retreive message/string
+ def editor_input(initial_text = '')
+ require 'tempfile'
+ Tempfile.open('reviewrequest.md') do |f|
+ f << initial_text
+ f.flush
+
+ editor = ENV['EDITOR'] || 'vi'
+ flags = case editor
+ when 'mate', 'emacs'
+ '-w'
+ when 'mvim'
+ '-f'
+ else
+ ''
+ end
+ pid = fork { exec "#{editor} #{flags} #{f.path}" }
+ Process.waitpid(pid)
+ description = File.read(f.path)
+ description.gsub(/^\#.*/, '').chomp.strip
+ end
end
end
end
end