feat(gotify): added priority input for gotify (#1410)

* feat(gotify notification): added priority input for gotify

Added priority field for gotify messages on the gotify settings page

issue 562

* feat(gotify notification): added requested changes

fixed json end of file new line, removed unused code, added default priority for previous
configurations

* feat(gotify notifcation): fixed cypress/config/settings.cypress.json

fixed cypress/config/settings.cypress.json

* Update cypress/config/settings.cypress.json

Removed extra line from settings.cypress.json

Co-authored-by: Gauthier <mail@gauthierth.fr>

---------

Co-authored-by: Gauthier <mail@gauthierth.fr>
This commit is contained in:
Nathan Lemmon
2025-04-06 09:49:43 -05:00
committed by GitHub
parent 5a6ff61f64
commit 21400cecdc
5 changed files with 52 additions and 7 deletions

View File

@@ -138,7 +138,8 @@
"types": 0, "types": 0,
"options": { "options": {
"url": "", "url": "",
"token": "" "token": "",
"priority": 0
} }
} }
} }

View File

@@ -30,7 +30,12 @@ class GotifyAgent
public shouldSend(): boolean { public shouldSend(): boolean {
const settings = this.getSettings(); const settings = this.getSettings();
if (settings.enabled && settings.options.url && settings.options.token) { if (
settings.enabled &&
settings.options.url &&
settings.options.token &&
settings.options.priority
) {
return true; return true;
} }
@@ -42,7 +47,8 @@ class GotifyAgent
payload: NotificationPayload payload: NotificationPayload
): GotifyPayload { ): GotifyPayload {
const { applicationUrl, applicationTitle } = getSettings().main; const { applicationUrl, applicationTitle } = getSettings().main;
let priority = 0; const settings = this.getSettings();
const priority = settings.options.priority ?? 1;
const title = payload.event const title = payload.event
? `${payload.event} - ${payload.subject}` ? `${payload.event} - ${payload.subject}`
@@ -86,10 +92,6 @@ class GotifyAgent
message += `\n**Issue Status:** ${ message += `\n**Issue Status:** ${
payload.issue.status === IssueStatus.OPEN ? 'Open' : 'Resolved' payload.issue.status === IssueStatus.OPEN ? 'Open' : 'Resolved'
} `; } `;
if (type == Notification.ISSUE_CREATED) {
priority = 1;
}
} }
for (const extra of payload.extra ?? []) { for (const extra of payload.extra ?? []) {

View File

@@ -254,6 +254,7 @@ export interface NotificationAgentGotify extends NotificationAgentConfig {
options: { options: {
url: string; url: string;
token: string; token: string;
priority: number;
}; };
} }
@@ -463,6 +464,7 @@ class Settings {
options: { options: {
url: '', url: '',
token: '', token: '',
priority: 0,
}, },
}, },
}, },

View File

