File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments