From 65eab4fa742be06386dd26f356ed8d5ebd79674c Mon Sep 17 00:00:00 2001 From: michaeljguarino Date: Tue, 17 Sep 2024 13:26:34 -0400 Subject: [PATCH] Handle empty strings in string pr automation context (#1393) --- lib/console/deployments/pr/validation.ex | 2 +- test/console/deployments/git_test.exs | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/console/deployments/pr/validation.ex b/lib/console/deployments/pr/validation.ex index 2983a6b9f..ee70a4304 100644 --- a/lib/console/deployments/pr/validation.ex +++ b/lib/console/deployments/pr/validation.ex @@ -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 diff --git a/test/console/deployments/git_test.exs b/test/console/deployments/git_test.exs index 21f74c9f6..28ee38558 100644 --- a/test/console/deployments/git_test.exs +++ b/test/console/deployments/git_test.exs @@ -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("console@plural.sh")