refactor: Fix more analysis issues

pull/201/head
Robert Dailey 1 year ago
parent c226097cb5
commit ce6afa4157

@ -105,7 +105,7 @@ public class MigrationExecutorTest : IntegrationFixture
using var console = new TestConsole();
var step = Substitute.For<IMigrationStep>();
var executor = new MigrationExecutor(new[] {step}, console);
var exception = new MigrationException(new Exception(), "a", new[] {"b"});
var exception = new MigrationException(new ArgumentException(), "a", new[] {"b"});
step.CheckIfNeeded().Returns(true);
step.When(x => x.Execute(null)).Throw(exception);

@ -3,18 +3,21 @@ using System.Text.RegularExpressions;
namespace Recyclarr.TestLibrary;
public static class FileUtils
public static partial class FileUtils
{
public static ICollection<string> NormalizePaths(IEnumerable<string> paths)
=> paths.Select(NormalizePath).ToList();
public static string NormalizePath(string path)
{
if (MockUnixSupport.IsUnixPlatform())
{
return Regex.Replace(path, @"^C:\\", "/").Replace("\\", "/");
}
return Regex.Replace(path, @"^/", @"C:\").Replace("/", "\\");
return MockUnixSupport.IsUnixPlatform()
? WindowsRootRegex().Replace(path, "/").Replace("\\", "/")
: LinuxRootRegex().Replace(path, @"C:\").Replace("/", "\\");
}
[GeneratedRegex(@"^C:\\")]
private static partial Regex WindowsRootRegex();
[GeneratedRegex("^/")]
private static partial Regex LinuxRootRegex();
}

@ -4,6 +4,5 @@ namespace Recyclarr.TrashLib.Http;
public interface IServiceRequestBuilder
{
string SanitizedBaseUrl { get; }
IFlurlRequest Request(params object[] path);
}

@ -20,6 +20,4 @@ public class ServiceRequestBuilder : IServiceRequestBuilder
return client.Request(new[] {"api", "v3"}.Concat(path).ToArray())
.SetQueryParams(new {apikey = _config.ApiKey});
}
public string SanitizedBaseUrl => FlurlLogging.SanitizeUrl(_config.BaseUrl);
}

@ -1,6 +1,5 @@
using Recyclarr.Common.Extensions;
using Recyclarr.TrashLib.Config.Services;
using Recyclarr.TrashLib.Http;
using Recyclarr.TrashLib.Services.Common;
using Recyclarr.TrashLib.Services.CustomFormat.Processors;
using Recyclarr.TrashLib.Services.CustomFormat.Processors.PersistenceSteps;
@ -15,7 +14,6 @@ internal class CustomFormatUpdater : ICustomFormatUpdater
private readonly IGuideProcessor _guideProcessor;
private readonly IPersistenceProcessor _persistenceProcessor;
private readonly IAnsiConsole _console;
private readonly IServiceRequestBuilder _service;
private readonly ILogger _log;
public CustomFormatUpdater(
@ -23,15 +21,13 @@ internal class CustomFormatUpdater : ICustomFormatUpdater
ICachePersister cache,
IGuideProcessor guideProcessor,
IPersistenceProcessor persistenceProcessor,
IAnsiConsole console,
IServiceRequestBuilder service)
IAnsiConsole console)
{
_log = log;
_cache = cache;
_guideProcessor = guideProcessor;
_persistenceProcessor = persistenceProcessor;
_console = console;
_service = service;
}
public async Task Process(bool isPreview, IEnumerable<CustomFormatConfig> configs, IGuideService guideService)
@ -197,8 +193,7 @@ internal class CustomFormatUpdater : ICustomFormatUpdater
// No CFs are defined in this item, or they are all invalid. Skip this whole instance.
if (_guideProcessor.ConfigData.Count == 0)
{
_log.Error("Guide processing yielded no custom formats for configured instance host {BaseUrl}",
_service.SanitizedBaseUrl);
_log.Error("Guide processing yielded no custom formats");
return false;
}

@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using Newtonsoft.Json.Linq;
namespace Recyclarr.TrashLib.Services.CustomFormat.Models;
@ -15,6 +16,7 @@ public class ProcessedCustomFormatData
public string Name => _data.Name;
public string TrashId => _data.TrashId;
public int? Score => _data.Score;
[SuppressMessage("Usage", "CA2227:Collection properties should be read only")]
public JObject Json { get; set; }
public int FormatId { get; set; }
}

Loading…
Cancel
Save