Skip to content

Commit b90080c

Browse files
committed
move bounty notification logic into bounties context
1 parent 31faef9 commit b90080c

File tree

2 files changed

+35
-29
lines changed

2 files changed

+35
-29
lines changed

lib/algora/bounties/bounties.ex

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ defmodule Algora.Bounties do
99
alias Algora.Bounties.Claim
1010
alias Algora.Bounties.Tip
1111
alias Algora.FeeTier
12+
alias Algora.Github
1213
alias Algora.MoneyUtils
1314
alias Algora.Organizations.Member
1415
alias Algora.Payments
@@ -18,6 +19,8 @@ defmodule Algora.Bounties do
1819
alias Algora.Workspace
1920
alias Algora.Workspace.Ticket
2021

22+
require Logger
23+
2124
def base_query, do: Bounty
2225

2326
@type criterion ::
@@ -79,6 +82,36 @@ defmodule Algora.Bounties do
7982
end
8083
end
8184

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+
)
102+
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
111+
end
112+
end)
113+
end
114+
82115
@spec create_tip(%{creator: User.t(), owner: User.t(), recipient: User.t(), amount: Money.t()}) ::
83116
{:ok, String.t()} | {:error, atom()}
84117
def create_tip(%{creator: creator, owner: owner, recipient: recipient, amount: amount}) do

lib/algora_web/live/community/dashboard_live.ex

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ defmodule AlgoraWeb.Community.DashboardLive do
1010
alias Algora.Accounts
1111
alias Algora.Bounties
1212
alias Algora.Contracts
13-
alias Algora.Github
1413
alias Algora.Types.USD
1514
alias Algora.Validations
1615
alias Algora.Workspace
@@ -221,40 +220,14 @@ defmodule AlgoraWeb.Community.DashboardLive do
221220
ticket_ref = get_field(changeset, :ticket_ref)
222221

223222
with %{valid?: true} <- changeset,
224-
{:ok, _} <-
223+
{:ok, bounty} <-
225224
Bounties.create_bounty(%{
226225
creator: socket.assigns.current_user,
227226
owner: socket.assigns.current_user,
228227
amount: amount,
229228
ticket_ref: ticket_ref
230229
}) do
231-
# TODO: post comment in a separate job
232-
body = """
233-
💎 **#{socket.assigns.current_user.provider_login}** is offering a **#{Money.to_string!(amount, no_fraction_if_integer: true)}** bounty for this issue
234-
235-
👉 Got a pull request resolving this? Claim the bounty by commenting `/claim ##{ticket_ref.number}` in your PR and joining swift.algora.io
236-
"""
237-
238-
Task.start(fn ->
239-
if Github.pat_enabled() do
240-
Github.create_issue_comment(
241-
Github.pat(),
242-
ticket_ref.owner,
243-
ticket_ref.repo,
244-
ticket_ref.number,
245-
body
246-
)
247-
else
248-
Logger.info("""
249-
Github.create_issue_comment(Github.pat(), "#{ticket_ref.owner}", "#{ticket_ref.repo}", #{ticket_ref.number},
250-
\"\"\"
251-
#{body}
252-
\"\"\")
253-
""")
254-
255-
:ok
256-
end
257-
end)
230+
Bounties.notify_bounty(%{owner: socket.assigns.current_user, bounty: bounty, ticket_ref: ticket_ref})
258231

259232
{:noreply,
260233
socket

0 commit comments

Comments
 (0)