brew/Library/Homebrew/dev-cmd/release-notes.rb

48 lines
1.5 KiB
Ruby
Raw Normal View History

#: * `release-notes` [`--markdown`] [<previous_tag>] [<end_ref>]:
#: Output the merged pull requests on Homebrew/brew between two Git refs.
#: If no <previous_tag> is provided it defaults to the newest tag.
#: If no <end_ref> is provided it defaults to `origin/master`.
#:
#: If `--markdown` is passed, output as a Markdown list.
require "cli_parser"
module Homebrew
module_function
def release_notes
args = Homebrew::CLI::Parser.new do
switch "--markdown"
end.parse
previous_tag = ARGV.named.first
2017-09-24 19:24:46 +01:00
previous_tag ||= Utils.popen_read("git tag --list --sort=-version:refname")
.lines.first.chomp
odie "Could not find any previous tags!" unless previous_tag
end_ref = ARGV.named[1] || "origin/master"
[previous_tag, end_ref].each do |ref|
next if quiet_system "git", "rev-parse", "--verify", "--quiet", ref
odie "Ref #{ref} does not exist!"
end
output = Utils.popen_read("git log --pretty=format:'%s >> - %b%n' '#{previous_tag}'..'#{end_ref}'")
.lines.grep(/Merge pull request/)
output.map! do |s|
2017-06-03 20:52:36 +01:00
s.gsub(%r{.*Merge pull request #(\d+) from ([^/]+)/[^>]*(>>)*},
"https://github.com/Homebrew/brew/pull/\\1 (@\\2)")
end
if args.markdown?
output.map! do |s|
/(.*\d)+ \(@(.+)\) - (.*)/ =~ s
"- [#{Regexp.last_match(3)}](#{Regexp.last_match(1)}) (@#{Regexp.last_match(2)})"
end
end
puts "Release notes between #{previous_tag} and #{end_ref}:"
puts output
end
end