Skip to content

Commit

Permalink
Add initial support to mix tasks result
Browse files Browse the repository at this point in the history
  • Loading branch information
qgadrian committed Feb 15, 2022
1 parent 0115026 commit 9803e1f
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions lib/tasks/mix.ex
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,22 @@ defimpl GitHooks.Task, for: GitHooks.Tasks.Mix do
Map.put(mix_task, :result, result)
end

# Mix tasks always raise an error if they are not success, at the moment does
# not seems that handling the result is needed. Also, handling the result to
# check the success of a task is almost impossible, as it will depend on each
# implementation.
#
# XXX Since tests runs on the command, if they fail then this task is
# considered failed.
def success?(%MixTask{result: 1}), do: false
def success?(%MixTask{result: _}), do: true

def print_result(%MixTask{task: task, result: 1} = mix_task) do
Printer.error("`#{task}` failed")
# Mix tasks raise an error if they are valid, but determining if they are
# success or not depends on the return of the task.
@success_results [0, :ok, nil]

def success?(%MixTask{result: result}) when result in @success_results, do: true
def success?(%MixTask{result: _}), do: false

def print_result(%MixTask{task: task, result: result} = mix_task)
when result in @success_results do
Printer.success("`#{task}` was successful")

mix_task
end

def print_result(%MixTask{task: task, result: _} = mix_task) do
Printer.success("`#{task}` was successful")
def print_result(%MixTask{task: task, result: result} = mix_task) do
Printer.error("mix task `#{task}` failed, return result: #{inspect(result)}")

mix_task
end
Expand Down

0 comments on commit 9803e1f

Please sign in to comment.