@@ -7,9 +7,9 @@ defmodule Algora.Bounties do
7
7
alias Algora.Accounts.User
8
8
alias Algora.Bounties.Bounty
9
9
alias Algora.Bounties.Claim
10
+ alias Algora.Bounties.Jobs
10
11
alias Algora.Bounties.Tip
11
12
alias Algora.FeeTier
12
- alias Algora.Github
13
13
alias Algora.MoneyUtils
14
14
alias Algora.Organizations.Member
15
15
alias Algora.Payments
@@ -37,9 +37,9 @@ defmodule Algora.Bounties do
37
37
Phoenix.PubSub . subscribe ( Algora.PubSub , "bounties:all" )
38
38
end
39
39
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 ( ) } ) ::
41
41
{ :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
43
43
changeset =
44
44
Bounty . changeset ( % Bounty { } , % {
45
45
amount: amount ,
@@ -72,46 +72,30 @@ defmodule Algora.Bounties do
72
72
creator: creator ,
73
73
owner: owner ,
74
74
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
76
76
} ) 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 }
102
83
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
111
85
end
112
86
end )
113
87
end
114
88
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
+
115
99
@ spec create_tip ( % { creator: User . t ( ) , owner: User . t ( ) , recipient: User . t ( ) , amount: Money . t ( ) } ) ::
116
100
{ :ok , String . t ( ) } | { :error , atom ( ) }
117
101
def create_tip ( % { creator: creator , owner: owner , recipient: recipient , amount: amount } ) do
0 commit comments