Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: discord channels for test/deployment failure notifications #67

Merged
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
19 changes: 15 additions & 4 deletions cd/manager/notifs/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 10 additions & 6 deletions cd/manager/notifs/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading