Skip to content

Commit

Permalink
🎨 apply mix format to the repo
Browse files Browse the repository at this point in the history
  • Loading branch information
mpanarin committed Jul 15, 2021
1 parent 713e71d commit e65556a
Show file tree
Hide file tree
Showing 17 changed files with 200 additions and 152 deletions.
1 change: 1 addition & 0 deletions config/dev.exs
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions config/prod.exs
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions config/test.exs
@@ -0,0 +1 @@

4 changes: 2 additions & 2 deletions lib/Bumper/bumper.ex
Expand Up @@ -14,7 +14,7 @@ defmodule Versioce.Bumper do
iex> Versioce.Bumper.current_version
{:ok, "0.1.0"}
"""
@spec current_version() :: {:ok, String.t} | {:error, String.t}
@spec current_version() :: {:ok, String.t()} | {:error, String.t()}
def current_version do
case Mix.Project.get() do
nil -> {:error, "No project configured"}
Expand Down Expand Up @@ -49,7 +49,7 @@ defmodule Versioce.Bumper do
iex> Versioce.Bumper.bump({[], ["minor"]}, "0.0.1")
"0.1.0"
"""
@spec bump({OptionParser.parsed, OptionParser.argv}, String.t) :: String.t
@spec bump({OptionParser.parsed(), OptionParser.argv()}, String.t()) :: String.t()
def bump({[], []}, from) do
IO.puts("Nothing to do")
from
Expand Down
8 changes: 5 additions & 3 deletions lib/Bumper/files.ex
Expand Up @@ -2,7 +2,8 @@ defmodule Versioce.Bumper.Files do
alias Versioce.Bumper.FilesFake
alias Versioce.Bumper.FilesImplementation

defdelegate update_version_files(from, to), to: if Mix.env == :test, do: FilesFake, else: FilesImplementation
defdelegate update_version_files(from, to),
to: if(Mix.env() == :test, do: FilesFake, else: FilesImplementation)
end

defmodule Versioce.Bumper.FilesFake do
Expand Down Expand Up @@ -30,16 +31,17 @@ defmodule Versioce.Bumper.FilesImplementation do
"""
@spec update_version_files(String.t(), String.t()) :: :ok | Exception
def update_version_files(from, to) do
["mix.exs" | Config.files]
["mix.exs" | Config.files()]
|> Enum.each(&update_version_file(&1, from, to))
end

defp update_version_file(file, from, to) do
data =
File.read!(file)
|> String.replace(from, to, global: Config.global)
|> String.replace(from, to, global: Config.global())

File.write!(file, data)
end

# coveralls-ignore-stop
end
39 changes: 28 additions & 11 deletions lib/Config/config.ex
Expand Up @@ -13,27 +13,44 @@ defmodule Versioce.Config do

import Versioce.Config.Macros, only: :macros

value :files, ["README.md"],
"Files to be updated with new version"
value :global, false,
value(:files, ["README.md"], "Files to be updated with new version")

value(
:global,
false,
"Whether the update will be global in file.\nBy default versioce will update only the first version in file it finds"
value :pre_hooks, [],
"Hooks to run before the version bumping"
value :post_hooks, [],
"Hooks to run after the version bumping"
)

value(:pre_hooks, [], "Hooks to run before the version bumping")
value(:post_hooks, [], "Hooks to run after the version bumping")

defmodule Git do
@moduledoc """
Configuration module for versioce git integration.
see `Versioce.Config` for more details
"""
value [:git, :dirty_add], false,
value(
[:git, :dirty_add],
false,
"Whether to add all the files in `git add` or only from `Versioce.Config.files`. By default only `Versioce.Config.files`"
value [:git, :commit_message_template], "Bump version to {version}",
)

value(
[:git, :commit_message_template],
"Bump version to {version}",
"Template for the commit message. `{version}` will be replaced with the version you bumped to"
value [:git, :tag_template], "{version}",
)

value(
[:git, :tag_template],
"{version}",
"Template for the tag annotation. `{version}` will be replaced with the version you bumped to"
value [:git, :tag_message_template], "Release version to {version}",
)

value(
[:git, :tag_message_template],
"Release version to {version}",
"Template for the tag message. `{version}` will be replaced with the version you bumped to"
)
end
end
2 changes: 1 addition & 1 deletion lib/Config/config_macros.ex
Expand Up @@ -51,6 +51,7 @@ defmodule Versioce.Config.Macros do
defmacro value(path, default, doc) when is_list(path) do
h = List.first(path)
t = List.last(path)

quote do
@doc """
Get config value for #{to_string(unquote(t))}
Expand Down Expand Up @@ -81,5 +82,4 @@ defmodule Versioce.Config.Macros do
end
end
end

