fix(sonarr): Error when using release profiles with Sonarr v4

Fixes #100
pull/124/head
Robert Dailey 2 years ago
parent f87971fec1
commit 2db0faa00c

@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Docker: Fix `/config` permissions when not using bind-mount for the volume. (#111)
- Sonarr: Error message is printed when attempting to use release profiles with Sonarr v4. (#100)
### Security

@ -1,4 +1,5 @@
using System.Reactive.Linq;
using AutoFixture.NUnit3;
using AutoMapper;
using FluentAssertions;
using Newtonsoft.Json;
@ -6,16 +7,20 @@ using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
using NSubstitute;
using NUnit.Framework;
using TestLibrary.AutoFixture;
using TrashLib.ExceptionTypes;
using TrashLib.Services.Sonarr;
using TrashLib.Services.Sonarr.Api;
using TrashLib.Services.Sonarr.Api.Objects;
using TrashLib.Services.Sonarr.Config;
using TrashLib.Services.Sonarr.ReleaseProfile;
using TrashLib.Startup;
namespace TrashLib.Tests.Sonarr.Api;
namespace TrashLib.Tests.Sonarr;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class SonarrReleaseProfileCompatibilityHandlerTest
public class SonarrCompatibilityTest
{
private class TestContext : IDisposable
{
@ -111,4 +116,40 @@ public class SonarrReleaseProfileCompatibilityHandlerTest
result.Should().BeEquivalentTo(data);
}
[Test, AutoMockData]
public async Task Failure_when_release_profiles_used_with_sonarr_v4(
[Frozen] ISonarrApi api,
[Frozen(Matching.ImplementedInterfaces)] SonarrCompatibility compatibility,
ReleaseProfileUpdater updater)
{
api.GetVersion().Returns(new Version(4, 0));
var config = new SonarrConfiguration
{
ReleaseProfiles = new List<ReleaseProfileConfig> {new()}
};
var act = () => updater.Process(false, config);
await act.Should().ThrowAsync<VersionException>().WithMessage("Sonarr v4*");
}
[Test, AutoMockData]
public async Task No_failure_when_release_profiles_used_with_sonarr_v3(
[Frozen] ISonarrApi api,
[Frozen(Matching.ImplementedInterfaces)] SonarrCompatibility compatibility,
ReleaseProfileUpdater updater)
{
api.GetVersion().Returns(new Version(3, 9));
var config = new SonarrConfiguration
{
ReleaseProfiles = new List<ReleaseProfileConfig> {new()}
};
var act = () => updater.Process(false, config);
await act.Should().NotThrowAsync();
}
}

@ -10,4 +10,6 @@ public interface ISonarrApi
Task<IList<SonarrQualityDefinitionItem>> UpdateQualityDefinition(
IReadOnlyCollection<SonarrQualityDefinitionItem> newQuality);
Task<Version> GetVersion();
}

@ -14,6 +14,15 @@ public class SonarrApi : ISonarrApi
_serverInfo = serverInfo;
}
public async Task<Version> GetVersion()
{
var response = await BaseUrl()
.AppendPathSegment("system/status")
.GetJsonAsync();
return new Version(response.version);
}
public async Task<IList<SonarrTag>> GetTags()
{
return await BaseUrl()

@ -41,6 +41,8 @@ public class ReleaseProfileUpdater : IReleaseProfileUpdater
public async Task Process(bool isPreview, SonarrConfiguration config)
{
await DoVersionEnforcement(config);
var profilesFromGuide = _guide.GetReleaseProfileData();
var filteredProfiles = new List<(ReleaseProfileData Profile, IReadOnlyCollection<string> Tags)>();
@ -129,8 +131,6 @@ public class ReleaseProfileUpdater : IReleaseProfileUpdater
private async Task ProcessReleaseProfiles(
List<(ReleaseProfileData Profile, IReadOnlyCollection<string> Tags)> profilesAndTags)
{
await DoVersionEnforcement();
// Obtain all of the existing release profiles first. If any were previously created by our program
// here, we favor replacing those instead of creating new ones, which would just be mostly duplicates
// (but with some differences, since there have likely been updates since the last run).
@ -196,7 +196,7 @@ public class ReleaseProfileUpdater : IReleaseProfileUpdater
.ToList();
}
private async Task DoVersionEnforcement()
private async Task DoVersionEnforcement(SonarrConfiguration config)
{
var capabilities = await _compatibility.Capabilities.LastAsync();
if (!capabilities.SupportsNamedReleaseProfiles)
@ -205,6 +205,11 @@ public class ReleaseProfileUpdater : IReleaseProfileUpdater
$"Your Sonarr version {capabilities.Version} does not meet the minimum " +
$"required version of {_compatibility.MinimumVersion} to use this program");
}
if (capabilities.SupportsCustomFormats && config.ReleaseProfiles.Any())
{
throw new VersionException("Sonarr v4 does not support Release Profiles. Please use Sonarr v3 instead.");
}
}
private async Task CreateMissingTags(ICollection<SonarrTag> sonarrTags, IEnumerable<string> configTags)

@ -1,19 +1,11 @@
namespace TrashLib.Services.Sonarr;
public record SonarrCapabilities
public record SonarrCapabilities(Version Version)
{
public SonarrCapabilities()
public SonarrCapabilities() : this(new Version())
{
Version = new Version();
}
public SonarrCapabilities(Version version)
{
Version = version;
}
public Version Version { get; }
public bool SupportsNamedReleaseProfiles { get; init; }
// Background: Issue #16 filed which points to a backward-breaking API
@ -21,4 +13,6 @@ public record SonarrCapabilities
//
// [deed85d2f]: https://github.com/Sonarr/Sonarr/commit/deed85d2f9147e6180014507ef4f5af3695b0c61
public bool ArraysNeededForReleaseProfileRequiredAndIgnored { get; init; }
public bool SupportsCustomFormats { get; init; }
}

@ -1,8 +1,7 @@
using System.Reactive.Concurrency;
using System.Reactive.Linq;
using Flurl.Http;
using Serilog;
using TrashLib.Config.Services;
using TrashLib.Services.Sonarr.Api;
namespace TrashLib.Services.Sonarr;
@ -10,15 +9,11 @@ public class SonarrCompatibility : ISonarrCompatibility
{
private readonly ILogger _log;
public SonarrCompatibility(IServerInfo serverInfo, ILogger log)
public SonarrCompatibility(ISonarrApi api, ILogger log)
{
_log = log;
Capabilities = Observable.FromAsync(
async () => await serverInfo.BuildRequest()
.AppendPathSegment("system/status")
.GetJsonAsync(), NewThreadScheduler.Default)
Capabilities = Observable.FromAsync(async () => await api.GetVersion(), NewThreadScheduler.Default)
.Timeout(TimeSpan.FromSeconds(15))
.Select(x => new Version(x.version))
.Select(BuildCapabilitiesObject)
.Replay(1)
.AutoConnect();
@ -36,7 +31,10 @@ public class SonarrCompatibility : ISonarrCompatibility
version >= MinimumVersion,
ArraysNeededForReleaseProfileRequiredAndIgnored =
version >= new Version("3.0.6.1355")
version >= new Version("3.0.6.1355"),
SupportsCustomFormats =
version >= new Version(4, 0)
};
}
}

Loading…
Cancel
Save