Skip to content

Commit bf6b161

Browse files
committed
require amount in slash bounty command
1 parent 4588221 commit bf6b161

File tree

3 files changed

+36
-42
lines changed

3 files changed

+36
-42
lines changed

lib/algora/integrations/github/command.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ defmodule Algora.Github.Command do
3838
"/bounty"
3939
|> string()
4040
|> ignore()
41-
|> concat(whitespace() |> ignore() |> concat(amount()) |> optional())
41+
|> concat(whitespace() |> ignore() |> concat(amount()))
4242
|> tag(:bounty)
4343
|> label(@usage.bounty)
4444
end

lib/algora_web/controllers/webhooks/github_controller.ex

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -48,50 +48,44 @@ defmodule AlgoraWeb.Webhooks.GithubController do
4848
defp get_permissions(_author, _params), do: {:error, :invalid_params}
4949

5050
defp execute_command({:bounty, args}, author, params) do
51-
amount = Keyword.get(args, :amount)
51+
amount = Keyword.fetch!(args, :amount)
5252

5353
case get_permissions(author, params) do
5454
{:ok, "admin"} ->
55-
case amount do
56-
nil ->
57-
{:ok, :open_to_bids}
58-
59-
amount ->
60-
# Get repository and issue details from params
61-
repo = params["repository"]
62-
issue = params["issue"]
63-
64-
# Construct the bounty message
65-
message = """
66-
## 💎 $#{amount} bounty [• #{repo["owner"]["login"]}](https://console.algora.io/org/#{repo["owner"]["login"]})
67-
### Steps to solve:
68-
1. **Start working**: Comment `/attempt ##{issue["number"]}` with your implementation plan
69-
2. **Submit work**: Create a pull request including `/claim ##{issue["number"]}` in the PR body to claim the bounty
70-
3. **Receive payment**: 100% of the bounty is received 2-5 days post-reward. [Make sure you are eligible for payouts](https://docs.algora.io/bounties/payments#supported-countries-regions)
71-
72-
Thank you for contributing to #{repo["full_name"]}!
73-
74-
**[Add a bounty](https://console.algora.io/org/#{repo["owner"]["login"]}/bounties/community?fund=#{repo["full_name"]}%23#{issue["number"]})** • **[Share on socials](https://twitter.com/intent/tweet?text=%24#{amount}+bounty%21+%F0%9F%92%8E+#{issue["html_url"]}&related=algoraio)**
75-
76-
Attempt | Started (GMT+0) | Solution
77-
--------|----------------|----------
78-
"""
79-
80-
# Post comment to the issue
81-
with {:ok, %{"token" => token}} <-
82-
Github.get_installation_token(params["installation"]["id"]) do
83-
Github.create_issue_comment(
84-
token,
85-
repo["owner"]["login"],
86-
repo["name"],
87-
issue["number"],
88-
message
89-
)
90-
end
91-
92-
{:ok, amount}
55+
# Get repository and issue details from params
56+
repo = params["repository"]
57+
issue = params["issue"]
58+
59+
# Construct the bounty message
60+
message = """
61+
## 💎 $#{amount} bounty [• #{repo["owner"]["login"]}](https://console.algora.io/org/#{repo["owner"]["login"]})
62+
### Steps to solve:
63+
1. **Start working**: Comment `/attempt ##{issue["number"]}` with your implementation plan
64+
2. **Submit work**: Create a pull request including `/claim ##{issue["number"]}` in the PR body to claim the bounty
65+
3. **Receive payment**: 100% of the bounty is received 2-5 days post-reward. [Make sure you are eligible for payouts](https://docs.algora.io/bounties/payments#supported-countries-regions)
66+
67+
Thank you for contributing to #{repo["full_name"]}!
68+
69+
**[Add a bounty](https://console.algora.io/org/#{repo["owner"]["login"]}/bounties/community?fund=#{repo["full_name"]}%23#{issue["number"]})** • **[Share on socials](https://twitter.com/intent/tweet?text=%24#{amount}+bounty%21+%F0%9F%92%8E+#{issue["html_url"]}&related=algoraio)**
70+
71+
Attempt | Started (GMT+0) | Solution
72+
--------|----------------|----------
73+
"""
74+
75+
# Post comment to the issue
76+
with {:ok, %{"token" => token}} <-
77+
Github.get_installation_token(params["installation"]["id"]) do
78+
Github.create_issue_comment(
79+
token,
80+
repo["owner"]["login"],
81+
repo["name"],
82+
issue["number"],
83+
message
84+
)
9385
end
9486

87+
{:ok, amount}
88+
9589
{:ok, _permission} ->
9690
{:error, :unauthorized}
9791

test/algora_web/controllers/webhooks/github_controller_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ defmodule AlgoraWeb.Webhooks.GithubControllerTest do
2929

3030
@tag user: @unauthorized_user
3131
test "handles bounty command with unauthorized user", %{user: user} do
32-
assert [error: :unauthorized] == process_bounty_command("/bounty", user)
32+
assert [error: :unauthorized] == process_bounty_command("/bounty $100", user)
3333
end
3434

3535
test "handles bounty command without amount" do
36-
assert [ok: :open_to_bids] == process_bounty_command("/bounty")
36+
assert [] == process_bounty_command("/bounty")
3737
end
3838

3939
test "handles valid bounty command with $ prefix" do

0 commit comments

Comments
 (0)