@@ -50,7 +50,8 @@ defmodule AlgoraWeb.Webhooks.GithubController do
50
50
51
51
defp get_permissions ( _author , _params ) , do: { :error , :invalid_params }
52
52
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
54
55
amount = args [ :amount ]
55
56
repo = params [ "repository" ]
56
57
issue = params [ "issue" ]
@@ -81,7 +82,8 @@ defmodule AlgoraWeb.Webhooks.GithubController do
81
82
end
82
83
end
83
84
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
85
87
amount = args [ :amount ]
86
88
recipient = args [ :recipient ]
87
89
repo = params [ "repository" ]
@@ -112,7 +114,8 @@ defmodule AlgoraWeb.Webhooks.GithubController do
112
114
end
113
115
end
114
116
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
116
119
installation_id = params [ "installation" ] [ "id" ]
117
120
pull_request = params [ "pull_request" ]
118
121
repo = params [ "repository" ]
@@ -145,23 +148,28 @@ defmodule AlgoraWeb.Webhooks.GithubController do
145
148
end
146
149
end
147
150
148
- defp execute_command ( _command , _author , _params ) do
151
+ defp execute_command ( _event_action , _command , _author , _params ) do
149
152
{ :error , :unhandled_command }
150
153
end
151
154
152
155
def process_commands ( event , params ) do
153
156
author = get_author ( event , params )
154
157
body = get_body ( event , params )
155
158
159
+ event_action = event <> "." <> params [ "action" ]
160
+
156
161
case Github.Command . parse ( body ) do
157
162
{ :ok , commands } ->
158
163
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
160
165
{ :ok , result } ->
161
166
{ :cont , { :ok , [ result | results ] } }
162
167
163
168
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
+
165
173
{ :halt , error }
166
174
end
167
175
end )
0 commit comments