Skip to content

Commit b56bb17

Browse files
feat(notifications): Support for tags (#591)
## 📝 Description Feature branch for: #369 #### `notifications` - refresh protos - implement the updated API semaphoreci/api#39 (this API is also used by `front`) - adds the filtering by tag rule if `git_ref_type == :TAG` so both branch and tag rules can be defined in same notification #### `front` - refreshes protos - adds tag field in notifications form <img width="416" height="164" alt="image" src="https://github.com/user-attachments/assets/8d892f05-936b-4a32-9d62-716d81f32c13" /> #### `public-api-gateway` Refreshes protos in to add support for tags in notifications. ## ✅ Checklist - [x] I have tested this change - [x] This change requires documentation update
1 parent 71d9773 commit b56bb17

File tree

39 files changed

+1319
-480
lines changed

39 files changed

+1319
-480
lines changed

front/assets/js/edit_notification.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ export var EditNotification = {
4545
<p class="f6 mt1 mb0 nb1">Comma separated, regular expressions allowed</p>
4646
</div>
4747
48+
<div class="pl4 mb3">
49+
<label for="tags" class="db b mb1">
50+
Tags
51+
<span class="f6 normal gray"> · optional</span>
52+
</label>
53+
<input id="tags" name="rule_${rule_hash}[tags]" type="text"
54+
class="form-control w-100"
55+
placeholder="e.g. v1.0.0, /^v\\\\d+\\\\.\\\\d+\\\\.\\\\d+$/, release-*" >
56+
<p class="f6 mt1 mb0 nb1">Comma separated, regular expressions allowed</p>
57+
</div>
58+
4859
<div class="pl4 mb3">
4960
<label for="pipelines" class="db b mb1">
5061
Pipelines

front/lib/front/models/notification.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ defmodule Front.Models.Notification do
128128
pipelines: data.pipelines,
129129
projects: data.projects,
130130
branches: data.branches,
131-
results: data.results
131+
results: data.results,
132+
tags: data.tags || []
132133
),
133134
name: data.rule_name,
134135
notify:

front/lib/front_web/controllers/notifications_controller.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ defmodule FrontWeb.NotificationsController do
342342
blocks: params["blocks"] |> parse_entry,
343343
pipelines: params["pipelines"] |> parse_entry,
344344
results: params["results"] |> parse_entry,
345+
tags: params["tags"] |> parse_entry,
345346
rule_name: params["name"],
346347
slack_channels: params["slack_channels"] |> parse_entry,
347348
slack_endpoint: params["slack_endpoint"],
@@ -373,7 +374,8 @@ defmodule FrontWeb.NotificationsController do
373374
pipelines: [],
374375
projects: [],
375376
results: [],
376-
states: []
377+
states: [],
378+
tags: []
377379
},
378380
name: "",
379381
notify: %Notification.Spec.Rule.Notify{

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
<td class="pr3">Branches</td>
2121
<td><%= rule.filter.branches |> Enum.join(", ") %></td>
2222
</tr>
23+
<tr class="v-top">
24+
<td class="pr3">Tags</td>
25+
<td><%= rule.filter.tags |> Enum.join(", ") %></td>
26+
</tr>
2327
<tr class="v-top">
2428
<td class="pr3">Pipelines</td>
2529
<td><%= rule.filter.pipelines |> Enum.join(", ") %></td>

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,18 @@
6666
placeholder: "e.g. master, /prod-*/, /.*/" %>
6767
<p class="f6 mt1 mb0 nb1">Comma separated, regular expressions allowed</p>
6868
</div>
69+
<div class="mb3 pl4">
70+
<label class="db b mb1">
71+
Tags
72+
<span class="f6 normal gray"> · optional</span>
73+
</label>
74+
<%= text_input f, :tags,
75+
name: "rule_#{rule_hash}[tags]",
76+
value: rule.filter.tags |> Enum.join(", "),
77+
class: "form-control w-100",
78+
placeholder: "e.g. v1.0.0, /^v\\d+\\.\\d+\\.\\d+$/, release-*" %>
79+
<p class="f6 mt1 mb0 nb1">Comma separated, regular expressions allowed</p>
80+
</div>
6981
<div class="mb3 pl4">
7082
<label class="db b mb1">
7183
Pipelines

front/lib/public_api/semaphore/notifications.v1alpha.pb.ex

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,10 @@ defmodule Semaphore.Notifications.V1alpha.Notification.Spec.Rule.Filter do
7272
pipelines: [String.t()],
7373
blocks: [String.t()],
7474
states: [integer],
75-
results: [String.t()]
75+
results: [String.t()],
76+
tags: [String.t()]
7677
}
77-
defstruct [:projects, :branches, :pipelines, :blocks, :states, :results]
78+
defstruct [:projects, :branches, :pipelines, :blocks, :states, :results, :tags]
7879

