brew/Library/Homebrew/release_notes.rb

31 lines
949 B
Ruby
Raw Normal View History

2021-01-21 17:43:52 -05:00
# typed: true
# frozen_string_literal: true
# Helper functions for generating release notes.
#
# @api private
module ReleaseNotes
extend T::Sig
module_function
sig {
2021-01-23 02:06:12 -05:00
params(start_ref: T.any(String, Version), end_ref: T.any(String, Version), markdown: T.nilable(T::Boolean))
2021-01-21 17:43:52 -05:00
.returns(String)
}
def generate_release_notes(start_ref, end_ref, markdown: false)
Utils.popen_read(
2021-01-21 17:43:52 -05:00
"git", "-C", HOMEBREW_REPOSITORY, "log", "--pretty=format:'%s >> - %b%n'", "#{start_ref}..#{end_ref}"
).lines.map do |s|
matches = s.match(%r{.*Merge pull request #(?<pr>\d+) from (?<user>[^/]+)/[^>]*>> - (?<body>.*)})
next if matches.blank?
next if matches[:user] == "Homebrew"
2021-01-21 17:43:52 -05:00
body = matches[:body].presence
body ||= s.gsub(/.*(Merge pull request .*) >> - .*/, "\\1").chomp
2021-01-21 17:43:52 -05:00
"- [#{body}](https://github.com/Homebrew/brew/pull/#{matches[:pr]}) (@#{matches[:user]})\n"
end.compact.join
2021-01-21 17:43:52 -05:00
end
end