Skip to content

Commit 3100054

Browse files
authored
fix: add missing title to ntfy provider (#1955)
1 parent 7837c65 commit 3100054

File tree

7 files changed

+25
-6
lines changed

7 files changed

+25
-6
lines changed

backend/internal/models/notification.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ type NtfyConfig struct {
142142
Topic string `json:"topic"`
143143
Username string `json:"username,omitempty"`
144144
Password string `json:"password,omitempty"` //nolint:gosec // JSON schema compatibility with external provider config
145+
Title string `json:"title,omitempty"`
145146
Priority string `json:"priority,omitempty"`
146147
Tags []string `json:"tags,omitempty"`
147148
Icon string `json:"icon,omitempty"`

backend/internal/services/notification_service.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3125,9 +3125,6 @@ func (s *NotificationService) sendNtfyPruneNotification(ctx context.Context, res
31253125
s.formatBytesInternal(result.VolumeSpaceReclaimed),
31263126
s.formatBytesInternal(result.BuildCacheSpaceReclaimed))
31273127

3128-
// Ntfy sends the title as part of the message or needs a separate header not currently in config
3129-
// For now, we omit the title attribute as it is not in the struct
3130-
31313128
return notifications.SendNtfy(ctx, ntfyConfig, message)
31323129
}
31333130

backend/internal/utils/notifications/ntfy_sender.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ func BuildNtfyURL(config models.NtfyConfig) (string, error) {
4747
// Add query parameters
4848
q := u.Query()
4949

50+
if config.Title != "" {
51+
q.Set("title", config.Title)
52+
}
53+
5054
if config.Priority != "" {
5155
q.Set("priority", config.Priority)
5256
}

backend/internal/utils/notifications/ntfy_sender_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,19 @@ func TestBuildNtfyURL(t *testing.T) {
7171
},
7272
},
7373
{
74-
name: "config with priority and tags",
74+
name: "config with title priority and tags",
7575
config: models.NtfyConfig{
7676
Host: "ntfy.sh",
7777
Topic: "alerts",
78+
Title: "Arcane Update",
7879
Priority: "high",
7980
Tags: []string{"warning", "server"},
8081
Cache: true,
8182
Firebase: true,
8283
},
8384
wantErr: false,
8485
check: func(url string) bool {
85-
return url == "ntfy://ntfy.sh/alerts?cache=yes&firebase=yes&priority=high&tags=warning%2Cserver"
86+
return url == "ntfy://ntfy.sh/alerts?cache=yes&firebase=yes&priority=high&tags=warning%2Cserver&title=Arcane+Update"
8687
},
8788
},
8889
{
@@ -100,6 +101,7 @@ func TestBuildNtfyURL(t *testing.T) {
100101
Topic: "test",
101102
Username: "user",
102103
Password: "pass",
104+
Title: "Arcane Alert",
103105
Priority: "max",
104106
Tags: []string{"urgent"},
105107
Icon: "https://example.com/icon.png",
@@ -109,7 +111,7 @@ func TestBuildNtfyURL(t *testing.T) {
109111
},
110112
wantErr: false,
111113
check: func(url string) bool {
112-
return url == "ntfy://user:pass@ntfy.example.com:8080/test?cache=no&disabletls=yes&firebase=no&icon=https%3A%2F%2Fexample.com%2Ficon.png&priority=max&tags=urgent"
114+
return url == "ntfy://user:pass@ntfy.example.com:8080/test?cache=no&disabletls=yes&firebase=no&icon=https%3A%2F%2Fexample.com%2Ficon.png&priority=max&tags=urgent&title=Arcane+Alert"
113115
},
114116
},
115117
}

frontend/messages/en.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,6 +1824,9 @@
18241824
"notifications_ntfy_password_help": "Password for authentication (if required by server)",
18251825
"notifications_ntfy_priority_label": "Priority",
18261826
"notifications_ntfy_priority_help": "Notification priority level (Min=1, Low=2, Default=3, High=4, Max/Urgent=5)",
1827+
"notifications_ntfy_title_label": "Title (Optional)",
1828+
"notifications_ntfy_title_placeholder": "Container Update",
1829+
"notifications_ntfy_title_help": "Optional title override for notifications",
18271830
"notifications_ntfy_tags_label": "Tags (Optional)",
18281831
"notifications_ntfy_tags_placeholder": "warning, server, docker",
18291832
"notifications_ntfy_tags_help": "Comma-separated list of tags (may map to emojis on supported clients)",

frontend/src/lib/types/notification-providers.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export interface NtfyFormValues extends BaseProviderFormValues {
7878
topic: string;
7979
username: string;
8080
password: string;
81+
title: string;
8182
priority: string;
8283
tags: string;
8384
icon: string;
@@ -402,6 +403,7 @@ export function ntfySettingsToFormValues(settings?: NotificationSettings): NtfyF
402403
topic: (cfg?.topic as string) || '',
403404
username: (cfg?.username as string) || '',
404405
password: (cfg?.password as string) || '',
406+
title: (cfg?.title as string) || '',
405407
priority: (cfg?.priority as string) || 'default',
406408
tags: Array.isArray(cfg?.tags) ? (cfg.tags as string[]).join(', ') : '',
407409
icon: (cfg?.icon as string) || '',
@@ -509,6 +511,7 @@ export function ntfyFormValuesToSettings(values: NtfyFormValues): NotificationSe
509511
topic: values.topic,
510512
username: values.username,
511513
password: values.password,
514+
title: values.title,
512515
priority: values.priority,
513516
tags: values.tags
514517
.split(',')

frontend/src/routes/(app)/settings/notifications/providers/BuiltInProviderForm.svelte

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@
277277
topic: z.string(),
278278
username: z.string(),
279279
password: z.string(),
280+
title: z.string(),
280281
priority: z.string(),
281282
tags: z.string(),
282283
icon: z.string(),
@@ -759,6 +760,14 @@
759760
helpText: m.notifications_ntfy_password_help(),
760761
inputType: 'password'
761762
},
763+
{
764+
kind: 'input',
765+
key: 'title',
766+
id: 'ntfy-title',
767+
label: m.notifications_ntfy_title_label(),
768+
placeholder: m.notifications_ntfy_title_placeholder(),
769+
helpText: m.notifications_ntfy_title_help()
770+
},
762771
{
763772
kind: 'native-select',
764773
key: 'priority',

0 commit comments

Comments
 (0)