Skip to content

Commit 6297514

Browse files
committed
refactor: Github.Command
1 parent 7ad9c47 commit 6297514

File tree

1 file changed

+20
-31
lines changed

1 file changed

+20
-31
lines changed

lib/algora/integrations/github/command.ex

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,14 @@ defmodule Algora.Github.Command do
1313
attempt: "/attempt <issue-ref> (e.g. #123, repo#123, owner/repo#123, or full GitHub URL)"
1414
}
1515

16-
def commands do
17-
repeat(
18-
choice([
19-
# Any text that is not a command
20-
[not: ?/] |> utf8_string(min: 1) |> ignore(),
21-
22-
# Known command
23-
choice([
24-
bounty_command(),
25-
tip_command(),
26-
claim_command(),
27-
split_command(),
28-
attempt_command()
29-
]),
30-
31-
# Unknown command
32-
"/"
33-
|> string()
34-
|> ignore()
35-
|> concat(utf8_string([?a..?z, ?A..?Z, ?_, ?-], min: 1))
36-
|> ignore()
37-
])
38-
)
16+
def command do
17+
choice([
18+
bounty_command(),
19+
tip_command(),
20+
claim_command(),
21+
split_command(),
22+
attempt_command()
23+
])
3924
end
4025

4126
def bounty_command do
@@ -91,6 +76,16 @@ defmodule Algora.Github.Command do
9176
|> tag(:attempt)
9277
|> label(@usage.attempt)
9378
end
79+
80+
def commands do
81+
repeat(
82+
choice([
83+
ignore(utf8_string([not: ?/], min: 1)),
84+
command(),
85+
ignore(string("/"))
86+
])
87+
)
88+
end
9489
end
9590

9691
defparsec(:parse_raw, Helper.commands())
@@ -99,14 +94,8 @@ defmodule Algora.Github.Command do
9994

10095
def parse(input) when is_binary(input) do
10196
case parse_raw(input) do
102-
{:ok, parsed, _, _, _, _} ->
103-
{:ok, Enum.reject(parsed, &is_nil/1)}
104-
105-
{:error, reason, _, _, _, _} ->
106-
{:error, reason}
97+
{:ok, parsed, _, _, _, _} -> {:ok, Enum.reject(parsed, &is_nil/1)}
98+
{:error, reason, _, _, _, _} -> {:error, reason}
10799
end
108-
rescue
109-
ArgumentError ->
110-
{:error, "Failed to parse commands"}
111100
end
112101
end

0 commit comments

Comments
 (0)