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

Commit

Permalink
Merge pull request #10 from mattbrictson/changelog-h1s
Browse files Browse the repository at this point in the history
Support CHANGELOG versions at h1-level headings
  • Loading branch information
mattbrictson committed Feb 6, 2016
2 parents 6d25011 + 576f287 commit 3fe0ae4
Show file tree
Hide file tree
Showing 6 changed files with 12,395 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ chandler is in a pre-1.0 state. This means that its APIs and behavior are subjec
## [Unreleased][]

* Your contribution here!
* Chandler now understands versions at Markdown/Rdoc h1-level headings (previously only h2 and h3 were searched).
* If Chandler can't find any version tags, print an error message rather than exiting silently.
* If Chandler can't find a version in your CHANGELOG, it will log a warning rather than exiting with an uncaught exception.
* Add `--tag-prefix` option to allow for other Git version tag formats (e.g. `myapp-v1.0.0`; see [#3](https://github.com/mattbrictson/chandler/issues/3))
Expand Down
15 changes: 7 additions & 8 deletions lib/chandler/changelog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ class Changelog
NoMatchingVersion = Class.new(StandardError)

HEADING_PATTERNS = [
/^##[[:space:]]+.*\n/, # Markdown "atx" style
/^#[[:space:]]+.*\n/, # Markdown "atx" style
/^##[[:space:]]+.*\n/,
/^###[[:space:]]+.*\n/,
/^==[[:space:]]+.*\n/, # Rdoc style
/^=[[:space:]]+.*\n/, # Rdoc style
/^==[[:space:]]+.*\n/,
/^===[[:space:]]+.*\n/,
/^\S.*\n-+\n/ # Markdown "Setext" style
].freeze
Expand Down Expand Up @@ -49,19 +51,16 @@ def basename
# The version numbers are assumed to be contained at Markdown or Rdoc
# headings. The release notes for those version numbers are the text
# delimited by those headings. The algorithm tries various styles of these
# Markdown and Rdoc headings (see `HEADING_PATTERNS`) until it finds one
# that matches.
# Markdown and Rdoc headings (see `HEADING_PATTERNS`).
#
# The resulting hash entries look like:
# { "1.0.1" => "\nRelease notes for 1.0.1.\n" }
#
def versions
@versions ||= begin
versions = HEADING_PATTERNS.find do |heading_re|
found = versions_at_headings(heading_re)
break(found) unless found.empty?
HEADING_PATTERNS.reduce({}) do |found, heading_re|
versions_at_headings(heading_re).merge(found)
end
versions || {}
end
end

Expand Down
27 changes: 27 additions & 0 deletions test/chandler/changelog_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ def test_fetch_airbrussh_versions
assert_match("Initial release", changelog.fetch("v0.0.1"))
end

def test_fetch_angular_versions
changelog = new_changelog("angular.md")

assert_match("Copy `inputs` for expressions", changelog.fetch("1.5.0"))
assert_match("does not affect the `ngSwipe`", changelog.fetch("1.5.0-rc.2"))
assert_match("**filterFilter:** due to", changelog.fetch("1.4.0-beta.2"))
end

def test_fetch_async_versions
changelog = new_changelog("async.md")

assert_match('Allow using `"consructor"`', changelog.fetch("v1.5.2"))
assert_match("Various doc fixes (#971, #980)", changelog.fetch("v1.5.1"))
assert_match("Added `asyncify`/`wrapSync`", changelog.fetch("v1.3.0"))
assert_match("No known breaking changes", changelog.fetch("v1.0.0"))
end

def test_fetch_bootstrap_sass_versions
changelog = new_changelog("bootstrap-sass.md")

Expand Down Expand Up @@ -97,6 +114,16 @@ def test_fetch_devise_versions
assert_match("`bcrypt` dependency updated", changelog.fetch("v3.2.4"))
end

def test_fetch_less_js_versions
changelog = new_changelog("less.js.md")

assert_match("Underscore now allowed in dimen", changelog.fetch("2.6.0"))
assert_match("Fix import inline a URL", changelog.fetch("2.5.3"))
assert_match("less.parse now exposes a way to", changelog.fetch("2.2.0"))
assert_match("browser bundle no longer leaks", changelog.fetch("2.0.0-b3"))
assert_match("support @import-once", changelog.fetch("1.3.1"))
end

def test_fetch_rake_versions
changelog = new_changelog("rake.rdoc")

Expand Down
Loading

0 comments on commit 3fe0ae4

Please sign in to comment.