Created
April 13, 2012 18:17
-
-
Save paladiy/2378905 to your computer and use it in GitHub Desktop.
Grep git log for delivery title and description
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'optparse' | |
require 'ostruct' | |
def parse_logs(logs) | |
logs.map do |record| | |
array = record.scan(/(.+) \[#(\d+)\] (.+)/).first | |
next unless array | |
OpenStruct.new :revision => array[0], :id => array[1], :comment => array[2] | |
end.compact | |
end | |
def title(commits) | |
puts "Title" | |
puts " Ticket ids: #{commits.map(&:id).uniq.join(", ")}" | |
end | |
def description(commits) | |
return if commits.size < 1 | |
puts "Description" | |
commits.group_by(&:id).each do |ticket_id, records| | |
puts " Ticket #{ticket_id}:" | |
records.each{|r| puts " * #{r.comment}"} | |
end | |
end | |
options = { :branch1 => "master", :branch2 => "origin/master" } | |
OptionParser.new do |opts| | |
opts.on("--full", "Create title and description") do |v| | |
options[:full] = true | |
end | |
opts.on("-f BRANCH", String, "Branch/Tag/Revision") do |b| | |
options[:branch1] = b | |
end | |
opts.on("-s BRANCH", String, "Branch/Tag/Revision N2") do |b| | |
options[:branch2] = b | |
end | |
end.parse! | |
commits = parse_logs(`git log --oneline #{options[:branch1]}...#{options[:branch2]}`.split("\n")) | |
title(commits) | |
description(commits) if options[:full] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment