Skip to content

Commit 347e31d

Browse files
committed
Changed eliver.bump to work off of VERSION file instead of mix.exs, also fixed all syntax warnings
1 parent fd5d682 commit 347e31d

File tree

8 files changed

+30
-92
lines changed

8 files changed

+30
-92
lines changed

lib/eliver/git.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ defmodule Eliver.Git do
2727
end
2828

2929
def on_master? do
30-
current_branch == "master"
30+
current_branch() == "master"
3131
end
3232

3333
def fetch! do
@@ -42,7 +42,7 @@ defmodule Eliver.Git do
4242
end
4343

4444
def push!(new_version) do
45-
git "push", ["-q", "origin", current_branch, new_version]
45+
git "push", ["-q", "origin", current_branch(), new_version]
4646
end
4747

4848
defp git(command, args) when is_list(args) do

lib/eliver/mixfile.ex

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
defmodule Eliver.MixFile do
2-
def version_from_mixfile(filename \\ "mix.exs") do
2+
3+
@version_regex ~r/([0-9]+\.[0-9]+\.[0-9]+)/
4+
5+
def version(filename \\ "VERSION") do
36
case File.read(filename) do
47
{:ok, body} ->
5-
(Regex.run(version_regex, body) || []) |> Enum.at(0)
8+
(Regex.run(@version_regex, body) || []) |> Enum.at(0)
69
{:error, _} -> nil
710
end
811
end
912

10-
def bump(new_version, filename \\ "mix.exs") do
13+
def bump(new_version, filename \\ "VERSION") do
1114
case File.read(filename) do
1215
{:ok, body} ->
13-
new_contents = Regex.replace(version_regex, body, new_version)
16+
new_contents = Regex.replace(@version_regex, body, new_version)
1417
File.write(filename, new_contents)
1518
{:error, _} -> nil
1619
end
1720
end
1821

19-
defp version_regex, do: ~r/(?<=version: ")(.*)(?=")/
20-
2122
end
2223

lib/mix/tasks/eliver.bump.ex

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@ defmodule Mix.Tasks.Eliver.Bump do
77
end
88

99
defp bump(_) do
10-
case check_for_git_problems do
10+
case check_for_git_problems() do
1111
{:error, message} ->
1212
say message, :red
1313
{:ok} ->
14-
{new_version, changelog_entries} = get_changes
14+
{new_version, changelog_entries} = get_changes()
1515
if allow_changes?(new_version, changelog_entries) do
1616
make_changes(new_version, changelog_entries)
1717
end
1818
end
1919
end
2020

2121
defp get_changes do
22-
{get_new_version, get_changelog_entries}
22+
{get_new_version(), get_changelog_entries()}
2323
end
2424

2525
defp allow_changes?(new_version, changelog_entries) do
26-
current_version = Eliver.MixFile.version_from_mixfile
26+
current_version = Eliver.MixFile.version
2727
say "\n"
2828
say "Summary of changes:"
2929
say "Bumping version #{current_version}#{new_version}", :green
@@ -48,7 +48,7 @@ defmodule Mix.Tasks.Eliver.Bump do
4848
cond do
4949
!Eliver.Git.is_tracking_branch? ->
5050
{:error, "This branch is not tracking a remote branch. Aborting..."}
51-
!Eliver.Git.on_master? && !continue_on_branch? ->
51+
!Eliver.Git.on_master? && !continue_on_branch?() ->
5252
{:error, "Aborting"}
5353
Eliver.Git.index_dirty? ->
5454
{:error, "Git index dirty. Commit changes before continuing"}
@@ -64,12 +64,12 @@ defmodule Mix.Tasks.Eliver.Bump do
6464
result = ask question, false
6565
case result do
6666
{:ok, value} -> value
67-
{:error, _} -> continue_on_branch?
67+
{:error, _} -> continue_on_branch?()
6868
end
6969
end
7070

7171
defp get_new_version do
72-
Eliver.MixFile.version_from_mixfile |> Eliver.next_version(get_bump_type)
72+
Eliver.MixFile.version |> Eliver.next_version(get_bump_type())
7373
end
7474

7575
defp get_changelog_entries do
@@ -86,7 +86,7 @@ defmodule Mix.Tasks.Eliver.Bump do
8686

8787
case result do
8888
{:ok, value} -> value
89-
{:error, _} -> get_bump_type
89+
{:error, _} -> get_bump_type()
9090
end
9191
end
9292

