From 844b92bf120d75c0c942cb9ed28a419c80a2c18b Mon Sep 17 00:00:00 2001
From: David McClure <dave@xerotrope.org>
Date: Fri, 7 Nov 2014 04:01:44 -0800
Subject: [PATCH] Include perf improvements in release notes Add ability to
 specify 'from' and 'to' tags in rake task

---
 lib/tasks/release_note.rake | 34 ++++++++++++++++++++++++----------
 1 file changed, 24 insertions(+), 10 deletions(-)

diff --git a/lib/tasks/release_note.rake b/lib/tasks/release_note.rake
index f7957533a73..54c40e267b1 100644
--- a/lib/tasks/release_note.rake
+++ b/lib/tasks/release_note.rake
@@ -1,14 +1,15 @@
 desc "generate a release note from the important commits"
-task "release_note:generate", :tag do |t, args|
-  tag = args[:tag] || `git describe --tags --abbrev=0`.strip
+task "release_note:generate", :from, :to do |t, args|
+  from = args[:from] || `git describe --tags --abbrev=0`.strip
+  to = args[:to] || "HEAD"
 
   bug_fixes = Set.new
   new_features = Set.new
   ux_changes = Set.new
   sec_changes = Set.new
+  perf_changes = Set.new
 
-
-  `git log #{tag}..HEAD`.each_line do |comment|
+  `git log #{from}..#{to}`.each_line do |comment|
     next if comment =~ /^\s*Revert/
     split_comments(comment).each do |line|
       if line =~ /^FIX:/
@@ -19,14 +20,25 @@ task "release_note:generate", :tag do |t, args|
         ux_changes << better(line)
       elsif line =~ /^SECURITY:/
         sec_changes << better(line)
+      elsif line =~ /^PERF:/
+        perf_changes << better(line)
       end
     end
   end
 
-  puts "NEW FEATURES:", "-------------", "", new_features.to_a, ""
-  puts "BUG FIXES:", "----------", "", bug_fixes.to_a, ""
-  puts "UX CHANGES:", "-----------", "", ux_changes.to_a, ""
-  puts "SECURITY CHANGES:", "-----------------", "", sec_changes.to_a, ""
+  print_changes("NEW FEATURES", new_features)
+  print_changes("BUG FIXES", bug_fixes)
+  print_changes("UX CHANGES", ux_changes)
+  print_changes("SECURITY CHANGES", sec_changes)
+  print_changes("PERFORMANCE", perf_changes)
+end
+
+def print_changes(heading, changes)
+  return if changes.length == 0
+
+  puts heading
+  puts "-" * heading.length, ""
+  puts changes.to_a, ""
 end
 
 def better(line)
@@ -38,7 +50,7 @@ def better(line)
 end
 
 def remove_prefix(line)
-  line.gsub(/^(FIX|FEATURE|UX|SECURITY):/, "").strip
+  line.gsub(/^(FIX|FEATURE|UX|SECURITY|PERF):/, "").strip
 end
 
 def escape_brackets(line)
@@ -50,7 +62,7 @@ end
 
 def split_comments(text)
   text = normalize_terms(text)
-  terms = ["FIX:", "FEATURE:", "UX:", "SECURITY:"]
+  terms = ["FIX:", "FEATURE:", "UX:", "SECURITY:" ,"PERF:"]
   terms.each do |term|
     text = newlines_at_term(text, term)
   end
@@ -61,6 +73,8 @@ def normalize_terms(text)
   text = text.gsub(/(BUGFIX|FIX|BUG):/i, "FIX:")
   text = text.gsub(/FEATURE:/i, "FEATURE:")
   text = text.gsub(/UX:/i, "UX:")
+  text = text.gsub(/(SECURITY):/i, "SECURITY:")
+  text = text.gsub(/(PERF):/i, "PERF:")
 end
 
 def newlines_at_term(text, term)