2022-12-07 06:31:00 +03:00
|
|
|
# Usage: ruby tool/update-NEWS-refs.rb
|
|
|
|
|
|
|
|
orig_src = File.read(File.join(__dir__, "../NEWS.md"))
|
|
|
|
lines = orig_src.lines(chomp: true)
|
|
|
|
|
|
|
|
links = {}
|
2022-12-21 06:52:44 +03:00
|
|
|
while lines.last =~ %r{\A\[(.*?)\]:\s+(.*)\z}
|
|
|
|
links[$1] = $2
|
|
|
|
lines.pop
|
2022-12-07 06:31:00 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
if links.empty? || lines.last != ""
|
2022-12-19 08:47:37 +03:00
|
|
|
raise "NEWS.md must end with a sequence of links"
|
2022-12-07 06:31:00 +03:00
|
|
|
end
|
|
|
|
|
2022-12-20 20:06:03 +03:00
|
|
|
labels = links.keys.select {|k| !(k.start_with?("Feature") || k.start_with?("Bug"))}
|
2022-12-19 08:47:37 +03:00
|
|
|
new_src = lines.join("\n").gsub(/\[?\[((?:Feature|Bug)\s+#(\d+))\]\]?/) do
|
2022-12-21 06:52:44 +03:00
|
|
|
links[$1] ||= "https://bugs.ruby-lang.org/issues/#$2"
|
2022-12-19 08:47:37 +03:00
|
|
|
"[[#$1]]"
|
2022-12-20 20:06:03 +03:00
|
|
|
end.gsub(/\[\[#{Regexp.union(labels)}\]\]?/) do
|
|
|
|
"[#$1]"
|
2022-12-19 08:47:37 +03:00
|
|
|
end.chomp + "\n\n"
|
|
|
|
|
2022-12-21 06:52:44 +03:00
|
|
|
label_width = links.max_by {|k, _| k.size}.first.size + 4
|
2022-12-19 08:47:37 +03:00
|
|
|
redmine_links, non_redmine_links = links.partition {|k,| k =~ /\A(Feature|Bug)\s+#\d+\z/ }
|
|
|
|
|
2022-12-21 06:52:44 +03:00
|
|
|
(redmine_links.sort_by {|k,| k[/\d+/].to_i } + non_redmine_links.reverse).each do |k, v|
|
|
|
|
new_src << "[#{k}]:".ljust(label_width) << v << "\n"
|
2022-12-19 08:47:37 +03:00
|
|
|
end
|
2022-12-07 06:31:00 +03:00
|
|
|
|
|
|
|
if orig_src != new_src
|
|
|
|
print "Update NEWS.md? [y/N]"
|
|
|
|
$stdout.flush
|
|
|
|
if gets.chomp == "y"
|
|
|
|
File.write(File.join(__dir__, "../NEWS.md"), new_src)
|
|
|
|
end
|
|
|
|
end
|