@@ -50,7 +50,8 @@ defmodule AlgoraWeb.Webhooks.GithubController do
5050
5151 defp get_permissions ( _author , _params ) , do: { :error , :invalid_params }
5252
53- defp execute_command ( { :bounty , args } , author , params ) do
53+ defp execute_command ( event_action , { :bounty , args } , author , params )
54+ when event_action in [ "issues.opened" , "issues.edited" , "issue_comment.created" , "issue_comment.edited" ] do
5455 amount = args [ :amount ]
5556 repo = params [ "repository" ]
5657 issue = params [ "issue" ]
@@ -81,7 +82,8 @@ defmodule AlgoraWeb.Webhooks.GithubController do
8182 end
8283 end
8384
84- defp execute_command ( { :tip , args } , author , params ) when not is_nil ( args ) do
85+ defp execute_command ( event_action , { :tip , args } , author , params )
86+ when event_action in [ "issue_comment.created" , "issue_comment.edited" ] do
8587 amount = args [ :amount ]
8688 recipient = args [ :recipient ]
8789 repo = params [ "repository" ]
@@ -112,7 +114,8 @@ defmodule AlgoraWeb.Webhooks.GithubController do
112114 end
113115 end
114116
115- defp execute_command ( { :claim , args } , author , params ) when not is_nil ( args ) do
117+ defp execute_command ( event_action , { :claim , args } , author , params )
118+ when event_action in [ "pull_request.opened" , "pull_request.reopened" , "pull_request.edited" ] do
116119 installation_id = params [ "installation" ] [ "id" ]
117120 pull_request = params [ "pull_request" ]
118121 repo = params [ "repository" ]
@@ -145,23 +148,28 @@ defmodule AlgoraWeb.Webhooks.GithubController do
145148 end
146149 end
147150
148- defp execute_command ( _command , _author , _params ) do
151+ defp execute_command ( _event_action , _command , _author , _params ) do
149152 { :error , :unhandled_command }
150153 end
151154
152155 def process_commands ( event , params ) do
153156 author = get_author ( event , params )
154157 body = get_body ( event , params )
155158
159+ event_action = event <> "." <> params [ "action" ]
160+
156161 case Github.Command . parse ( body ) do
157162 { :ok , commands } ->
158163 Enum . reduce_while ( commands , { :ok , [ ] } , fn command , { :ok , results } ->
159- case execute_command ( command , author , params ) do
164+ case execute_command ( event_action , command , author , params ) do
160165 { :ok , result } ->
161166 { :cont , { :ok , [ result | results ] } }
162167
163168 error ->
164- Logger . error ( "Command execution failed for #{ inspect ( command ) } : #{ inspect ( error ) } " )
169+ Logger . error (
170+ "Command execution failed for #{ event_action } (#{ event [ "id" ] } ): #{ inspect ( command ) } : #{ inspect ( error ) } "
171+ )
172+
165173 { :halt , error }
166174 end
167175 end )
0 commit comments