Skip to content

Commit da7145e

Browse files
committed
add mix algora.create_tip
1 parent 9c97221 commit da7145e

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

lib/mix/tasks/algora/create_tip.ex

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
defmodule Mix.Tasks.Algora.CreateTip do
2+
@shortdoc "Creates a mock bounty"
3+
4+
@moduledoc false
5+
use Mix.Task
6+
7+
import Algora.Mocks.GithubMock
8+
9+
def run(args) do
10+
Application.ensure_all_started(:algora)
11+
Application.ensure_all_started(:mox)
12+
Mox.defmock(Algora.GithubMock, for: Algora.Github.Behaviour)
13+
Application.put_env(:algora, :github_client, Algora.GithubMock)
14+
setup_get_issue()
15+
setup_get_repository()
16+
17+
opts = parse_opts(args)
18+
from_user = Algora.Accounts.get_user_by_handle(opts[:from])
19+
to_user = Algora.Accounts.get_user_by_handle(opts[:to])
20+
amount = Money.new(opts[:amount], :USD)
21+
22+
%{
23+
creator: from_user,
24+
owner: from_user,
25+
recipient: to_user,
26+
amount: amount
27+
}
28+
|> Algora.Bounties.create_tip()
29+
|> case do
30+
{:ok, _bounty} ->
31+
IO.puts("Tip created")
32+
33+
{:error, :already_exists} ->
34+
IO.puts("Tip already created")
35+
end
36+
end
37+
38+
defp parse_opts(args) do
39+
{opts, _, _} =
40+
OptionParser.parse(
41+
args,
42+
strict: [from: :string, to: :string, amount: :string]
43+
)
44+
45+
opts
46+
end
47+
end

0 commit comments

Comments
 (0)