Skip to content

Commit f4695ea

Browse files
Add additional promote tags to test objects (#778)
1 parent 958f88a commit f4695ea

File tree

6 files changed

+42
-14
lines changed

6 files changed

+42
-14
lines changed

apps/core/lib/core/schema/test.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ defmodule Core.Schema.Test do
1010
field :name, :string
1111
field :source_tag, :string
1212
field :promote_tag, :string
13+
field :tags, {:array, :string}
1314
field :status, Status
1415

1516
belongs_to :repository, Repository
@@ -41,7 +42,7 @@ defmodule Core.Schema.Test do
4142
from(t in query, order_by: ^order)
4243
end
4344

44-
@valid ~w(name source_tag promote_tag status repository_id creator_id)a
45+
@valid ~w(name source_tag promote_tag status repository_id creator_id tags)a
4546

4647
def changeset(model, attrs \\ %{}) do
4748
model

apps/core/lib/core/services/tests.ex

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ defmodule Core.Services.Tests do
66
User,
77
Test,
88
TestStep,
9-
Version
9+
Version,
10+
VersionTag
1011
}
1112
alias Core.Services.{Versions, Repositories}
1213

@@ -80,11 +81,13 @@ defmodule Core.Services.Tests do
8081

8182
bindings
8283
|> Enum.reduce(start_transaction(), fn %{version: version}, tx ->
83-
add_operation(tx, version.id, fn _ ->
84-
case compare_vsn(version, tag) do
85-
:gt -> Versions.create_tag(version, tag)
86-
_ -> {:ok, :ignore}
87-
end
84+
Enum.reduce([tag | (test.tags || [])], tx, fn tag, tx ->
85+
add_operation(tx, {tag, version.id}, fn _ ->
86+
case compare_vsn(version, tag) do
87+
:gt -> Versions.create_tag(version, tag)
88+
_ -> {:ok, :ignore}
89+
end
90+
end)
8891
end)
8992
end)
9093
|> execute()
@@ -144,12 +147,12 @@ defmodule Core.Services.Tests do
144147
end
145148

146149
defp send_notifs(results, user) do
147-
Enum.map(results, fn
148-
{k, :ignore} -> {k, :ignore}
149-
{k, vt} ->
150-
%{version: vsn} = Core.Repo.preload(vt, [:version])
151-
{:ok, _} = Versions.notify({:ok, vsn}, :update, user)
152-
{k, vsn}
150+
Enum.filter(results, fn {_, v} -> v != :ignore end)
151+
|> Enum.uniq_by(fn {_, %VersionTag{version_id: v}} -> v end)
152+
|> Enum.map(fn {{_, k}, vt} ->
153+
%{version: vsn} = Core.Repo.preload(vt, [:version])
154+
{:ok, _} = Versions.notify({:ok, vsn}, :update, user)
155+
{k, vsn}
153156
end)
154157
|> Enum.into(%{})
155158
|> ok()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
defmodule Core.Repo.Migrations.AddTestPromoteTags do
2+
use Ecto.Migration
3+
4+
def change do
5+
alter table(:tests) do
6+
add :tags, {:array, :string}
7+
end
8+
end
9+
end

apps/core/test/services/tests_test.exs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,19 @@ defmodule Core.Services.TestsTest do
105105
assert_receive {:event, %PubSub.VersionUpdated{item: %{id: ^id}}}
106106
end
107107
end
108+
109+
test "it can also promote associated tags" do
110+
test = insert(:test, status: :succeeded, promote_tag: "stable", tags: ["0.3.0"])
111+
bindings = insert_list(3, :test_binding, test: test)
112+
113+
{:ok, _} = Tests.promote(test)
114+
115+
for %{version: %{id: id} = version} <- bindings do
116+
assert Versions.get_tag(:helm, version.chart_id, "stable").version_id == id
117+
assert Versions.get_tag(:helm, version.chart_id, "0.3.0").version_id == id
118+
assert_receive {:event, %PubSub.VersionUpdated{item: %{id: ^id}}}
119+
end
120+
end
108121
end
109122

110123
describe "#expire/1" do

apps/graphql/lib/graphql/schema/test.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ defmodule GraphQl.Schema.Test do
1212
field :name, :string
1313
field :status, :test_status
1414
field :promote_tag, :string
15+
field :tags, list_of(:string)
1516
field :steps, list_of(:test_step_attributes)
1617
end
1718

@@ -29,6 +30,7 @@ defmodule GraphQl.Schema.Test do
2930
field :status, non_null(:test_status)
3031
field :source_tag, non_null(:string)
3132
field :promote_tag, non_null(:string)
33+
field :tags, list_of(non_null(:string))
3234
field :steps, list_of(:test_step), resolve: dataloader(Test)
3335
field :creator, :user, resolve: dataloader(User)
3436
field :repository, :repository, resolve: dataloader(Repository)

mix.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
"stripity_stripe": {:hex, :stripity_stripe, "2.17.2", "6e4c5f0b2deb3d3411f91e23fedbe9db4c031a52dfeb7074b4df4fdd22ad32cd", [:mix], [{:hackney, "~> 1.15", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: true]}, {:uri_query, "~> 0.1.2", [hex: :uri_query, repo: "hexpm", optional: false]}], "hexpm", "42bffb591d34f3cfa95cb37e862140e44a61ca4c64578bf7bb591ba60c6a66bc"},
138138
"swarm": {:hex, :swarm, "3.4.0", "64f8b30055d74640d2186c66354b33b999438692a91be275bb89cdc7e401f448", [:mix], [{:gen_state_machine, "~> 2.0", [hex: :gen_state_machine, repo: "hexpm", optional: false]}, {:libring, "~> 1.0", [hex: :libring, repo: "hexpm", optional: false]}], "hexpm", "94884f84783fc1ba027aba8fe8a7dae4aad78c98e9f9c76667ec3471585c08c6"},
139139
"sweet_xml": {:hex, :sweet_xml, "0.7.3", "debb256781c75ff6a8c5cbf7981146312b66f044a2898f453709a53e5031b45b", [:mix], [], "hexpm", "e110c867a1b3fe74bfc7dd9893aa851f0eed5518d0d7cad76d7baafd30e4f5ba"},
140-
"telemetry": {:hex, :telemetry, "1.1.0", "a589817034a27eab11144ad24d5c0f9fab1f58173274b1e9bae7074af9cbee51", [], [], "hexpm", "b727b2a1f75614774cff2d7565b64d0dfa5bd52ba517f16543e6fc7efcc0df48"},
140+
"telemetry": {:hex, :telemetry, "1.1.0", "a589817034a27eab11144ad24d5c0f9fab1f58173274b1e9bae7074af9cbee51", [:rebar3], [], "hexpm", "b727b2a1f75614774cff2d7565b64d0dfa5bd52ba517f16543e6fc7efcc0df48"},
141141
"telemetry_metrics": {:hex, :telemetry_metrics, "0.6.1", "315d9163a1d4660aedc3fee73f33f1d355dcc76c5c3ab3d59e76e3edf80eef1f", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7be9e0871c41732c233be71e4be11b96e56177bf15dde64a8ac9ce72ac9834c6"},
142142
"telemetry_poller": {:hex, :telemetry_poller, "1.0.0", "db91bb424e07f2bb6e73926fcafbfcbcb295f0193e0a00e825e589a0a47e8453", [:rebar3], [{:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "b3a24eafd66c3f42da30fc3ca7dda1e9d546c12250a2d60d7b81d264fbec4f6e"},
143143
"tesla": {:hex, :tesla, "1.4.3", "f5a494e08fb1abe4fd9c28abb17f3d9b62b8f6fc492860baa91efb1aab61c8a0", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: true]}, {:exjsx, ">= 3.0.0", [hex: :exjsx, repo: "hexpm", optional: true]}, {:finch, "~> 0.3", [hex: :finch, repo: "hexpm", optional: true]}, {:fuse, "~> 2.4", [hex: :fuse, repo: "hexpm", optional: true]}, {:gun, "~> 1.3", [hex: :gun, repo: "hexpm", optional: true]}, {:hackney, "~> 1.6", [hex: :hackney, repo: "hexpm", optional: true]}, {:ibrowse, "4.4.0", [hex: :ibrowse, repo: "hexpm", optional: true]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.0", [hex: :mint, repo: "hexpm", optional: true]}, {:poison, ">= 1.0.0", [hex: :poison, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "e0755bb664bf4d664af72931f320c97adbf89da4586670f4864bf259b5750386"},

0 commit comments

Comments
 (0)