2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-10-02 12:01:10 -05:00
|
|
|
desc "generate a release note from the important commits"
|
2014-11-07 06:01:44 -06:00
|
|
|
task "release_note:generate", :from, :to do |t, args|
|
|
|
|
from = args[:from] || `git describe --tags --abbrev=0`.strip
|
|
|
|
to = args[:to] || "HEAD"
|
2014-10-02 12:01:10 -05:00
|
|
|
|
2014-10-02 12:18:07 -05:00
|
|
|
bug_fixes = Set.new
|
|
|
|
new_features = Set.new
|
|
|
|
ux_changes = Set.new
|
2014-11-06 15:02:11 -06:00
|
|
|
sec_changes = Set.new
|
2014-11-07 06:01:44 -06:00
|
|
|
perf_changes = Set.new
|
2021-01-28 11:58:04 -06:00
|
|
|
a11y_changes = Set.new
|
2014-10-02 12:01:10 -05:00
|
|
|
|
2020-10-15 15:20:32 -05:00
|
|
|
`git log --pretty="tformat:%s" #{from}..#{to}`.each_line do |comment|
|
2014-11-06 14:58:03 -06:00
|
|
|
next if comment =~ /^\s*Revert/
|
2014-10-23 17:51:00 -05: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)
|
2014-11-06 15:02:11 -06:00
|
|
|
elsif line =~ /^SECURITY:/
|
|
|
|
sec_changes << better(line)
|
2014-11-07 06:01:44 -06:00
|
|
|
elsif line =~ /^PERF:/
|
|
|
|
perf_changes << better(line)
|
2021-01-28 11:58:04 -06:00
|
|
|
elsif line =~ /^A11Y:/
|
|
|
|
a11y_changes << better(line)
|
2014-10-23 17:51:00 -05:00
|
|
|
end
|
2014-10-02 12:01:10 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-11-07 06:01:44 -06:00
|
|
|
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)
|
2021-01-28 11:58:04 -06:00
|
|
|
print_changes("ACCESSIBILITY", a11y_changes)
|
2014-11-07 06:01:44 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
def print_changes(heading, changes)
|
|
|
|
return if changes.length == 0
|
|
|
|
|
|
|
|
puts heading
|
|
|
|
puts "-" * heading.length, ""
|
|
|
|
puts changes.to_a, ""
|
2014-10-02 12:01:10 -05:00
|
|
|
end
|
2014-10-02 12:18:07 -05:00
|
|
|
|
|
|
|
def better(line)
|
2014-10-23 17:51:00 -05:00
|
|
|
line = remove_prefix(line)
|
|
|
|
line = escape_brackets(line)
|
2020-11-30 16:11:02 -06:00
|
|
|
line = remove_pull_request(line)
|
2014-10-23 17:51:00 -05:00
|
|
|
line[0] = '\#' if line[0] == '#'
|
2019-12-05 10:53:10 -06:00
|
|
|
if line[0]
|
|
|
|
line[0] = line[0].capitalize
|
|
|
|
"- " + line
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
2014-10-23 17:51:00 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def remove_prefix(line)
|
2021-01-28 11:58:04 -06:00
|
|
|
line.gsub(/^(FIX|FEATURE|UX|SECURITY|PERF|A11Y):/, "").strip
|
2014-10-23 17:51:00 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def escape_brackets(line)
|
|
|
|
line.gsub("<", "`<")
|
2017-07-27 20:20:09 -05:00
|
|
|
.gsub(">", ">`")
|
|
|
|
.gsub("[", "`[")
|
|
|
|
.gsub("]", "]`")
|
2014-10-23 17:51:00 -05:00
|
|
|
end
|
|
|
|
|
2020-11-30 16:11:02 -06:00
|
|
|
def remove_pull_request(line)
|
|
|
|
line.gsub(/ \(\#\d+\)$/, "")
|
|
|
|
end
|
|
|
|
|
2014-10-23 17:51:00 -05:00
|
|
|
def split_comments(text)
|
|
|
|
text = normalize_terms(text)
|
2021-01-28 11:58:04 -06:00
|
|
|
terms = ["FIX:", "FEATURE:", "UX:", "SECURITY:" , "PERF:" , "A11Y:"]
|
2014-10-23 17:51:00 -05:00
|
|
|
terms.each do |term|
|
2019-09-04 08:45:48 -05:00
|
|
|
text = text.gsub(/(#{term})+/i, term)
|
2014-10-23 17:51:00 -05:00
|
|
|
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:")
|
2014-11-07 06:01:44 -06:00
|
|
|
text = text.gsub(/(SECURITY):/i, "SECURITY:")
|
|
|
|
text = text.gsub(/(PERF):/i, "PERF:")
|
2021-01-28 11:58:04 -06:00
|
|
|
text = text.gsub(/(A11Y):/i, "A11Y:")
|
2014-10-23 17:51:00 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def newlines_at_term(text, term)
|
|
|
|
if text.include?(term)
|
2017-07-27 20:20:09 -05:00
|
|
|
text = text.split(term).map { |l| l.strip }.join("\n#{term} ")
|
2014-10-23 17:51:00 -05:00
|
|
|
end
|
|
|
|
text
|
2014-10-02 12:18:07 -05:00
|
|
|
end
|