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

@ -30,22 +30,23 @@ func (s *service) testConnection(ctx context.Context, client domain.DownloadClie
return s.testRTorrentConnection(client)
case domain.DownloadClientTypeTransmission:
return s.testTransmissionConnection(client)
return s.testTransmissionConnection(ctx, client)
case domain.DownloadClientTypeRadarr:
return s.testRadarrConnection(client)
return s.testRadarrConnection(ctx, client)
case domain.DownloadClientTypeSonarr:
return s.testSonarrConnection(client)
return s.testSonarrConnection(ctx, client)
case domain.DownloadClientTypeLidarr:
return s.testLidarrConnection(client)
return s.testLidarrConnection(ctx, client)
case domain.DownloadClientTypeWhisparr:
return s.testWhisparrConnection(client)
return s.testWhisparrConnection(ctx, client)
case domain.DownloadClientTypeReadarr:
return s.testReadarrConnection(client)
return s.testReadarrConnection(ctx, client)
default:
return errors.New("unsupported client")
}
@ -138,7 +139,7 @@ func (s *service) testRTorrentConnection(client domain.DownloadClient) error {
return nil
}
func (s *service) testTransmissionConnection(client domain.DownloadClient) error {
func (s *service) testTransmissionConnection(ctx context.Context, client domain.DownloadClient) error {
tbt, err := transmissionrpc.New(client.Host, client.Username, client.Password, &transmissionrpc.AdvancedConfig{
HTTPS: client.TLS,
Port: uint16(client.Port),
@ -147,7 +148,7 @@ func (s *service) testTransmissionConnection(client domain.DownloadClient) error
return errors.Wrap(err, "error logging into client: %v", client.Host)
}
ok, version, _, err := tbt.RPCVersion(context.TODO())
ok, version, _, err := tbt.RPCVersion(ctx)
if err != nil {
return errors.Wrap(err, "error getting rpc info: %v", client.Host)
}
@ -163,7 +164,7 @@ func (s *service) testTransmissionConnection(client domain.DownloadClient) error
return nil
}
func (s *service) testRadarrConnection(client domain.DownloadClient) error {
func (s *service) testRadarrConnection(ctx context.Context, client domain.DownloadClient) error {
r := radarr.New(radarr.Config{
Hostname: client.Host,
APIKey: client.Settings.APIKey,
@ -173,8 +174,7 @@ func (s *service) testRadarrConnection(client domain.DownloadClient) error {
Log: s.subLogger,
})
_, err := r.Test()
if err != nil {
if _, err := r.Test(ctx); err != nil {
return errors.Wrap(err, "radarr: connection test failed: %v", client.Host)
}
@ -183,7 +183,7 @@ func (s *service) testRadarrConnection(client domain.DownloadClient) error {
return nil
}
func (s *service) testSonarrConnection(client domain.DownloadClient) error {
func (s *service) testSonarrConnection(ctx context.Context, client domain.DownloadClient) error {
r := sonarr.New(sonarr.Config{
Hostname: client.Host,
APIKey: client.Settings.APIKey,
@ -193,8 +193,7 @@ func (s *service) testSonarrConnection(client domain.DownloadClient) error {
Log: s.subLogger,
})
_, err := r.Test()
if err != nil {
if _, err := r.Test(ctx); err != nil {
return errors.Wrap(err, "sonarr: connection test failed: %v", client.Host)
}
@ -203,7 +202,7 @@ func (s *service) testSonarrConnection(client domain.DownloadClient) error {
return nil
}
func (s *service) testLidarrConnection(client domain.DownloadClient) error {
func (s *service) testLidarrConnection(ctx context.Context, client domain.DownloadClient) error {
r := lidarr.New(lidarr.Config{
Hostname: client.Host,
APIKey: client.Settings.APIKey,
@ -213,8 +212,7 @@ func (s *service) testLidarrConnection(client domain.DownloadClient) error {
Log: s.subLogger,
})
_, err := r.Test()
if err != nil {
if _, err := r.Test(ctx); err != nil {
return errors.Wrap(err, "lidarr: connection test failed: %v", client.Host)
}
@ -223,7 +221,7 @@ func (s *service) testLidarrConnection(client domain.DownloadClient) error {
return nil
}
func (s *service) testWhisparrConnection(client domain.DownloadClient) error {
func (s *service) testWhisparrConnection(ctx context.Context, client domain.DownloadClient) error {
r := whisparr.New(whisparr.Config{
Hostname: client.Host,
APIKey: client.Settings.APIKey,
@ -233,8 +231,7 @@ func (s *service) testWhisparrConnection(client domain.DownloadClient) error {
Log: s.subLogger,
})
_, err := r.Test()
if err != nil {
if _, err := r.Test(ctx); err != nil {
return errors.Wrap(err, "whisparr: connection test failed: %v", client.Host)
}
@ -243,7 +240,7 @@ func (s *service) testWhisparrConnection(client domain.DownloadClient) error {
return nil
}
func (s *service) testReadarrConnection(client domain.DownloadClient) error {
func (s *service) testReadarrConnection(ctx context.Context, client domain.DownloadClient) error {
r := readarr.New(readarr.Config{
Hostname: client.Host,
APIKey: client.Settings.APIKey,
@ -253,8 +250,7 @@ func (s *service) testReadarrConnection(client domain.DownloadClient) error {
Log: s.subLogger,
})
_, err := r.Test()
if err != nil {
if _, err := r.Test(ctx); err != nil {
return errors.Wrap(err, "readarr: connection test failed: %v", client.Host)
}