2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-07-21 02:25:48 +08:00
|
|
|
DATE_REGEX ||= /\A\d{4}-\d{2}-\d{2}/
|
2021-07-15 14:15:57 +08:00
|
|
|
|
2021-07-21 02:25:48 +08:00
|
|
|
CHANGE_TYPES ||= [
|
2021-07-15 14:15:57 +08:00
|
|
|
{ pattern: /^FEATURE:/, heading: "New Features" },
|
|
|
|
{ pattern: /^FIX:/, heading: "Bug Fixes" },
|
|
|
|
{ pattern: /^UX:/, heading: "UX Changes" },
|
|
|
|
{ pattern: /^SECURITY:/, heading: "Security Changes" },
|
|
|
|
{ pattern: /^PERF:/, heading: "Performance" },
|
|
|
|
{ pattern: /^A11Y:/, heading: "Accessibility" },
|
|
|
|
]
|
|
|
|
|
2014-10-03 01:01:10 +08:00
|
|
|
desc "generate a release note from the important commits"
|
2021-07-13 04:23:50 +08:00
|
|
|
task "release_note:generate", :from, :to, :repo do |t, args|
|
|
|
|
repo = args[:repo] || "."
|
2021-07-15 14:15:57 +08:00
|
|
|
changes = find_changes(repo, args[:from], args[:to])
|
2021-07-13 04:23:50 +08:00
|
|
|
|
2021-09-02 11:08:31 +08:00
|
|
|
CHANGE_TYPES.each { |ct| print_changes(ct[:heading], changes[ct], "###") }
|
2014-10-03 01:01:10 +08:00
|
|
|
|
2021-07-15 14:15:57 +08:00
|
|
|
puts "(no changes)", "" if changes.values.all?(&:empty?)
|
2021-07-13 04:23:50 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# To use with all-the-plugins:
|
|
|
|
# 1. Make sure you have a local, up-to-date clone of https://github.com/discourse/all-the-plugins
|
|
|
|
# 2. In all-the-plugins, `git submodule update --init --recursive --remote`
|
|
|
|
# 3. Change back to your discourse directory
|
2021-07-15 14:15:57 +08:00
|
|
|
# 4. rake "release_note:plugins:generate[ 2021-06-01 , 2021-07-01 , /path/to/all-the-plugins/plugins/* , discourse ]"
|
2021-07-13 04:23:50 +08:00
|
|
|
desc "generate release notes for all official plugins in a directory"
|
|
|
|
task "release_note:plugins:generate", :from, :to, :plugin_glob, :org do |t, args|
|
|
|
|
from = args[:from]
|
|
|
|
to = args[:to]
|
|
|
|
plugin_glob = args[:plugin_glob] || "./plugins/*"
|
|
|
|
git_org = args[:org]
|
|
|
|
|
2022-01-06 01:45:08 +08:00
|
|
|
all_repos = Dir.glob(plugin_glob).filter { |f| File.directory?(f) && File.exist?("#{f}/.git") }
|
2021-07-13 04:23:50 +08:00
|
|
|
|
|
|
|
if git_org
|
|
|
|
all_repos =
|
|
|
|
all_repos.filter do |dir|
|
|
|
|
`git -C #{dir} remote get-url origin`.match?(%r{github.com[/:]#{git_org}/})
|
2023-01-09 20:10:19 +08:00
|
|
|
end
|
2021-07-13 04:23:50 +08:00
|
|
|
end
|
|
|
|
|
2021-07-15 14:15:57 +08:00
|
|
|
no_changes_repos = []
|
|
|
|
|
2021-07-13 04:23:50 +08:00
|
|
|
all_repos.each do |dir|
|
2021-07-15 14:15:57 +08:00
|
|
|
name = File.basename(dir)
|
|
|
|
changes = find_changes(dir, from, to)
|
|
|
|
|
|
|
|
if changes.values.all?(&:empty?)
|
|
|
|
no_changes_repos << name
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
2021-09-02 11:08:31 +08:00
|
|
|
puts "### #{name}\n\n"
|
2022-09-23 22:29:00 +08:00
|
|
|
CHANGE_TYPES.each { |ct| print_changes_plugin(ct[:heading], changes[ct]) }
|
2021-07-13 04:23:50 +08:00
|
|
|
end
|
2021-07-15 14:15:57 +08:00
|
|
|
|
|
|
|
puts "(No changes found in #{no_changes_repos.join(", ")})"
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_changes(repo, from, to)
|
|
|
|
dates = from&.match?(DATE_REGEX) || to&.match?(DATE_REGEX)
|
|
|
|
|
|
|
|
if !dates
|
|
|
|
from ||= `git -C #{repo} describe --tags --abbrev=0`.strip
|
|
|
|
to ||= "HEAD"
|
|
|
|
end
|
|
|
|
|
|
|
|
cmd = "git -C #{repo} log --pretty='tformat:%s' "
|
|
|
|
if dates
|
|
|
|
cmd += "--after '#{from}' " if from
|
|
|
|
cmd += "--before '#{to}' " if to
|
|
|
|
else
|
|
|
|
cmd += "#{from}..#{to}"
|
|
|
|
end
|
|
|
|
|
|
|
|
out = `#{cmd}`
|
|
|
|
raise "Status #{$?.exitstatus} running git log\n#{out}" if !$?.success?
|
|
|
|
|
|
|
|
changes = {}
|
|
|
|
CHANGE_TYPES.each { |ct| changes[ct] = Set.new }
|
|
|
|
|
|
|
|
out.each_line do |comment|
|
|
|
|
next if comment =~ /^\s*Revert/
|
|
|
|
split_comments(comment).each do |line|
|
|
|
|
ct = CHANGE_TYPES.find { |t| line =~ t[:pattern] }
|
|
|
|
changes[ct] << better(line) if ct
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
changes
|
2014-11-07 20:01:44 +08:00
|
|
|
end
|
|
|
|
|
2021-09-02 11:08:31 +08:00
|
|
|
def print_changes(heading, changes, importance)
|
2014-11-07 20:01:44 +08:00
|
|
|
return if changes.length == 0
|
|
|
|
|
2021-09-02 11:08:31 +08:00
|
|
|
puts "#{importance} #{heading}", ""
|
2014-11-07 20:01:44 +08:00
|
|
|
puts changes.to_a, ""
|
2014-10-03 01:01:10 +08:00
|
|
|
end
|
2014-10-03 01:18:07 +08:00
|
|
|
|
2022-09-23 22:29:00 +08:00
|
|
|
def print_changes_plugin(heading, changes)
|
|
|
|
return if changes.length == 0
|
|
|
|
|
|
|
|
puts "[details=\"#{heading}\"]\n", ""
|
|
|
|
puts changes.to_a, ""
|
|
|
|
puts "[/details]\n", ""
|
|
|
|
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)
|
2020-12-01 06:11:02 +08:00
|
|
|
line = remove_pull_request(line)
|
2014-10-24 06:51:00 +08:00
|
|
|
line[0] = '\#' if line[0] == "#"
|
2019-12-06 00:53:10 +08:00
|
|
|
if line[0]
|
|
|
|
line[0] = line[0].capitalize
|
|
|
|
"- " + line
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
2014-10-24 06:51:00 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def remove_prefix(line)
|
2021-01-29 01:58:04 +08:00
|
|
|
line.gsub(/^(FIX|FEATURE|UX|SECURITY|PERF|A11Y):/, "").strip
|
2014-10-24 06:51:00 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def escape_brackets(line)
|
|
|
|
line.gsub("<", "`<").gsub(">", ">`").gsub("[", "`[").gsub("]", "]`")
|
|
|
|
end
|
|
|
|
|
2020-12-01 06:11:02 +08:00
|
|
|
def remove_pull_request(line)
|
|
|
|
line.gsub(/ \(\#\d+\)$/, "")
|
|
|
|
end
|
|
|
|
|
2014-10-24 06:51:00 +08:00
|
|
|
def split_comments(text)
|
|
|
|
text = normalize_terms(text)
|
2021-01-29 01:58:04 +08:00
|
|
|
terms = %w[FIX: FEATURE: UX: SECURITY: PERF: A11Y:]
|
2014-10-24 06:51:00 +08:00
|
|
|
terms.each do |term|
|
2019-09-04 21:45:48 +08:00
|
|
|
text = text.gsub(/(#{term})+/i, term)
|
2014-10-24 06:51:00 +08: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:")
|
2021-02-18 23:53:23 +08:00
|
|
|
text = text.gsub(/(UX|UI):/i, "UX:")
|
2014-11-07 20:01:44 +08:00
|
|
|
text = text.gsub(/(SECURITY):/i, "SECURITY:")
|
|
|
|
text = text.gsub(/(PERF):/i, "PERF:")
|
2021-01-29 01:58:04 +08:00
|
|
|
text = text.gsub(/(A11Y):/i, "A11Y:")
|
2014-10-24 06:51:00 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def newlines_at_term(text, term)
|
|
|
|
text = text.split(term).map { |l| l.strip }.join("\n#{term} ") if text.include?(term)
|
|
|
|
text
|
2014-10-03 01:18:07 +08:00
|
|
|
end
|