7980
field(:projects, 1, repeated: true, type: :string)
8081
field(:branches, 2, repeated: true, type: :string)
@@ -88,6 +89,7 @@ defmodule Semaphore.Notifications.V1alpha.Notification.Spec.Rule.Filter do
8889
)
8990

9091
field(:results, 6, repeated: true, type: :string)
92+
field(:tags, 7, repeated: true, type: :string)
9193
end
9294

9395
defmodule Semaphore.Notifications.V1alpha.Notification.Spec.Rule.Filter.State do

front/test/support/stubs/notification.ex

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,15 @@ defmodule Support.Stubs.Notification do
133133
def create_notification(notification, call) do
134134
{org_id, _} = call |> extract_headers
135135

136+
notification =
137+
if notification.metadata.id == "" do
138+
id = UUID.gen()
139+
metadata = %{notification.metadata | id: id}
140+
%{notification | metadata: metadata}
141+
else
142+
notification
143+
end
144+
136145
DB.insert(:notifications, %{
137146
id: notification.metadata.id,
138147
org_id: org_id,
@@ -146,10 +155,19 @@ defmodule Support.Stubs.Notification do
146155
def update_notification(req, call) do
147156
case find(req, call) do
148157
{:ok, notification} ->
158+
# Ensure the notification has the correct ID in metadata
159+
updated_notification =
160+
if req.notification.metadata.id == "" do
161+
metadata = %{req.notification.metadata | id: notification.id}
162+
%{req.notification | metadata: metadata}
163+
else
164+
req.notification
165+
end
166+
149167
new_notification = %{
150-
id: req.notification.metadata.id,
151-
name: req.notification.metadata.name,
152-
api_model: req.notification,
168+
id: notification.id,
169+
name: updated_notification.metadata.name,
170+
api_model: updated_notification,
153171
org_id: notification.org_id
154172
}
155173

notifications/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ include ../Makefile
44

55
APP_NAME=$(shell grep 'app:' mix.exs | cut -d ':' -f3 | cut -d ',' -f1)
66
PROTOC_TAG=1.12.1-3.17.3-0.7.1
7-
TMP_REPO_DIR=/tmp/internal_api
7+
TMP_REPO_DIR ?= /tmp/internal_api
88

99
INTERNAL_API_BRANCH ?= master
1010
PUBLIC_API_BRANCH ?= master

notifications/lib/internal_api/notifications.pb.ex

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ defmodule InternalApi.Notifications.Notification.Rule.Filter do
6565
pipelines: [String.t()],
6666
blocks: [String.t()],
6767
states: [[InternalApi.Notifications.Notification.Rule.Filter.State.t()]],
68-
results: [[InternalApi.Notifications.Notification.Rule.Filter.Results.t()]]
68+
results: [[InternalApi.Notifications.Notification.Rule.Filter.Results.t()]],
69+
tags: [String.t()]
6970
}
7071

71-
defstruct [:projects, :branches, :pipelines, :blocks, :states, :results]
72+
defstruct [:projects, :branches, :pipelines, :blocks, :states, :results, :tags]
7273

7374
field(:projects, 1, repeated: true, type: :string)
7475
field(:branches, 2, repeated: true, type: :string)
@@ -86,6 +87,8 @@ defmodule InternalApi.Notifications.Notification.Rule.Filter do
8687
type: InternalApi.Notifications.Notification.Rule.Filter.Results,
8788
enum: true
8889
)
90+
91+
field(:tags, 7, repeated: true, type: :string)
8992
end
9093

9194
defmodule InternalApi.Notifications.Notification.Rule.Notify.Slack do
@@ -224,10 +227,11 @@ defmodule InternalApi.Notifications.Notification do
224227
update_time: Google.Protobuf.Timestamp.t() | nil,
225228
rules: [InternalApi.Notifications.Notification.Rule.t()],
226229
status: InternalApi.Notifications.Notification.Status.t() | nil,
227-
org_id: String.t()
230+
org_id: String.t(),
231+
creator_id: String.t()
228232
}
229233

230-
defstruct [:name, :id, :create_time, :update_time, :rules, :status, :org_id]
234+
defstruct [:name, :id, :create_time, :update_time, :rules, :status, :org_id, :creator_id]
231235

232236
field(:name, 1, type: :string)
233237
field(:id, 2, type: :string)
@@ -236,6 +240,7 @@ defmodule InternalApi.Notifications.Notification do
236240
field(:rules, 5, repeated: true, type: InternalApi.Notifications.Notification.Rule)
237241
field(:status, 6, type: InternalApi.Notifications.Notification.Status)
238242
field(:org_id, 7, type: :string)
243+
field(:creator_id, 8, type: :string)
239244
end
240245

241246
defmodule InternalApi.Notifications.ListRequest do

0 commit comments

Comments
 (0)