refactor: filter and action flow (#225)

* refactor: fitler and action flow

* fix: save release before filters

* feat: add action client to notifications

* feat: improve filter check logging
This commit is contained in:
Ludvig Lundgren 2022-04-09 21:20:26 +02:00 committed by GitHub
parent f32379ae76
commit a3854ecd59
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 654 additions and 313 deletions

View file

@ -4,7 +4,9 @@ import (
"bytes"
"crypto/tls"
"encoding/json"
"fmt"
"net/http"
"strings"
"time"
"github.com/autobrr/autobrr/internal/domain"
@ -38,7 +40,7 @@ func discordNotification(event domain.EventsReleasePushed, webhookURL string) {
},
}
client := http.Client{Transport: t, Timeout: 15 * time.Second}
client := http.Client{Transport: t, Timeout: 30 * time.Second}
color := map[domain.ReleasePushStatus]int{
domain.ReleasePushStatusApproved: 5814783,
@ -72,8 +74,18 @@ func discordNotification(event domain.EventsReleasePushed, webhookURL string) {
{
Name: "Action",
Value: event.Action,
Inline: false,
Inline: true,
},
{
Name: "Action type",
Value: string(event.ActionType),
Inline: true,
},
//{
// Name: "Action client",
// Value: event.ActionClient,
// Inline: true,
//},
},
Timestamp: time.Now(),
},
@ -81,6 +93,31 @@ func discordNotification(event domain.EventsReleasePushed, webhookURL string) {
Username: "brr",
}
if event.ActionClient == "" {
rej := DiscordEmbedsFields{
Name: "Action client",
Value: "n/a",
Inline: true,
}
m.Embeds[0].Fields = append(m.Embeds[0].Fields, rej)
} else {
rej := DiscordEmbedsFields{
Name: "Action client",
Value: event.ActionClient,
Inline: true,
}
m.Embeds[0].Fields = append(m.Embeds[0].Fields, rej)
}
if len(event.Rejections) > 0 {
rej := DiscordEmbedsFields{
Name: "Reasons",
Value: fmt.Sprintf("```\n%v\n```", strings.Join(event.Rejections, " ,")),
Inline: false,
}
m.Embeds[0].Fields = append(m.Embeds[0].Fields, rej)
}
jsonData, err := json.Marshal(m)
if err != nil {
log.Error().Err(err).Msgf("discord client could not marshal data: %v", m)
@ -89,7 +126,7 @@ func discordNotification(event domain.EventsReleasePushed, webhookURL string) {
req, err := http.NewRequest(http.MethodPost, webhookURL, bytes.NewBuffer(jsonData))
if err != nil {
//log.Error().Err(err).Msgf("webhook client request error: %v", action.WebhookHost)
log.Error().Err(err).Msgf("discord client request error: %v", event.ReleaseName)
return
}
@ -98,7 +135,7 @@ func discordNotification(event domain.EventsReleasePushed, webhookURL string) {
res, err := client.Do(req)
if err != nil {
//log.Error().Err(err).Msgf("webhook client request error: %v", action.WebhookHost)
log.Error().Err(err).Msgf("discord client request error: %v", event.ReleaseName)
return
}