mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 16:59:12 +00:00
feat: return action rejections from arrs (#103)
* refactor: push status * feat: return push status for arr actions
This commit is contained in:
parent
20138030e1
commit
373c85f060
16 changed files with 294 additions and 255 deletions
|
@ -22,7 +22,7 @@ type Config struct {
|
|||
|
||||
type Client interface {
|
||||
Test() (*SystemStatusResponse, error)
|
||||
Push(release Release) (bool, string, error)
|
||||
Push(release Release) ([]string, error)
|
||||
}
|
||||
|
||||
type client struct {
|
||||
|
@ -93,15 +93,15 @@ func (c *client) Test() (*SystemStatusResponse, error) {
|
|||
return &response, nil
|
||||
}
|
||||
|
||||
func (c *client) Push(release Release) (bool, string, error) {
|
||||
func (c *client) Push(release Release) ([]string, error) {
|
||||
res, err := c.post("release/push", release)
|
||||
if err != nil {
|
||||
log.Error().Stack().Err(err).Msg("sonarr client post error")
|
||||
return false, "", err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if res == nil {
|
||||
return false, "", nil
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
defer res.Body.Close()
|
||||
|
@ -109,14 +109,14 @@ func (c *client) Push(release Release) (bool, string, error) {
|
|||
body, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
log.Error().Stack().Err(err).Msg("sonarr client error reading body")
|
||||
return false, "", err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pushResponse := make([]PushResponse, 0)
|
||||
err = json.Unmarshal(body, &pushResponse)
|
||||
if err != nil {
|
||||
log.Error().Stack().Err(err).Msg("sonarr client error json unmarshal")
|
||||
return false, "", err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Trace().Msgf("sonarr release/push response body: %+v", string(body))
|
||||
|
@ -126,9 +126,9 @@ func (c *client) Push(release Release) (bool, string, error) {
|
|||
rejections := strings.Join(pushResponse[0].Rejections, ", ")
|
||||
|
||||
log.Trace().Msgf("sonarr push rejected: %s - reasons: %q", release.Title, rejections)
|
||||
return false, rejections, nil
|
||||
return pushResponse[0].Rejections, nil
|
||||
}
|
||||
|
||||
// successful push
|
||||
return true, "", nil
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
@ -47,11 +47,12 @@ func Test_client_Push(t *testing.T) {
|
|||
release Release
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
err error
|
||||
wantErr bool
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
rejections []string
|
||||
err error
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "push",
|
||||
|
@ -73,8 +74,9 @@ func Test_client_Push(t *testing.T) {
|
|||
Protocol: "torrent",
|
||||
PublishDate: "2021-08-21T15:36:00Z",
|
||||
}},
|
||||
err: errors.New("sonarr push rejected Unknown Series"),
|
||||
wantErr: true,
|
||||
rejections: []string{"Unknown Series"},
|
||||
//err: errors.New("sonarr push rejected Unknown Series"),
|
||||
//wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "push_error",
|
||||
|
@ -96,15 +98,17 @@ func Test_client_Push(t *testing.T) {
|
|||
Protocol: "torrent",
|
||||
PublishDate: "2021-08-21T15:36:00Z",
|
||||
}},
|
||||
err: errors.New("sonarr push rejected Unknown Series"),
|
||||
wantErr: true,
|
||||
rejections: []string{"Unknown Series"},
|
||||
//err: errors.New("sonarr push rejected Unknown Series"),
|
||||
//wantErr: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
c := New(tt.fields.config)
|
||||
|
||||
_, _, err := c.Push(tt.args.release)
|
||||
rejections, err := c.Push(tt.args.release)
|
||||
assert.Equal(t, tt.rejections, rejections)
|
||||
if tt.wantErr && assert.Error(t, err) {
|
||||
assert.Equal(t, tt.err, err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue