Skip to content
This repository has been archived by the owner on May 16, 2021. It is now read-only.

Commit

Permalink
Improve strip behavior of release notes to fix bug
Browse files Browse the repository at this point in the history
Fix a bug where the formatting of certain Markdown release notes were
inadvertently altered due to stripping indentation off the first line of the
text.
  • Loading branch information
mattbrictson committed Apr 22, 2016
1 parent 472387e commit 6b82a16
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ chandler is in a pre-1.0 state. This means that its APIs and behavior are subjec
## [Unreleased][]

* Your contribution here!
* Fix a bug where the formatting of certain Markdown release notes were
inadvertently altered due to stripping indentation off the first line of the
text.

## [0.3.0][] (2016-03-22)

Expand Down
10 changes: 9 additions & 1 deletion lib/chandler/commands/push.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,19 @@ def exit_with_warning

def changelog_version_and_notes_for_tag(tag)
version = tag_mapper.call(tag)
[version, changelog.fetch(version).strip]
notes = strip_surrounding_empty_lines(changelog.fetch(version))
[version, notes]
rescue Chandler::Changelog::NoMatchingVersion
info("Skip #{tag} (no #{version} entry in #{changelog.basename})".gray)
nil
end

# Returns a new string with leading and trailing empty lines removed. A
# line is empty if it is zero-length or contains only whitespace.
def strip_surrounding_empty_lines(str)
str.sub(/\A[[:space:]]*^/, "")
.sub(/$[[:space:]]*\z/, "")
end
end
end
end
13 changes: 13 additions & 0 deletions test/chandler/commands/push_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ def test_tag_prefix_is_removed_from_title_when_pushing_to_github
push.call
end

def test_leading_and_trailing_blank_lines_are_stripped_when_pushing_to_github
@config.changelog
.expects(:fetch).with("v1")
.returns("\n\n * one\n\n * two\n\n")
@github.unstub(:create_or_update_release)
@github
.expects(:create_or_update_release)
.with(:tag => "v1", :title => "1", :description => " * one\n\n * two")

push = Chandler::Commands::Push.new(:tags => %w(v1), :config => @config)
push.call
end

def test_progress_is_pretty_printed_to_stdout
push = Chandler::Commands::Push.new(
:tags => %w(v1 v2.0.2 v99.1.18),
Expand Down

0 comments on commit 6b82a16

Please sign in to comment.