Skip to content

Commit

Permalink
feat(Changex.Formatter.Markdown): pass version in opts instead arguments
Browse files Browse the repository at this point in the history
Previously there was an inconsistency between
`Changex.Formatter.Markdown` and `Changex.Formatter.Elixir` where in
`Elixir` it would take the version as part of the opts list and in
`Markdown` it was a separate argument. In commit
c3919d4 it is made clear that the
intention was to pass an opts instead of the version, however this
change was node made for `Markdown` at the same time. The format
function between the two modules is now consistent.

The `update` and `diff` tasks have been updated to use the new function
with an arity of 2.

BREAKING CHANGE: Calling `Changex.Formatter.Markdown.format` with an
arity of 3 is no longer valid. The `version` should be specified as a
keyword in the second argument which is a keyword list.
  • Loading branch information
Gary Rennie committed Dec 4, 2014
1 parent 42c5719 commit 34bd26d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/changex/formatter/markdown.ex
Expand Up @@ -42,8 +42,8 @@ defmodule Changex.Formatter.Markdown do
* commit 8 - hash
"""
def format(commits, version \\ nil, opts \\ []) do
heading(version) <> types(commits, opts)
def format(commits, opts \\ []) do
heading(Keyword.get(opts, :version)) <> types(commits, opts)
end

defp heading(version) do
Expand Down
2 changes: 1 addition & 1 deletion lib/mix/tasks/changex/diff.ex
Expand Up @@ -81,7 +81,7 @@ defmodule Mix.Tasks.Changex.Diff do
Changex.Formatter.Terminal.output(commits, version)
end
defp output(commits, "markdown", version, opts) do
Changex.Formatter.Markdown.format(commits, version, opts) |> IO.puts
Changex.Formatter.Markdown.format(commits, Keyword.put(opts, :version, version)) |> IO.puts
end
defp output(commits, "elixir", version, opts) do
Changex.Formatter.Elixir.format(commits, version: version) |> IO.puts
Expand Down
4 changes: 2 additions & 2 deletions lib/mix/tasks/changex/update.ex
Expand Up @@ -48,12 +48,12 @@ defmodule Mix.Tasks.Changex.Update do
end

defp build(commits, previous, "markdown", opts) do
head = commits |> Changex.Formatter.Markdown.format(nil, opts)
head = commits |> Changex.Formatter.Markdown.format(opts)
head <> "\n\n" <> previous
end

defp build(commits, previous, "elixir", opts) do
head = commits |> Changex.Formatter.Elixir.format(nil, opts)
head = commits |> Changex.Formatter.Elixir.format(opts)
head <> "\n\n" <> previous
end

Expand Down
6 changes: 3 additions & 3 deletions test/changex/formatter/markdown_test.exs
Expand Up @@ -19,7 +19,7 @@ defmodule Changex.Formatter.MarkdownTest do
end

test "Formatting with an explicit version", %{commits: commits} do
assert Changex.Formatter.Markdown.format(commits, "v10") == expected_markdown("v10")
assert Changex.Formatter.Markdown.format(commits, version: "v10") == expected_markdown("v10")
end

test "Formatting with an implicit version", %{commits: commits} do
Expand All @@ -28,7 +28,7 @@ defmodule Changex.Formatter.MarkdownTest do
end

test "Formatting with a github url", %{commits: commits} do
assert Changex.Formatter.Markdown.format(commits, "v10", [github: "gazler/changex"]) == expected_markdown_with_github
assert Changex.Formatter.Markdown.format(commits, [version: "v10", github: "gazler/changex"]) == expected_markdown_with_github
end

test "Formatting with a missing section" do
Expand All @@ -43,7 +43,7 @@ defmodule Changex.Formatter.MarkdownTest do
* **dashboard**
* show number of bots on the dashboard (5c764b2957d1c6e7ed73e1691a55399c85b62c34)
""" |> String.rstrip
assert Changex.Formatter.Markdown.format(commits, "v10") == expected
assert Changex.Formatter.Markdown.format(commits, version: "v10") == expected
end

defp expected_markdown(version) do
Expand Down

0 comments on commit 34bd26d

Please sign in to comment.