@@ -57,6 +57,7 @@ defmodule AlgoraWeb.Webhooks.GithubController do
57
57
issue = params [ "issue" ]
58
58
installation_id = params [ "installation" ] [ "id" ]
59
59
60
+ # TODO: community bounties?
60
61
with { :ok , "admin" } <- get_permissions ( author , params ) ,
61
62
{ :ok , token } <- Github . get_installation_token ( installation_id ) ,
62
63
{ :ok , installation } <-
@@ -81,11 +82,35 @@ 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
- amount = Keyword . get ( args , :amount )
86
- recipient = Keyword . get ( args , :username )
85
+ defp execute_command ( { :tip , args } , author , params ) when not is_nil ( args ) do
86
+ amount = args [ :amount ]
87
+ recipient = args [ :recipient ]
88
+ repo = params [ "repository" ]
89
+ issue = params [ "issue" ]
90
+ installation_id = params [ "installation" ] [ "id" ]
91
+
92
+ # TODO: handle missing amount
93
+ # TODO: handle missing recipient
94
+ # TODO: handle tip to self
95
+ # TODO: handle autopay with cooldown
96
+ # TODO: community tips?
97
+ case get_permissions ( author , params ) do
98
+ { :ok , "admin" } ->
99
+ Bounties . create_tip_intent (
100
+ % {
101
+ recipient: recipient ,
102
+ amount: amount ,
103
+ ticket_ref: % { owner: repo [ "owner" ] [ "login" ] , repo: repo [ "name" ] , number: issue [ "number" ] }
104
+ } ,
105
+ installation_id: installation_id
106
+ )
87
107
88
- Logger . info ( "Tip #{ amount } to #{ recipient } " )
108
+ { :ok , _permission } ->
109
+ { :error , :unauthorized }
110
+
111
+ { :error , _reason } = error ->
112
+ error
113
+ end
89
114
end
90
115
91
116
defp execute_command ( { :claim , args } , _author , _params ) when not is_nil ( args ) do
0 commit comments