@@ -7,9 +7,9 @@ defmodule Algora.Bounties do
77  alias  Algora.Accounts.User 
88  alias  Algora.Bounties.Bounty 
99  alias  Algora.Bounties.Claim 
10+   alias  Algora.Bounties.Jobs 
1011  alias  Algora.Bounties.Tip 
1112  alias  Algora.FeeTier 
12-   alias  Algora.Github 
1313  alias  Algora.MoneyUtils 
1414  alias  Algora.Organizations.Member 
1515  alias  Algora.Payments 
@@ -37,9 +37,9 @@ defmodule Algora.Bounties do
3737    Phoenix.PubSub . subscribe ( Algora.PubSub ,  "bounties:all" ) 
3838  end 
3939
40-   @ spec  create_bounty ( % { creator:  User . t ( ) ,  owner:  User . t ( ) ,  amount:  Money . t ( ) ,  ticket:  Ticket . t ( ) } )  :: 
40+   @ spec  do_create_bounty ( % { creator:  User . t ( ) ,  owner:  User . t ( ) ,  amount:  Money . t ( ) ,  ticket:  Ticket . t ( ) } )  :: 
4141          { :ok ,  Bounty . t ( ) }  |  { :error ,  atom ( ) } 
42-   def   create_bounty ( % { creator:  creator ,  owner:  owner ,  amount:  amount ,  ticket:  ticket } )  do 
42+   defp   do_create_bounty ( % { creator:  creator ,  owner:  owner ,  amount:  amount ,  ticket:  ticket } )  do 
4343    changeset  = 
4444      Bounty . changeset ( % Bounty { } ,  % { 
4545        amount:  amount , 
@@ -72,46 +72,30 @@ defmodule Algora.Bounties do
7272        creator:  creator , 
7373        owner:  owner , 
7474        amount:  amount , 
75-         ticket_ref:  % { owner:  repo_owner ,  repo:  repo_name ,  number:  number } 
75+         ticket_ref:  % { owner:  repo_owner ,  repo:  repo_name ,  number:  number }   =   ticket_ref 
7676      } )  do 
77-     with  { :ok ,  token }  <-  Accounts . get_access_token ( creator ) , 
78-          { :ok ,  ticket }  <-  Workspace . ensure_ticket ( token ,  repo_owner ,  repo_name ,  number )  do 
79-       create_bounty ( % { creator:  creator ,  owner:  owner ,  amount:  amount ,  ticket:  ticket } ) 
80-     else 
81-       { :error ,  _reason }  =  error  ->  error 
82-     end 
83-   end 
84- 
85-   def  notify_bounty ( % { owner:  owner ,  bounty:  bounty ,  ticket_ref:  ticket_ref } )  do 
86-     # TODO: post comment in a separate job 
87-     body  =  """ 
88-     💎 **#{ owner . provider_login }  ** is offering a **#{ Money . to_string! ( bounty . amount ,  no_fraction_if_integer:  true ) }  ** bounty for this issue 
89- 
90-     👉 Got a pull request resolving this? Claim the bounty by commenting `/claim ##{ ticket_ref . number }  ` in your PR and joining swift.algora.io 
91-     """ 
92- 
93-     Task . start ( fn  -> 
94-       if  Github . pat_enabled ( )  do 
95-         Github . create_issue_comment ( 
96-           Github . pat ( ) , 
97-           ticket_ref . owner , 
98-           ticket_ref . repo , 
99-           ticket_ref . number , 
100-           body 
101-         ) 
77+     Repo . transact ( fn  -> 
78+       with  { :ok ,  token }  <-  Accounts . get_access_token ( creator ) , 
79+            { :ok ,  ticket }  <-  Workspace . ensure_ticket ( token ,  repo_owner ,  repo_name ,  number ) , 
80+            { :ok ,  bounty }  <-  do_create_bounty ( % { creator:  creator ,  owner:  owner ,  amount:  amount ,  ticket:  ticket } ) , 
81+            { :ok ,  _job }  <-  notify_bounty ( % { owner:  owner ,  bounty:  bounty ,  ticket_ref:  ticket_ref } )  do 
82+         { :ok ,  bounty } 
10283      else 
103-         Logger . info ( """ 
104-         Github.create_issue_comment(Github.pat(), "#{ ticket_ref . owner }  ", "#{ ticket_ref . repo }  ", #{ ticket_ref . number }  , 
105-                \" \" \"  
106-                #{ body }  
107-                \" \" \" ) 
108-         """ ) 
109- 
110-         :ok 
84+         { :error ,  _reason }  =  error  ->  error 
11185      end 
11286    end ) 
11387  end 
11488
89+   def  notify_bounty ( % { owner:  owner ,  bounty:  bounty ,  ticket_ref:  ticket_ref } )  do 
90+     % { 
91+       owner_login:  owner . provider_login , 
92+       amount:  Money . to_string! ( bounty . amount ,  no_fraction_if_integer:  true ) , 
93+       ticket_ref:  % { owner:  ticket_ref . owner ,  repo:  ticket_ref . repo ,  number:  ticket_ref . number } 
94+     } 
95+     |>  Jobs.NotifyBounty . new ( ) 
96+     |>  Oban . insert ( ) 
97+   end 
98+ 
11599  @ spec  create_tip ( % { creator:  User . t ( ) ,  owner:  User . t ( ) ,  recipient:  User . t ( ) ,  amount:  Money . t ( ) } )  :: 
116100          { :ok ,  String . t ( ) }  |  { :error ,  atom ( ) } 
117101  def  create_tip ( % { creator:  creator ,  owner:  owner ,  recipient:  recipient ,  amount:  amount } )  do 
0 commit comments