Sha256: 94d84cc7fe02f9877270703b8ab10da285a18415df6cfea7468dae85961d1e1f
Contents?: true
Size: 1.45 KB
Versions: 56
Compression:
Stored size: 1.45 KB
Contents
#!/usr/bin/env ruby # Installed by the git-story gem require 'tempfile' class CommitMesssageParser def initialize @line_index = 0 @story_number_found = false @message_data = [] end attr_reader :line_index def story_number_found? @story_number_found end def parse(template) @message_data = template.readlines @message_data.each do |line| line =~ /\[.*#\d+.*\]/ and @story_number_found = true if line =~ /^\s*#/ break else @line_index += 1 end end ensure @line_index = [ @line_index - 1, 0 ].max return self end def data @message_data[0..@line_index] end def footer @message_data[(@line_index + 1)..-1] end def total data + footer end end story_numbers = `git branch --no-color`.sub!(/^\* .*?(?:_(\d+(?:_\d+)*))$/) { break $1.split(/_/) } || [] story_numbers.map!(&:chomp) unless story_numbers.empty? Tempfile.open('commit') do |output| File.open(ARGV.first) do |template| message_parsed = CommitMesssageParser.new.parse(template) if message_parsed.story_number_found? output.puts message_parsed.total else output.puts message_parsed.data, "", "[#{story_numbers.map { |story_number| "##{story_number}" } * ' '}]", "", message_parsed.footer end output.rewind File.open(ARGV.first, 'w') do |message| message.write output.read end end end end
Version data entries
56 entries across 56 versions & 1 rubygems