Skip to content

Commit cd93a6c

Browse files
committed
fix: ignore bot events
1 parent 4b9c836 commit cd93a6c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/algora_web/controllers/webhooks/github_controller.ex

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ defmodule AlgoraWeb.Webhooks.GithubController do
1616

1717
def new(conn, params) do
1818
with {:ok, webhook} <- Webhook.new(conn),
19+
:ok <- ensure_human_author(webhook, params),
1920
{:ok, _} <- process_commands(webhook, params) do
2021
conn |> put_status(:accepted) |> json(%{status: "ok"})
2122
else
23+
{:error, :bot_event} ->
24+
conn |> put_status(:ok) |> json(%{status: "ok"})
25+
2226
{:error, :missing_header} ->
2327
conn |> put_status(:bad_request) |> json(%{error: "Missing header"})
2428

@@ -35,6 +39,13 @@ defmodule AlgoraWeb.Webhooks.GithubController do
3539
conn |> put_status(:internal_server_error) |> json(%{error: "Internal server error"})
3640
end
3741

42+
defp ensure_human_author(%Webhook{event: event}, params) do
43+
case get_author(event, params) do
44+
%{"type" => "Bot"} -> {:error, :bot_event}
45+
_ -> :ok
46+
end
47+
end
48+
3849
# TODO: cache installation tokens
3950
# TODO: check org permissions on algora
4051
defp get_permissions(author, %{"repository" => repository, "installation" => installation}) do

0 commit comments

Comments
 (0)