2014-10-03 01:01:10 +08:00
|
|
|
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
|
|
|
|
|
2014-10-03 01:18:07 +08:00
|
|
|
bug_fixes = Set.new
|
|
|
|
new_features = Set.new
|
|
|
|
ux_changes = Set.new
|
2014-10-03 01:01:10 +08:00
|
|
|
|
2014-11-07 04:58:03 +08:00
|
|
|
|
2014-10-28 21:31:30 +08:00
|
|
|
`git log #{tag}..HEAD`.each_line do |comment|
|
2014-11-07 04:58:03 +08:00
|
|
|
next if comment =~ /^\s*Revert/
|
2014-10-24 06:51:00 +08:00
|
|
|
split_comments(comment).each do |line|
|
|
|
|
if line =~ /^FIX:/
|
|
|
|
bug_fixes << better(line)
|
|
|
|
elsif line =~ /^FEATURE:/
|
|
|
|
new_features << better(line)
|
|
|
|
elsif line =~ /^UX:/
|
|
|
|
ux_changes << better(line)
|
|
|
|
end
|
2014-10-03 01:01:10 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-10-24 06:51:00 +08:00
|
|
|
puts "NEW FEATURES:", "-------------", "", new_features.to_a, ""
|
|
|
|
puts "BUG FIXES:", "----------", "", bug_fixes.to_a, ""
|
|
|
|
puts "UX CHANGES:", "-----------", "", ux_changes.to_a, ""
|
2014-10-03 01:01:10 +08:00
|
|
|
end
|
2014-10-03 01:18:07 +08:00
|
|
|
|
|
|
|
def better(line)
|
2014-10-24 06:51:00 +08:00
|
|
|
line = remove_prefix(line)
|
|
|
|
line = escape_brackets(line)
|
|
|
|
line[0] = '\#' if line[0] == '#'
|
2014-10-03 01:18:07 +08:00
|
|
|
line[0] = line[0].capitalize
|
2014-10-24 06:51:00 +08:00
|
|
|
"- " + line
|
|
|
|
end
|
|
|
|
|
|
|
|
def remove_prefix(line)
|
|
|
|
line.gsub(/^(FIX|FEATURE|UX):/, "").strip
|
|
|
|
end
|
|
|
|
|
|
|
|
def escape_brackets(line)
|
|
|
|
line.gsub("<", "`<")
|
|
|
|
.gsub(">", ">`")
|
|
|
|
.gsub("[", "`[")
|
|
|
|
.gsub("]", "]`")
|
|
|
|
end
|
|
|
|
|
|
|
|
def split_comments(text)
|
|
|
|
text = normalize_terms(text)
|
|
|
|
terms = ["FIX:", "FEATURE:", "UX:"]
|
|
|
|
terms.each do |term|
|
|
|
|
text = newlines_at_term(text, term)
|
|
|
|
end
|
|
|
|
text.split("\n")
|
|
|
|
end
|
|
|
|
|
|
|
|
def normalize_terms(text)
|
|
|
|
text = text.gsub(/(BUGFIX|FIX|BUG):/i, "FIX:")
|
|
|
|
text = text.gsub(/FEATURE:/i, "FEATURE:")
|
|
|
|
text = text.gsub(/UX:/i, "UX:")
|
|
|
|
end
|
|
|
|
|
|
|
|
def newlines_at_term(text, term)
|
|
|
|
if text.include?(term)
|
|
|
|
text = text.split(term).map{ |l| l.strip }.join("\n#{term} ")
|
|
|
|
end
|
|
|
|
text
|
2014-10-03 01:18:07 +08:00
|
|
|
end
|