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(); using var console = new TestConsole();
var step = Substitute.For<IMigrationStep>(); var step = Substitute.For<IMigrationStep>();
var executor = new MigrationExecutor(new[] {step}, console); 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.CheckIfNeeded().Returns(true);
step.When(x => x.Execute(null)).Throw(exception); step.When(x => x.Execute(null)).Throw(exception);

@ -3,18 +3,21 @@ using System.Text.RegularExpressions;
namespace Recyclarr.TestLibrary; namespace Recyclarr.TestLibrary;
public static class FileUtils public static partial class FileUtils
{ {
public static ICollection<string> NormalizePaths(IEnumerable<string> paths) public static ICollection<string> NormalizePaths(IEnumerable<string> paths)
=> paths.Select(NormalizePath).ToList(); => paths.Select(NormalizePath).ToList();
public static string NormalizePath(string path) public static string NormalizePath(string path)
{ {
if (MockUnixSupport.IsUnixPlatform()) return MockUnixSupport.IsUnixPlatform()
{ ? WindowsRootRegex().Replace(path, "/").Replace("\\", "/")
return Regex.Replace(path, @"^C:\\", "/").Replace("\\", "/"); : LinuxRootRegex().Replace(path, @"C:\").Replace("/", "\\");
}
return Regex.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 public interface IServiceRequestBuilder
{ {
string SanitizedBaseUrl { get; }
IFlurlRequest Request(params object[] path); IFlurlRequest Request(params object[] path);
} }

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

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

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

Loading…
Cancel
Save