Skip to content

Commit d3066d2

Browse files
committed
feat: create tips via GitHub app
1 parent d46e4d3 commit d3066d2

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

lib/algora_web/controllers/webhooks/github_controller.ex

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ defmodule AlgoraWeb.Webhooks.GithubController do
5757
issue = params["issue"]
5858
installation_id = params["installation"]["id"]
5959

60+
# TODO: community bounties?
6061
with {:ok, "admin"} <- get_permissions(author, params),
6162
{:ok, token} <- Github.get_installation_token(installation_id),
6263
{:ok, installation} <-
@@ -81,11 +82,35 @@ 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-
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+
)
87107

88-
Logger.info("Tip #{amount} to #{recipient}")
108+
{:ok, _permission} ->
109+
{:error, :unauthorized}
110+
111+
{:error, _reason} = error ->
112+
error
113+
end
89114
end
90115

91116
defp execute_command({:claim, args}, _author, _params) when not is_nil(args) do

0 commit comments

Comments
 (0)