Skip to content

Commit 395dffd

Browse files
committed
refactor: streamline command execution and event processing in webhooks
- Added a new private function in GitHubController to handle specific commands without alerting for known commands. - Simplified the alerting mechanism for unknown commands in GitHubController. - Updated StripeController to track only relevant Stripe events, enhancing clarity in event processing and alerting. - Improved logging for unhandled Stripe events to provide better monitoring and debugging capabilities.
1 parent 89c4ee1 commit 395dffd

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

lib/algora_web/controllers/webhooks/github_controller.ex

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -573,20 +573,19 @@ defmodule AlgoraWeb.Webhooks.GithubController do
573573
end
574574
end
575575

576+
defp execute_command(_webhook, {cmd, _args}) when cmd in [:bounty, :tip, :claim, :attempt] do
577+
{:ok, nil}
578+
end
579+
576580
defp execute_command(webhook, command) do
577581
github_ticket = get_github_ticket(webhook)
578582

579-
message =
580-
"Received unknown command: #{inspect(command)}. Ticket: #{github_ticket["html_url"]}. Hook ID: #{webhook.hook_id}"
581-
582-
case Algora.Admin.alert(message) do
583-
[] ->
584-
Logger.error(message)
585-
{:error, :unknown_command}
583+
Algora.Admin.alert(
584+
"Received unknown command: #{inspect(command)}. Ticket: #{github_ticket["html_url"]}. Hook ID: #{webhook.hook_id}",
585+
:error
586+
)
586587

587-
_jobs ->
588-
:ok
589-
end
588+
{:error, :unknown_command}
590589
end
591590

592591
def build_command({:claim, args}, commands) do

lib/algora_web/controllers/webhooks/stripe_controller.ex

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ defmodule AlgoraWeb.Webhooks.StripeController do
4747
{:error, error}
4848
end
4949

50-
@tracked_events ["charge.succeeded", "transfer.created", "checkout.session.completed"]
51-
5250
defp process_event(
5351
%Stripe.Event{
5452
type: "charge.succeeded",
@@ -98,7 +96,13 @@ defmodule AlgoraWeb.Webhooks.StripeController do
9896
end
9997
end
10098

101-
defp process_event(%Stripe.Event{type: type} = event) when type in @tracked_events do
99+
defp process_event(%Stripe.Event{type: type} = event) when type in ["checkout.session.completed"] do
100+
Algora.Admin.alert("Unhandled Stripe event: #{event.type} #{event.id}", :info)
101+
:ok
102+
end
103+
104+
defp process_event(%Stripe.Event{type: type} = event)
105+
when type in ["charge.succeeded", "transfer.created", "checkout.session.completed"] do
102106
Algora.Admin.alert("Unhandled Stripe event: #{event.type} #{event.id}", :error)
103107
:ok
104108
end

0 commit comments

Comments
 (0)