Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 20 additions & 31 deletions lib/algora/integrations/github/command.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,14 @@ defmodule Algora.Github.Command do
attempt: "/attempt <issue-ref> (e.g. #123, repo#123, owner/repo#123, or full GitHub URL)"
}

def commands do
repeat(
choice([
# Any text that is not a command
[not: ?/] |> utf8_string(min: 1) |> ignore(),

# Known command
choice([
bounty_command(),
tip_command(),
claim_command(),
split_command(),
attempt_command()
]),

# Unknown command
"/"
|> string()
|> ignore()
|> concat(utf8_string([?a..?z, ?A..?Z, ?_, ?-], min: 1))
|> ignore()
])
)
def command do
choice([
bounty_command(),
tip_command(),
claim_command(),
split_command(),
attempt_command()
])
end

def bounty_command do
Expand Down Expand Up @@ -91,6 +76,16 @@ defmodule Algora.Github.Command do
|> tag(:attempt)
|> label(@usage.attempt)
end

def commands do
repeat(
choice([
ignore(utf8_string([not: ?/], min: 1)),
command(),
ignore(string("/"))
])
)
end
end

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

def parse(input) when is_binary(input) do
case parse_raw(input) do
{:ok, parsed, _, _, _, _} ->
{:ok, Enum.reject(parsed, &is_nil/1)}

{:error, reason, _, _, _, _} ->
{:error, reason}
{:ok, parsed, _, _, _, _} -> {:ok, Enum.reject(parsed, &is_nil/1)}
{:error, reason, _, _, _, _} -> {:error, reason}
end
rescue
ArgumentError ->
{:error, "Failed to parse commands"}
end
end
Loading