@@ -17,9 +17,11 @@ const messages = defineMessages(
agentenabled: 'Enable Agent', agentenabled: 'Enable Agent',
url: 'Server URL', url: 'Server URL',
token: 'Application Token', token: 'Application Token',
priority: 'Priority',
validationUrlRequired: 'You must provide a valid URL', validationUrlRequired: 'You must provide a valid URL',
validationUrlTrailingSlash: 'URL must not end in a trailing slash', validationUrlTrailingSlash: 'URL must not end in a trailing slash',
validationTokenRequired: 'You must provide an application token', validationTokenRequired: 'You must provide an application token',
validationPriorityRequired: 'You must set a priority number',
gotifysettingssaved: 'Gotify notification settings saved successfully!', gotifysettingssaved: 'Gotify notification settings saved successfully!',
gotifysettingsfailed: 'Gotify notification settings failed to save.', gotifysettingsfailed: 'Gotify notification settings failed to save.',
toastGotifyTestSending: 'Sending Gotify test notification…', toastGotifyTestSending: 'Sending Gotify test notification…',
@@ -65,6 +67,15 @@ const NotificationsGotify = () => {
.required(intl.formatMessage(messages.validationTokenRequired)), .required(intl.formatMessage(messages.validationTokenRequired)),
otherwise: Yup.string().nullable(), otherwise: Yup.string().nullable(),
}), }),
priority: Yup.string().when('enabled', {
is: true,
then: Yup.string()
.nullable()
.min(0)
.max(9)
.required(intl.formatMessage(messages.validationPriorityRequired)),
otherwise: Yup.string().nullable(),
}),
}); });
if (!data && !error) { if (!data && !error) {
@@ -78,6 +89,7 @@ const NotificationsGotify = () => {
types: data?.types, types: data?.types,
url: data?.options.url, url: data?.options.url,
token: data?.options.token, token: data?.options.token,
priority: data?.options.priority,
}} }}
validationSchema={NotificationsGotifySchema} validationSchema={NotificationsGotifySchema}
onSubmit={async (values) => { onSubmit={async (values) => {
@@ -93,6 +105,7 @@ const NotificationsGotify = () => {
options: { options: {
url: values.url, url: values.url,
token: values.token, token: values.token,
priority: Number(values.priority),
}, },
}), }),
}); });
@@ -147,6 +160,7 @@ const NotificationsGotify = () => {
options: { options: {
url: values.url, url: values.url,
token: values.token, token: values.token,
priority: Number(values.priority),
}, },
}), }),
} }
@@ -216,6 +230,30 @@ const NotificationsGotify = () => {
)} )}
</div> </div>
</div> </div>
<div className="form-row">
<label htmlFor="priority" className="text-label">
{intl.formatMessage(messages.priority)}
<span className="label-required">*</span>
</label>
<div className="form-input-area">
<Field
id="priority"
name="priority"
type="text"
inputMode="numeric"
className="short"
autoComplete="off"
data-1pignore="true"
data-lpignore="true"
data-bwignore="true"
/>
{errors.priority &&
touched.priority &&
typeof errors.priority === 'string' && (
<div className="error">{errors.priority}</div>
)}
</div>
</div>
<NotificationTypeSelector <NotificationTypeSelector
currentTypes={values.enabled ? values.types : 0} currentTypes={values.enabled ? values.types : 0}
onUpdate={(newTypes) => { onUpdate={(newTypes) => {

View File

@@ -598,11 +598,13 @@
"components.Settings.Notifications.NotificationsGotify.agentenabled": "Enable Agent", "components.Settings.Notifications.NotificationsGotify.agentenabled": "Enable Agent",
"components.Settings.Notifications.NotificationsGotify.gotifysettingsfailed": "Gotify notification settings failed to save.", "components.Settings.Notifications.NotificationsGotify.gotifysettingsfailed": "Gotify notification settings failed to save.",
"components.Settings.Notifications.NotificationsGotify.gotifysettingssaved": "Gotify notification settings saved successfully!", "components.Settings.Notifications.NotificationsGotify.gotifysettingssaved": "Gotify notification settings saved successfully!",
"components.Settings.Notifications.NotificationsGotify.priority": "Priority",
"components.Settings.Notifications.NotificationsGotify.toastGotifyTestFailed": "Gotify test notification failed to send.", "components.Settings.Notifications.NotificationsGotify.toastGotifyTestFailed": "Gotify test notification failed to send.",
"components.Settings.Notifications.NotificationsGotify.toastGotifyTestSending": "Sending Gotify test notification…", "components.Settings.Notifications.NotificationsGotify.toastGotifyTestSending": "Sending Gotify test notification…",
"components.Settings.Notifications.NotificationsGotify.toastGotifyTestSuccess": "Gotify test notification sent!", "components.Settings.Notifications.NotificationsGotify.toastGotifyTestSuccess": "Gotify test notification sent!",
"components.Settings.Notifications.NotificationsGotify.token": "Application Token", "components.Settings.Notifications.NotificationsGotify.token": "Application Token",
"components.Settings.Notifications.NotificationsGotify.url": "Server URL", "components.Settings.Notifications.NotificationsGotify.url": "Server URL",
"components.Settings.Notifications.NotificationsGotify.validationPriorityRequired": "You must set a priority number",
"components.Settings.Notifications.NotificationsGotify.validationTokenRequired": "You must provide an application token", "components.Settings.Notifications.NotificationsGotify.validationTokenRequired": "You must provide an application token",
"components.Settings.Notifications.NotificationsGotify.validationTypes": "You must select at least one notification type", "components.Settings.Notifications.NotificationsGotify.validationTypes": "You must select at least one notification type",
"components.Settings.Notifications.NotificationsGotify.validationUrlRequired": "You must provide a valid URL", "components.Settings.Notifications.NotificationsGotify.validationUrlRequired": "You must provide a valid URL",