end
15 changes: 7 additions & 8 deletions lib/Git/utils.ex
Expand Up @@ -6,15 +6,15 @@ defmodule Versioce.Git do
@doc """
Get git repository.
"""
@spec repo() :: Git.Repository.t
@spec repo() :: Git.Repository.t()
def repo do
Git.init!()
end

@doc """
Stage files.
"""
@spec add([String.t]) :: String.t
@spec add([String.t()]) :: String.t()
def add(args \\ ["."]) do
repo()
|> Git.add!(args)
Expand All @@ -23,7 +23,7 @@ defmodule Versioce.Git do
@doc """
Make a commit with a message.
"""
@spec commit(String.t) :: String.t
@spec commit(String.t()) :: String.t()
def commit(message) do
repo()
|> Git.commit!(["-m", message])
Expand All @@ -32,27 +32,26 @@ defmodule Versioce.Git do
@doc """
Create a tag.
"""
@spec tag(String.t, String.t) :: String.t
@spec tag(String.t(), String.t()) :: String.t()
def tag(name, message) do
repo()
|> Git.tag!(["-a", name, "-m", message])
end
end


defmodule Versioce.Git.Hook do
@moduledoc false
@moduledoc false

@doc false
defmacro __using__(_opts) do
quote do
quote do
@doc false
def run(false, _) do
{:error, "Optional dependency `git_cli` is not loaded."}
end

@doc false
def run(params) do
def run(params) do
Code.ensure_loaded?(Git)
|> run(params)
end
Expand Down
15 changes: 7 additions & 8 deletions lib/Hooks/behaviours.ex
Expand Up @@ -25,12 +25,12 @@ defmodule Versioce.PreHook do
a list of command line args for `bump` task.
It should return them in form `{:ok, args} | {:error, reason}`
"""
@callback run([String.t]) :: {:ok, [String.t]} | {:error, String.t}
@callback run([String.t()]) :: {:ok, [String.t()]} | {:error, String.t()}

@doc false
defmacro __using__(_opts) do
quote do
@behaviour Versioce.PreHook
quote do
@behaviour Versioce.PreHook
end
end
end
Expand Down Expand Up @@ -62,17 +62,16 @@ defmodule Versioce.PostHook do
the new version of the project.
It should return it in form `{:ok, version} | {:error, reason}`
"""
@callback run(String.t) :: {:ok, String.t} | {:error, String.t}
@callback run(String.t()) :: {:ok, String.t()} | {:error, String.t()}

@doc false
defmacro __using__(_opts) do
quote do
@behaviour Versioce.PostHook
quote do
@behaviour Versioce.PostHook
end
end
end


defmodule Versioce.OK do
@moduledoc false

Expand All @@ -88,12 +87,12 @@ defmodule Versioce.OK do
def unit(value), do: {:ok, value}
end


defmodule Versioce.Hooks do
@moduledoc false

@spec run(any, [module()]) :: Versioce.OK.ok_tuple()
def run(params, []), do: Versioce.OK.unit(params)

def run(params, hooks) do
[h | tail] = hooks

