Skip to content
Snippets Groups Projects
Verified Commit 2fef540e authored by Rémy Coutable's avatar Rémy Coutable
Browse files

Fix edge cases with automated CHANGELOG


Handle the case when no blank line is present after an existing header: it
  will add one

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent a9fbbab9
No related branches found
No related tags found
1 merge request!48Fix edge cases with automated CHANGELOG
Pipeline #
Loading
Loading
@@ -45,12 +45,21 @@ module Changelog
header = Version.new($1)
 
if version.to_ce == header
no_blank_line_below_header = contents[index + 1].chomp != ''
entries = markdown.lines
entries.shift(2) # Remove the header and the blank line
entries.pop # Remove the trailing blank line
entries.shift # Remove the header
entries.shift unless no_blank_line_below_header # Remove the blank line if present
entries.pop # Remove the trailing blank line
 
# Insert the entries below the existing header and its blank line
contents.insert(index + 2, entries)
insert_at =
if no_blank_line_below_header
index + 1
else
index + 2
end
contents.insert(insert_at, entries)
break
elsif version.major >= header.major && version.minor >= header.minor
contents.insert(index, *markdown.lines)
Loading
Loading
Loading
Loading
@@ -53,7 +53,6 @@
- Change I
 
## 8.8.7 (2016-07-04)
- Change A
 
## 8.8.6 (2016-06-28)
Loading
Loading
Loading
Loading
@@ -64,6 +64,23 @@ describe Changelog::Updater do
- Change A
MD
end
it 'correctly inserts entries for a pre-existing version header without a blank line' do
version = Version.new('8.8.7-ee')
markdown = markdown(version)
writer = described_class.new(contents, version)
contents = writer.insert(markdown)
expect(contents).to include(<<-MD.strip_heredoc)
## 8.8.7 (2016-07-04)
- Change Z
- Change Y
- Change X
- Change A
MD
end
end
 
def markdown(version)
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment