release_notes: fix for missing body message

Some merge commits don't include the title of the pull request
on subsequent lines, leaving the markdown link text blank
in the release notes. This appends the subject line of the
commit message instead if the body is missing and adds a test
case.
This commit is contained in:
Steve Peters 2021-04-28 21:23:52 -07:00 committed by Mike McQuaid
parent c6ac648c08
commit f2c46d4608
No known key found for this signature in database
GPG Key ID: 48A898132FD8EE70
2 changed files with 11 additions and 2 deletions

View File

@ -19,8 +19,13 @@ module ReleaseNotes
).lines.grep(/Merge pull request/)
log_output.map! do |s|
s.gsub(%r{.*Merge pull request #(\d+) from ([^/]+)/[^>]*(>>)*},
"https://github.com/Homebrew/brew/pull/\\1 (@\\2)")
matches = s.match(%r{.*Merge pull request #(?<pr>\d+) from (?<user>[^/]+)/[^>]*>> - (?<body>.*)})
body = if matches[:body].empty?
s.gsub(/.*(Merge pull request .*) >> - .*/, "\\1").chomp
else
matches[:body]
end
"https://github.com/Homebrew/brew/pull/#{matches[:pr]} (@#{matches[:user]}) - #{body}\n"
end
if markdown

View File

@ -12,12 +12,15 @@ describe ReleaseNotes do
system "git", "commit", "--allow-empty", "-m", "Merge pull request #1 from Homebrew/fix", "-m", "Do something"
system "git", "commit", "--allow-empty", "-m", "make a change"
system "git", "commit", "--allow-empty", "-m", "Merge pull request #2 from User/fix", "-m", "Do something else"
system "git", "commit", "--allow-empty", "-m", "another change"
system "git", "commit", "--allow-empty", "-m", "Merge pull request #3 from User/another_change"
end
end
describe ".generate_release_notes" do
it "generates release notes" do
expect(described_class.generate_release_notes("release-notes-testing", "HEAD")).to eq <<~NOTES
https://github.com/Homebrew/brew/pull/3 (@User) - Merge pull request #3 from User/another_change
https://github.com/Homebrew/brew/pull/2 (@User) - Do something else
https://github.com/Homebrew/brew/pull/1 (@Homebrew) - Do something
NOTES
@ -25,6 +28,7 @@ describe ReleaseNotes do
it "generates markdown release notes" do
expect(described_class.generate_release_notes("release-notes-testing", "HEAD", markdown: true)).to eq <<~NOTES
- [Merge pull request #3 from User/another_change](https://github.com/Homebrew/brew/pull/3) (@User)
- [Do something else](https://github.com/Homebrew/brew/pull/2) (@User)
- [Do something](https://github.com/Homebrew/brew/pull/1) (@Homebrew)
NOTES