Skip to content

Commit 9803e1f

Browse files
committed
Add initial support to mix tasks result
1 parent 0115026 commit 9803e1f

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

lib/tasks/mix.ex

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,24 +75,22 @@ defimpl GitHooks.Task, for: GitHooks.Tasks.Mix do
7575
Map.put(mix_task, :result, result)
7676
end
7777

78-
# Mix tasks always raise an error if they are not success, at the moment does
79-
# not seems that handling the result is needed. Also, handling the result to
80-
# check the success of a task is almost impossible, as it will depend on each
81-
# implementation.
82-
#
83-
# XXX Since tests runs on the command, if they fail then this task is
84-
# considered failed.
85-
def success?(%MixTask{result: 1}), do: false
86-
def success?(%MixTask{result: _}), do: true
87-
88-
def print_result(%MixTask{task: task, result: 1} = mix_task) do
89-
Printer.error("`#{task}` failed")
78+
# Mix tasks raise an error if they are valid, but determining if they are
79+
# success or not depends on the return of the task.
80+
@success_results [0, :ok, nil]
81+
82+
def success?(%MixTask{result: result}) when result in @success_results, do: true
83+
def success?(%MixTask{result: _}), do: false
84+
85+
def print_result(%MixTask{task: task, result: result} = mix_task)
86+
when result in @success_results do
87+
Printer.success("`#{task}` was successful")
9088

9189
mix_task
9290
end
9391

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

9795
mix_task
9896
end

0 commit comments

Comments
 (0)