feat(actions): simplify macro parsing (#560)

* refactor(action): parse macros

* feat(action): add ctx to arr clients and test
This commit is contained in:
ze0s 2022-12-10 21:48:19 +01:00 committed by GitHub
parent f6e68fae2b
commit 839eb9f3f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 323 additions and 334 deletions

View file

@ -1,6 +1,9 @@
package domain
import "context"
import (
"context"
"github.com/autobrr/autobrr/pkg/errors"
)
type ActionRepo interface {
Store(ctx context.Context, action Action) (*Action, error)
@ -46,6 +49,27 @@ type Action struct {
Client DownloadClient `json:"client,omitempty"`
}
// ParseMacros parse all macros on action
func (a *Action) ParseMacros(release Release) error {
var err error
m := NewMacro(release)
a.ExecArgs, err = m.Parse(a.ExecArgs)
a.WatchFolder, err = m.Parse(a.WatchFolder)
a.Category, err = m.Parse(a.Category)
a.Tags, err = m.Parse(a.Tags)
a.Label, err = m.Parse(a.Label)
a.SavePath, err = m.Parse(a.SavePath)
a.WebhookData, err = m.Parse(a.WebhookData)
if err != nil {
return errors.Wrap(err, "could not parse macros for action: %v", a.Name)
}
return nil
}
type ActionType string
const (