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

59 lines
1.7 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2019-04-17 18:25:08 +09:00
require "cli/parser"
module Homebrew
module_function
def release_notes_args
Homebrew::CLI::Parser.new do
2018-09-28 21:39:52 +05:30
usage_banner <<~EOS
`release-notes` [<options>] [<previous_tag>] [<end_ref>]
2018-09-28 21:39:52 +05:30
Print the merged pull requests on Homebrew/brew between two Git refs.
2018-09-28 21:39:52 +05:30
If no <previous_tag> is provided it defaults to the latest tag.
If no <end_ref> is provided it defaults to `origin/master`.
EOS
switch "--markdown",
2019-04-30 08:44:35 +01:00
description: "Print as a Markdown list."
max_named 2
end
end
2018-09-08 22:21:04 +05:30
def release_notes
release_notes_args.parse
previous_tag = args.named.first
previous_tag ||= Utils.popen_read(
"git", "-C", HOMEBREW_REPOSITORY, "tag", "--list", "--sort=-version:refname"
).lines.first.chomp
odie "Could not find any previous tags!" unless previous_tag
end_ref = args.named.second || "origin/master"
[previous_tag, end_ref].each do |ref|
next if quiet_system "git", "-C", HOMEBREW_REPOSITORY, "rev-parse", "--verify", "--quiet", ref
2018-09-17 02:45:00 +02:00
odie "Ref #{ref} does not exist!"
end
output = Utils.popen_read(
"git", "-C", HOMEBREW_REPOSITORY, "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
$stderr.puts "Release notes between #{previous_tag} and #{end_ref}:"
puts output
end
end