Skip to content

Commit 5841ba6

Browse files
committed
discard oban jobs if spam detected
1 parent 4b63144 commit 5841ba6

File tree

1 file changed

+31
-27
lines changed

1 file changed

+31
-27
lines changed

lib/algora/bounties/jobs/notify_bounty.ex

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,37 +25,41 @@ defmodule Algora.Bounties.Jobs.NotifyBounty do
2525
"command_source" => command_source
2626
}
2727
}) do
28-
ticket_ref = %{
29-
owner: ticket_ref["owner"],
30-
repo: ticket_ref["repo"],
31-
number: ticket_ref["number"]
32-
}
28+
if owner_login in Algora.Settings.get_blocked_users() do
29+
:discard
30+
else
31+
ticket_ref = %{
32+
owner: ticket_ref["owner"],
33+
repo: ticket_ref["repo"],
34+
number: ticket_ref["number"]
35+
}
3336

34-
body = """
35-
💎 **#{owner_login}** is offering a **#{amount}** bounty for this issue. View and reward the bounty at `#{AlgoraWeb.Endpoint.host()}/#{ticket_ref.owner}/#{ticket_ref.repo}/issues/#{ticket_ref.number}`
37+
body = """
38+
💎 **#{owner_login}** is offering a **#{amount}** bounty for this issue. View and reward the bounty at `#{AlgoraWeb.Endpoint.host()}/#{ticket_ref.owner}/#{ticket_ref.repo}/issues/#{ticket_ref.number}`
3639
37-
👉 Got a pull request resolving this? Claim the bounty by commenting `/claim ##{ticket_ref.number}` in your PR and joining `#{AlgoraWeb.Endpoint.host()}`
38-
"""
40+
👉 Got a pull request resolving this? Claim the bounty by commenting `/claim ##{ticket_ref.number}` in your PR and joining `#{AlgoraWeb.Endpoint.host()}`
41+
"""
3942

40-
if Github.pat_enabled() do
41-
with {:ok, comment} <-
42-
Github.create_issue_comment(Github.pat(), ticket_ref.owner, ticket_ref.repo, ticket_ref.number, body),
43-
{:ok, ticket} <-
44-
Workspace.ensure_ticket(Github.pat(), ticket_ref.owner, ticket_ref.repo, ticket_ref.number) do
45-
Workspace.create_command_response(%{
46-
comment: comment,
47-
command_source: command_source,
48-
command_id: command_id,
49-
ticket_id: ticket.id
50-
})
43+
if Github.pat_enabled() do
44+
with {:ok, comment} <-
45+
Github.create_issue_comment(Github.pat(), ticket_ref.owner, ticket_ref.repo, ticket_ref.number, body),
46+
{:ok, ticket} <-
47+
Workspace.ensure_ticket(Github.pat(), ticket_ref.owner, ticket_ref.repo, ticket_ref.number) do
48+
Workspace.create_command_response(%{
49+
comment: comment,
50+
command_source: command_source,
51+
command_id: command_id,
52+
ticket_id: ticket.id
53+
})
54+
end
55+
else
56+
Logger.info("""
57+
Github.create_issue_comment(Github.pat(), "#{ticket_ref.owner}", "#{ticket_ref.repo}", #{ticket_ref.number},
58+
\"\"\"
59+
#{body}
60+
\"\"\")
61+
""")
5162
end
52-
else
53-
Logger.info("""
54-
Github.create_issue_comment(Github.pat(), "#{ticket_ref.owner}", "#{ticket_ref.repo}", #{ticket_ref.number},
55-
\"\"\"
56-
#{body}
57-
\"\"\")
58-
""")
5963
end
6064
end
6165

0 commit comments

Comments
 (0)