Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion lib/dispatch/dispatch.ex
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ defmodule Dispatch do
@doc """
Extracts stacks from a Webhook payload received from GitHub
"""
def extract_from_params(%{"pull_request" => %{"body" => body}, "stacks" => default_stacks}) when is_binary(default_stacks) do
def extract_from_params(%{"pull_request" => %{"body" => body}} = params) do
default_stacks = Map.get(params, "stacks", "")

~r/#dispatch\/(\w+)/i
|> Regex.scan(body, capture: :all_but_first)
|> (fn
Expand Down
14 changes: 14 additions & 0 deletions test/dispatch/dispatch_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,18 @@ defmodule DispatchTest do

assert stacks == ["hcl", "ruby"]
end

test "extract_from_params/1 with stacks in pull request body but no default ones, it should return them" do
body = """
This is my pull request! It adds a Terraform configuration file. Absolutely no GraphQL stuff to review.

Also, there are no default stacks in the webhook URL.

#dispatch/hcl #dispatch/Ruby
"""

stacks = Dispatch.extract_from_params(%{"pull_request" => %{"body" => body}})

assert stacks == ["hcl", "ruby"]
end
end