Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions services/tasks/TaskRunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ type TaskRunner struct {
Alias string

logWG sync.WaitGroup

// new notifications service (service-based notifiers)
notificationService *NotificationService
}

func NewTaskRunner(
Expand All @@ -67,10 +70,11 @@ func NewTaskRunner(
keyInstaller db_lib.AccessKeyInstaller,
) *TaskRunner {
return &TaskRunner{
Task: newTask,
pool: p,
Username: username,
keyInstaller: keyInstaller,
Task: newTask,
pool: p,
Username: username,
keyInstaller: keyInstaller,
notificationService: NewNotificationService(),
}
}

Expand Down
35 changes: 29 additions & 6 deletions services/tasks/TaskRunner_logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"os/exec"
"time"
"strconv"

"github.com/semaphoreui/semaphore/pkg/tz"

Expand Down Expand Up @@ -122,12 +123,34 @@ func (t *TaskRunner) SetStatus(status task_logger.TaskStatus) {
}

if status.IsNotifiable() {
t.sendTelegramAlert()
t.sendSlackAlert()
t.sendRocketChatAlert()
t.sendMicrosoftTeamsAlert()
t.sendDingTalkAlert()
t.sendGotifyAlert()
// Prefer new notification service if configured; otherwise fallback to legacy methods
if t.notificationService != nil && t.notificationService.HasNotifiers() {
author, version := t.alertInfos()
alert := Alert{
Name: t.Template.Name,
Author: author,
Color: t.alertColor("slack"),
Task: alertTask{
Comment on lines 125 to +133

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Respect alert flags and success suppression

The new notification-service path sends an alert unconditionally whenever status.IsNotifiable() is true, but it no longer checks the project/template alert toggle or Template.SuppressSuccessAlerts like the legacy send*Alert functions do. As a result, enabling the unified notifications config will emit Telegram/Slack/etc. messages even when alerts are disabled for the project or when success notifications are explicitly suppressed. The branch should short-circuit when t.alert is false or the template suppresses success notifications before invoking SendAll.

Useful? React with 👍 / 👎.

ID: strconv.Itoa(t.Task.ID),
URL: t.taskLink(),
Result: t.Task.Status.Format(),
Version: version,
Desc: t.Task.Message,
},
}
// If chat override is present, set it for telegram
if t.alertChat != nil && *t.alertChat != "" {
alert.Chat = alertChat{ID: *t.alertChat}
}
t.notificationService.SendAll(alert)
} else {
t.sendTelegramAlert()
t.sendSlackAlert()
t.sendRocketChatAlert()
t.sendMicrosoftTeamsAlert()
t.sendDingTalkAlert()
t.sendGotifyAlert()
}
}

for _, l := range t.statusListeners {
Expand Down
33 changes: 27 additions & 6 deletions services/tasks/alert_test_sender.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package tasks

import (
"strconv"

"github.com/semaphoreui/semaphore/db"
"github.com/semaphoreui/semaphore/pkg/task_logger"
)
Expand Down Expand Up @@ -40,12 +42,31 @@ func SendProjectTestAlerts(project db.Project, store db.Store) (err error) {
},
}

tr.sendTelegramAlert()
tr.sendSlackAlert()
tr.sendRocketChatAlert()
tr.sendMicrosoftTeamsAlert()
tr.sendDingTalkAlert()
tr.sendGotifyAlert()
if tr.notificationService != nil && tr.notificationService.HasNotifiers() {
author, version := tr.alertInfos()
alert := Alert{
Name: tr.Template.Name,
Author: author,
Task: alertTask{
ID: strconv.Itoa(tr.Task.ID),
URL: tr.taskLink(),
Result: tr.Task.Status.Format(),
Version: version,
Desc: tr.Task.Message,
},
}
if tr.alertChat != nil && *tr.alertChat != "" {
alert.Chat = alertChat{ID: *tr.alertChat}
}
tr.notificationService.SendAll(alert)
} else {
tr.sendTelegramAlert()
tr.sendSlackAlert()
tr.sendRocketChatAlert()
tr.sendMicrosoftTeamsAlert()
tr.sendDingTalkAlert()
tr.sendGotifyAlert()
}
tr.sendMailAlert()

return
Expand Down
Loading
Loading