Skip to content

Commit fb4d9cb

Browse files
Merge branch 'main' into feat/service-accounts
2 parents 5813d26 + 0ca22a0 commit fb4d9cb

File tree

7 files changed

+72
-12
lines changed

7 files changed

+72
-12
lines changed

front/assets/js/edit_notification.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ export var EditNotification = {
2929
class="form-control w-100"
3030
placeholder="e.g. my-project, /hotfix-*/, /.*/" >
3131
<p class="f6 mt1 mb0 nb1">Comma separated, regular expressions allowed</p>
32+
<p class="f6 mt2 pa2 bg-washed-yellow ba b--yellow br2">
33+
<strong>Note:</strong> Regardless of the regex patterns specified, notifications will only be sent for projects to which the creator of this notification has access.
34+
</p>
3235
</div>
3336
3437
<div class="pl4 mb3">

front/lib/front_web/controllers/notifications_controller.ex

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ defmodule FrontWeb.NotificationsController do
44

55
alias Front.Async
66
alias Front.Audit
7-
8-
alias Front.Models.{
9-
Notification,
10-
Organization
11-
}
7+
alias Front.Models.{Notification, Organization, User}
128

139
plug(FrontWeb.Plugs.FetchPermissions, scope: "org")
1410
plug(FrontWeb.Plugs.PageAccess, permissions: "organization.view")
@@ -25,6 +21,7 @@ defmodule FrontWeb.NotificationsController do
2521

2622
{:ok, organization} = Async.await(fetch_organization)
2723
{:ok, notifications} = Async.await(fetch_notifications)
24+
notifications = add_user_data_to_notifications(notifications)
2825

2926
render(
3027
conn,
@@ -298,6 +295,27 @@ defmodule FrontWeb.NotificationsController do
298295
|> render("404.html")
299296
end
300297

298+
defp add_user_data_to_notifications(notifications) when is_list(notifications) do
299+
import Enum
300+
301+
creators =
302+
notifications
303+
|> map(& &1.metadata.creator_id)
304+
|> reject(&(&1 == ""))
305+
|> uniq()
306+
|> User.find_many()
307+
308+
map(notifications, fn n ->
309+
if n.metadata.creator_id != "" do
310+
default_username = Application.get_env(:front, :default_user_name)
311+
creator = find(creators, &(&1.id == n.metadata.creator_id)) || %{name: default_username}
312+
%{n | metadata: Map.put(n.metadata, :creator, creator)}
313+
else
314+
n
315+
end
316+
end)
317+
end
318+
301319
def get_rule_identifiers(params) do
302320
params
303321
|> Map.keys()

front/lib/front_web/templates/notifications/_notifications.html.eex

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
<%= Enum.map(@notifications, fn notification -> %>
22
<div class="bg-white shadow-1 br3 pa3 mv3">
3-
<div class="f4 f3-m b mb2"><%= notification.metadata.name %></div>
3+
<div class="flex items-center justify-between mb2">
4+
<div class="f4 f3-m b"><%= notification.metadata.name %></div>
5+
<%= if Map.has_key?(notification.metadata, :creator) && Map.has_key?(notification.metadata.creator, :name) do %>
6+
<div class="f6 black-50 tr">last modified by <%= notification.metadata.creator.name %></div>
7+
<% end %>
8+
</div>
49

510
<div class="overflow-auto nowrap">
611
<%= Enum.map(notification.spec.rules, fn rule -> %>

front/lib/front_web/templates/notifications/form.html.eex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
class: "form-control w-100",
5151
placeholder: "e.g. my-project, /hotfix-*/, /.*/" %>
5252
<p class="f6 mt1 mb0 nb1">Comma separated, regular expressions allowed</p>
53+
<p class="f6 mt2 pa2 bg-washed-yellow ba b--yellow br2">
54+
<strong>Note:</strong> Regardless of the regex patterns specified, notifications will only be sent for projects to which the creator of this notification has access.
55+
</p>
5356
</div>
5457
<div class="mb3 pl4">
5558
<label class="db b mb1">

notifications/lib/notifications/api/public_api/serialization.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ defmodule Notifications.Api.PublicApi.Serialization do
1515
Notification.Metadata.new(
1616
name: notification.name,
1717
id: notification.id,
18+
creator_id: notification.creator_id,
1819
create_time: unix_timestamp(notification.inserted_at),
1920
update_time: unix_timestamp(notification.updated_at)
2021
)

zebra/lib/zebra/workers/task_finisher.ex

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ defmodule Zebra.Workers.TaskFinisher do
6161
log(task.id, "Processing task, results #{inspect(results)}, states #{inspect(states)}")
6262

6363
if Enum.all?(states, fn s -> s == Job.state_finished() end) do
64-
case calculate_task_result(results) do
64+
case calculate_task_result(results, task) do
6565
{:ok, result} ->
6666
finish(task, jobs, result)
6767
publish(task)
@@ -92,8 +92,13 @@ defmodule Zebra.Workers.TaskFinisher do
9292
log(task.id, "marked as finished")
9393
end
9494

95-
def calculate_task_result(job_results) do
95+
def calculate_task_result(job_results, task) do
9696
cond do
97+
# If fail_fast:stop is active and there's a failure, show as failed
98+
task.fail_fast_strategy == "stop" &&
99+
Enum.any?(job_results, fn r -> r == Job.result_failed() end) ->
100+
{:ok, "failed"}
101+
97102
Enum.any?(job_results, fn r -> r == Job.result_stopped() end) ->
98103
{:ok, "stopped"}
99104

zebra/test/zebra/workers/task_finisher_test.exs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,45 @@ defmodule Zebra.Workers.TaskFinisherTest do
6060
describe ".calculate_task_result" do
6161
test "when any of the jobs are stopped => result is stopped" do
6262
results = ["passed", "failed", "stopped"]
63+
{:ok, task} = Support.Factories.Task.create()
6364

64-
assert {:ok, "stopped"} = W.calculate_task_result(results)
65+
assert {:ok, "stopped"} = W.calculate_task_result(results, task)
6566
end
6667

6768
test "when any of the jobs are failed => result is failed" do
6869
results = ["passed", "failed", "passed"]
70+
{:ok, task} = Support.Factories.Task.create()
6971

70-
assert {:ok, "failed"} = W.calculate_task_result(results)
72+
assert {:ok, "failed"} = W.calculate_task_result(results, task)
7173
end
7274

7375
test "when all of the jobs are passed => result is passed" do
74-
results = ["passed", "failed", "passed"]
76+
results = ["passed", "passed", "passed"]
77+
{:ok, task} = Support.Factories.Task.create()
78+
79+
assert {:ok, "passed"} = W.calculate_task_result(results, task)
80+
end
81+
82+
test "when fail_fast:stop is active and jobs are stopped due to failure => result is failed" do
83+
results = ["passed", "failed", "stopped", "stopped"]
84+
{:ok, task} = Support.Factories.Task.create(%{fail_fast_strategy: "stop"})
85+
86+
assert {:ok, "failed"} = W.calculate_task_result(results, task)
87+
end
88+
89+
test "when fail_fast:stop is active but no jobs failed => result is stopped" do
90+
results = ["passed", "stopped", "stopped"]
91+
{:ok, task} = Support.Factories.Task.create(%{fail_fast_strategy: "stop"})
92+
93+
assert {:ok, "stopped"} = W.calculate_task_result(results, task)
94+
end
95+
96+
test "when fail_fast:cancel is active and jobs are stopped due to failure => result is stopped" do
97+
results = ["passed", "failed", "stopped"]
98+
{:ok, task} = Support.Factories.Task.create(%{fail_fast_strategy: "cancel"})
7599

76-
assert {:ok, "failed"} = W.calculate_task_result(results)
100+
# With cancel strategy, we don't override the normal logic
101+
assert {:ok, "stopped"} = W.calculate_task_result(results, task)
77102
end
78103
end
79104

0 commit comments

Comments
 (0)