File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed
lib/algora_web/controllers/webhooks Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -16,9 +16,13 @@ defmodule AlgoraWeb.Webhooks.GithubController do
16
16
17
17
def new ( conn , params ) do
18
18
with { :ok , webhook } <- Webhook . new ( conn ) ,
19
+ :ok <- ensure_human_author ( webhook , params ) ,
19
20
{ :ok , _ } <- process_commands ( webhook , params ) do
20
21
conn |> put_status ( :accepted ) |> json ( % { status: "ok" } )
21
22
else
23
+ { :error , :bot_event } ->
24
+ conn |> put_status ( :ok ) |> json ( % { status: "ok" } )
25
+
22
26
{ :error , :missing_header } ->
23
27
conn |> put_status ( :bad_request ) |> json ( % { error: "Missing header" } )
24
28
@@ -35,6 +39,13 @@ defmodule AlgoraWeb.Webhooks.GithubController do
35
39
conn |> put_status ( :internal_server_error ) |> json ( % { error: "Internal server error" } )
36
40
end
37
41
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
+
38
49
# TODO: cache installation tokens
39
50
# TODO: check org permissions on algora
40
51
defp get_permissions ( author , % { "repository" => repository , "installation" => installation } ) do
You can’t perform that action at this time.
0 commit comments