diff --git a/cd/manager/notifs/discord.go b/cd/manager/notifs/discord.go index ad59b26..c0e1ff2 100644 --- a/cd/manager/notifs/discord.go +++ b/cd/manager/notifs/discord.go @@ -88,25 +88,36 @@ func parseDiscordWebhookUrl(urlEnv string) (webhook.Client, error) { return nil, nil } -func webhooksForLabels(labels []string) ([]webhook.Client, error) { +func webhooksForLabels(labels []string) ([]webhook.Client, []webhook.Client, error) { webhooks := make([]webhook.Client, 0) + failureWebhooks := make([]webhook.Client, 0) for _, label := range labels { switch label { case job.WorkflowJobLabel_Test: if t, err := parseDiscordWebhookUrl("DISCORD_TESTS_WEBHOOK"); err != nil { - return nil, err + return nil, nil, err } else { webhooks = append(webhooks, t) } + if f, err := parseDiscordWebhookUrl("DISCORD_TEST_FAILURES_WEBHOOK"); err != nil { + return nil, nil, err + } else { + failureWebhooks = append(failureWebhooks, f) + } case job.WorkflowJobLabel_Deploy: if t, err := parseDiscordWebhookUrl("DISCORD_DEPLOYMENTS_WEBHOOK"); err != nil { - return nil, err + return nil, nil, err } else { webhooks = append(webhooks, t) } + if f, err := parseDiscordWebhookUrl("DISCORD_DEPLOYMENT_FAILURES_WEBHOOK"); err != nil { + return nil, nil, err + } else { + failureWebhooks = append(failureWebhooks, f) + } } } - return webhooks, nil + return webhooks, failureWebhooks, nil } func (n JobNotifs) NotifyJob(jobs ...job.JobState) { diff --git a/cd/manager/notifs/workflow.go b/cd/manager/notifs/workflow.go index 44f2825..e9ecefc 100644 --- a/cd/manager/notifs/workflow.go +++ b/cd/manager/notifs/workflow.go @@ -19,25 +19,29 @@ const ( ) type workflowNotif struct { - state job.JobState - workflow job.Workflow - workflowWebhooks []webhook.Client + state job.JobState + workflow job.Workflow + webhooks []webhook.Client + failureWebhooks []webhook.Client } func newWorkflowNotif(jobState job.JobState) (jobNotif, error) { if workflow, err := job.CreateWorkflowJob(jobState); err != nil { return nil, err - } else if webhooks, err := webhooksForLabels(workflow.Labels); err != nil { + } else if webhooks, failureWebhooks, err := webhooksForLabels(workflow.Labels); err != nil { return nil, err } else { - return &workflowNotif{jobState, workflow, webhooks}, nil + return &workflowNotif{jobState, workflow, webhooks, failureWebhooks}, nil } } func (w workflowNotif) getChannels() []webhook.Client { + if w.state.Stage == job.JobStage_Failed { + return w.failureWebhooks + } else // Skip "started" notifications so that the channel doesn't get too noisy if w.state.Stage != job.JobStage_Started { - return w.workflowWebhooks + return w.webhooks } return nil }