Skip to content

Commit

Permalink
Handle empty strings in string pr automation context (#1393)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljguarino authored Sep 17, 2024
1 parent 67729b1 commit 65eab4f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/console/deployments/pr/validation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ defmodule Console.Deployments.Pr.Validation do
end
end

defp do_validate(%Configuration{type: :string}, val) when is_binary(val), do: :ok
defp do_validate(%Configuration{type: :string}, val) when is_binary(val) and byte_size(val) > 0, do: :ok
defp do_validate(%Configuration{type: t}, val),
do: {:error, "value #{inspect(val)} does not match type #{String.upcase(to_string(t))}"}
end
22 changes: 22 additions & 0 deletions test/console/deployments/git_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,28 @@ defmodule Console.Deployments.GitTest do
assert err =~ "does not match regex"
end

test "it will reject a pull request w/ empty string configs" do
user = insert(:user)
conn = insert(:scm_connection, token: "some-pat")
pra = insert(:pr_automation,
identifier: "pluralsh/console",
cluster: build(:cluster),
connection: conn,
updates: %{regexes: ["regex"], match_strategy: :any, files: ["file.yaml"], replace_template: "replace"},
write_bindings: [%{user_id: user.id}],
create_bindings: [%{user_id: user.id}],
configuration: [
%{name: "first", type: :int},
%{name: "second", type: :string}
]
)

{:error, _} = Git.create_pull_request(%{
"first" => 10,
"second" => ""
}, pra.id, "pr-test", user)
end

test "it can create a pull request with a github app" do
user = insert(:user)
{:ok, pem_string, _} = Console.keypair("[email protected]")
Expand Down

0 comments on commit 65eab4f

Please sign in to comment.