Skip to content

Commit

Permalink
lint.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhadfield committed Jan 18, 2025
1 parent 9a45f6a commit 0f8732b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,17 +314,20 @@ func TestAzureDevOpsRepositoryBackupWithBackupsToKeepAsOne(t *testing.T) {

func TestGetRequestTimeout(t *testing.T) {
t.Setenv(envGitRequestTimeout, "600")

ok, timeout, err := getRequestTimeout()
require.NoError(t, err)
require.True(t, ok)
require.Equal(t, 600*time.Second, timeout)

t.Setenv(envGitRequestTimeout, "invalid")

ok, _, err = getRequestTimeout()
require.False(t, ok)
require.Error(t, err)

t.Setenv(envGitRequestTimeout, "")

ok, timeout, err = getRequestTimeout()
require.NoError(t, err)
require.False(t, ok)
Expand Down
9 changes: 6 additions & 3 deletions notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
const (
envSobaNtfyURL = "SOBA_NTFY_URL"
envSlackChannelID = "SLACK_CHANNEL_ID"
envSlackAPIToken = "SLACK_API_TOKEN"
envSlackAPIToken = "SLACK_API_TOKEN" //nolint:gosec
envTelegramBotToken = "SOBA_TELEGRAM_BOT_TOKEN"
envTelegramChatID = "SOBA_TELEGRAM_CHAT_ID"
)
Expand Down Expand Up @@ -68,22 +68,24 @@ func notify(backupResults BackupResults, succeeded int, failed int) {

telegramBotToken := os.Getenv(envTelegramBotToken)
telegramChatID := os.Getenv(envTelegramChatID)

if telegramBotToken != "" && telegramChatID != "" {
sendTelegramMessage(httpClient, telegramBotToken, telegramChatID, succeeded, failed, errs)
}
}

func sendTelegramMessage(hc *retryablehttp.Client, botToken, chatID string, succeeded, failed int, errs []errors.E) {
var text string

switch {
case succeeded > 0 && failed == 0:
text = "🚀 soba backups succeeded"
case failed > 0 && succeeded > 0:

text = "️⚠️ soba backups completed with errors"
default:
text = "️🚨 soba backups failed"
}

text += fmt.Sprintf("\ncompleted: %d, failed: %d",
succeeded, failed)

Expand Down Expand Up @@ -179,18 +181,19 @@ func sendNtfy(hc *retryablehttp.Client, nURL string, succeeded, failed int, errs

func sendSlackMessage(slackChannelID string, succeeded, failed int, errs []errors.E) {
errorMsgs := make([]string, 0)

for _, err := range errs {
if err != nil {
errorMsgs = append(errorMsgs, err.Error())
}
}

var title string

switch {
case succeeded > 0 && failed == 0:
title = "🚀 soba backups succeeded"
case failed > 0 && succeeded > 0:

title = "️⚠️ soba backups completed with errors"
default:
title = "️🚨 soba backups failed"
Expand Down

0 comments on commit 0f8732b

Please sign in to comment.