mix.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
%{"earmark": {:hex, :earmark, "1.2.3", "206eb2e2ac1a794aa5256f3982de7a76bf4579ff91cb28d0e17ea2c9491e46a4", [], [], "hexpm"},
2+
"enquirer": {:hex, :enquirer, "0.1.0", "96ca1a330c919652db4baed6cf572d8c9957a8a305365c54490262c337996a18", [], [], "hexpm"},
3+
"ex_doc": {:hex, :ex_doc, "0.16.4", "4bf6b82d4f0a643b500366ed7134896e8cccdbab4d1a7a35524951b25b1ec9f0", [], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"}}

test/change_log_file_test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ defmodule Eliver.ChangeLogFileTest do
3535
test "it updates the changelog" do
3636
Eliver.ChangeLogFile.bump("1.1.0", ["e1", "e2"], "test/support/CHANGELOG.md")
3737
{:ok, changelog_contents} = File.read("test/support/CHANGELOG.md")
38-
assert changelog_contents == expected_existing_changelog_contents
38+
assert changelog_contents == expected_existing_changelog_contents()
3939
end
4040

4141
test "it is case insensitive and updates the changelog" do
4242
Eliver.ChangeLogFile.bump("1.1.0", ["e1", "e2"], "test/support/CHANGELOG2.md")
4343
{:ok, changelog_contents} = File.read("test/support/CHANGELOG2.md")
44-
assert changelog_contents == expected_existing_changelog_contents
44+
assert changelog_contents == expected_existing_changelog_contents()
4545
end
4646
end
4747

@@ -58,7 +58,7 @@ defmodule Eliver.ChangeLogFileTest do
5858
test "it creates the changelog file if it doesn't exist" do
5959
Eliver.ChangeLogFile.bump("1.1.0", ["e1", "e2"], "test/support/test.md")
6060
{:ok, new_change_log_contents} = File.read("test/support/test.md")
61-
assert new_change_log_contents == expected_new_changelog_contents
61+
assert new_change_log_contents == expected_new_changelog_contents()
6262
end
6363
end
6464

test/mixfile_test.exs

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ defmodule Eliver.MixFileTest do
1414
end
1515

1616
describe "getting the current version number" do
17-
test "it gets the version number when the mix file exixts" do
18-
assert Eliver.MixFile.version_from_mixfile("test/support/test_with_version.exs") == "1.1.0"
17+
test "it gets the version number when the mix file exists" do
18+
assert Eliver.MixFile.version("test/support/test_with_version.exs") == "1.1.0"
1919
end
2020

2121
test "it returns nil when the file does not exist" do
22-
assert Eliver.MixFile.version_from_mixfile("foo.exs") == nil
22+
assert Eliver.MixFile.version("foo.exs") == nil
2323
end
2424

2525
test "it returns nil if the version is not specified in the mix file" do
26-
assert Eliver.MixFile.version_from_mixfile("test/support/test_without_version.exs") == nil
26+
assert Eliver.MixFile.version("test/support/test_without_version.exs") == nil
2727
end
2828
end
2929

@@ -38,35 +38,13 @@ defmodule Eliver.MixFileTest do
3838

3939
def expected_mixfile_contents do
4040
"""
41-
defmodule Eliver.Mixfile do
42-
use Mix.Project
43-
44-
def project do
45-
[app: :eliver_test,
46-
version: "2.0.0",
47-
elixir: "~> 1.3",
48-
build_embedded: Mix.env == :prod,
49-
start_permanent: Mix.env == :prod,
50-
deps: deps()]
51-
end
52-
53-
# Configuration for the OTP application
54-
#
55-
# Type "mix help compile.app" for more information
56-
def application do
57-
[applications: [:logger]]
58-
end
59-
60-
defp deps do
61-
[]
62-
end
63-
end
41+
2.0.0
6442
"""
6543
end
6644

6745
test "it updates the mixfile" do
6846
Eliver.MixFile.bump("2.0.0", "test/support/test_with_version.exs")
69-
assert mixfile_contents == expected_mixfile_contents
47+
assert mixfile_contents() == expected_mixfile_contents()
7048
end
7149

7250
end
Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1 @@
1-
defmodule Eliver.Mixfile do
2-
use Mix.Project
3-
4-
def project do
5-
[app: :eliver_test,
6-
version: "1.1.0",
7-
elixir: "~> 1.3",
8-
build_embedded: Mix.env == :prod,
9-
start_permanent: Mix.env == :prod,
10-
deps: deps()]
11-
end
12-
13-
# Configuration for the OTP application
14-
#
15-
# Type "mix help compile.app" for more information
16-
def application do
17-
[applications: [:logger]]
18-
end
19-
20-
defp deps do
21-
[]
22-
end
23-
end
1+
1.1.0
Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +0,0 @@
1-
defmodule Eliver.Mixfile do
2-
use Mix.Project
3-
4-
def project do
5-
[app: :eliver_test,
6-
elixir: "~> 1.3",
7-
build_embedded: Mix.env == :prod,
8-
start_permanent: Mix.env == :prod,
9-
deps: deps()]
10-
end
11-
12-
# Configuration for the OTP application
13-
#
14-
# Type "mix help compile.app" for more information
15-
def application do
16-
[applications: [:logger]]
17-
end
18-
19-
defp deps do
20-
[]
21-
end
22-
end

0 commit comments

Comments
 (0)