Expand Down
4 changes: 2 additions & 2 deletions lib/Hooks/inspect.ex
Expand Up @@ -6,7 +6,7 @@ defmodule Versioce.PreHooks.Inspect do
"""
use Versioce.PreHook

def run(args) do
def run(args) do
IO.inspect(args)
{:ok, args}
end
Expand All @@ -20,7 +20,7 @@ defmodule Versioce.PostHooks.Inspect do
"""
use Versioce.PostHook

def run(version) do
def run(version) do
IO.inspect(version)
{:ok, version}
end
Expand Down
26 changes: 16 additions & 10 deletions lib/Tasks/mix_bump.ex
Expand Up @@ -22,21 +22,27 @@ defmodule Mix.Tasks.Bump do

defp run_pre_hooks({options, params}) do
case Keyword.fetch(options, :no_pre_hooks) do
{:ok, true} -> {:ok, "No hooks to run"}
{:ok, true} ->
{:ok, "No hooks to run"}

_ ->
hooks = Config.pre_hooks()
|> IO.inspect(label: "Running pre-hooks")
hooks =
Config.pre_hooks()
|> IO.inspect(label: "Running pre-hooks")

Versioce.Hooks.run(params, hooks)
end
end

defp run_post_hooks({{options, _}, params}) do
case Keyword.fetch(options, :no_post_hooks) do
{:ok, true} -> {:ok, "No hooks to run"}
{:ok, true} ->
{:ok, "No hooks to run"}

_ ->
hooks = Config.post_hooks()
|> IO.inspect(label: "Running post-hooks")
hooks =
Config.post_hooks()
|> IO.inspect(label: "Running post-hooks")

Versioce.Hooks.run(params, hooks)
end
Expand All @@ -54,9 +60,9 @@ defmodule Mix.Tasks.Bump do

@doc false
@spec run(
{OptionParser.parsed, OptionParser.argv},
{:ok, String.t} | {:error, String.t}
) :: {:ok, String.t} | {:error, String.t}
{OptionParser.parsed(), OptionParser.argv()},
{:ok, String.t()} | {:error, String.t()}
) :: {:ok, String.t()} | {:error, String.t()}
def run(_, {:error, error} = res) do
IO.puts("Error: #{error}")

Expand All @@ -74,7 +80,7 @@ defmodule Mix.Tasks.Bump do
end

@doc false
@spec parse([String.t]) :: {OptionParser.parsed, OptionParser.argv}
@spec parse([String.t()]) :: {OptionParser.parsed(), OptionParser.argv()}
def parse(options) do
OptionParser.parse!(options, strict: @options)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/Tasks/mix_bump_version.ex
Expand Up @@ -14,7 +14,7 @@ defmodule Mix.Tasks.Bump.Version do

@doc false
def run(_) do
{_, text} = Versioce.Bumper.current_version
{_, text} = Versioce.Bumper.current_version()

IO.puts(text)
end
Expand Down
6 changes: 3 additions & 3 deletions mix.exs
Expand Up @@ -26,7 +26,7 @@ defmodule Versioce.MixProject do
"coveralls.detail": :test,
"coveralls.post": :test,
"coveralls.html": :test,
"coveralls.json": :test,
"coveralls.json": :test
]
]
end
Expand Down Expand Up @@ -57,7 +57,7 @@ defmodule Versioce.MixProject do
{:ex_doc, "~> 0.22", only: [:release, :dev]},
{:dialyxir, "~> 1.0", only: [:dev], runtime: false},
{:excoveralls, "~> 0.10", only: :test},
{:git_cli, "~> 0.3.0", optional: true},
{:git_cli, "~> 0.3.0", optional: true}
]
end

Expand All @@ -68,7 +68,7 @@ defmodule Versioce.MixProject do
source_ref: "v#{@version}",
extras: [
"README.md",
"docs/available_hooks.md",
"docs/available_hooks.md"
]
]
end
Expand Down

0 comments on commit e65556a

Please sign in to comment.