diff --git a/services/Archival/FilterLists.Archival.Application/Commands/ArchiveList.cs b/services/Archival/FilterLists.Archival.Application/Commands/ArchiveList.cs index b03de745c..a1e265ec1 100644 --- a/services/Archival/FilterLists.Archival.Application/Commands/ArchiveList.cs +++ b/services/Archival/FilterLists.Archival.Application/Commands/ArchiveList.cs @@ -34,18 +34,18 @@ public class Handler : IRequestHandler private readonly IHttpContentClient _client; private readonly IDirectoryApi _directory; private readonly ILogger _logger; - private readonly ITxtFileRepository _repo; + private readonly IFileRepository _repo; public Handler( IHttpContentClient httpContentClient, IDirectoryApi directoryApi, ILogger logger, - ITxtFileRepository txtFileRepository) + IFileRepository fileRepository) { _client = httpContentClient; _directory = directoryApi; _logger = logger; - _repo = txtFileRepository; + _repo = fileRepository; } public async Task Handle(Command request, CancellationToken cancellationToken) @@ -67,7 +67,7 @@ public async Task Handle(Command request, CancellationToken cancellationTo } else { - _logger.LogInformation("List {ListId} has no URLs to archive", request.ListId); + _logger.LogWarning("List {ListId} has no URLs to archive", request.ListId); } return Unit.Value; @@ -89,7 +89,7 @@ private IFile GetFileToArchive( CancellationToken cancellationToken) { var segmentsAsync = GetSegmentsAsync(segmentUrls, cancellationToken); - var target = $"{listId.ToString(CultureInfo.InvariantCulture).PadLeft(5, '0')}.txt"; + var target = listId.ToString(CultureInfo.InvariantCulture).PadLeft(5, '0'); return new File(segmentsAsync, target); } diff --git a/services/Archival/FilterLists.Archival.Infrastructure/Clients/IHttpContentClient.cs b/services/Archival/FilterLists.Archival.Infrastructure/Clients/IHttpContentClient.cs index b42735d62..8652ad17b 100644 --- a/services/Archival/FilterLists.Archival.Infrastructure/Clients/IHttpContentClient.cs +++ b/services/Archival/FilterLists.Archival.Infrastructure/Clients/IHttpContentClient.cs @@ -16,7 +16,7 @@ public interface IHttpContentClient : IDisposable internal sealed class HttpContentClient : IHttpContentClient { private readonly HttpClient _httpClient; - private readonly ICollection _httpResponseMessages = new List(); + private readonly ICollection _httpResponseMessages = new HashSet(); private readonly ILogger _logger; public HttpContentClient(HttpClient httpClient, ILogger logger) diff --git a/services/Archival/FilterLists.Archival.Infrastructure/Persistence/ConfigurationExtensions.cs b/services/Archival/FilterLists.Archival.Infrastructure/Persistence/ConfigurationExtensions.cs index d0d39ae8c..05beacce5 100644 --- a/services/Archival/FilterLists.Archival.Infrastructure/Persistence/ConfigurationExtensions.cs +++ b/services/Archival/FilterLists.Archival.Infrastructure/Persistence/ConfigurationExtensions.cs @@ -20,7 +20,7 @@ public static void AddPersistenceServices(this IServiceCollection services, ICon return new Repository(gitOptions.RepositoryPath); }); - services.AddTransient(); + services.AddTransient(); } } } diff --git a/services/Archival/FilterLists.Archival.Infrastructure/Persistence/ITxtFileRepository.cs b/services/Archival/FilterLists.Archival.Infrastructure/Persistence/IFileRepository.cs similarity index 76% rename from services/Archival/FilterLists.Archival.Infrastructure/Persistence/ITxtFileRepository.cs rename to services/Archival/FilterLists.Archival.Infrastructure/Persistence/IFileRepository.cs index b52e56737..68b6dd40b 100644 --- a/services/Archival/FilterLists.Archival.Infrastructure/Persistence/ITxtFileRepository.cs +++ b/services/Archival/FilterLists.Archival.Infrastructure/Persistence/IFileRepository.cs @@ -13,20 +13,20 @@ namespace FilterLists.Archival.Infrastructure.Persistence { - public interface ITxtFileRepository : IUnitOfWork + public interface IFileRepository : IUnitOfWork { Task AddFileAsync(IFile file, CancellationToken cancellationToken); } - internal sealed class GitTxtFileRepository : ITxtFileRepository + internal sealed class GitFileRepository : IFileRepository { private readonly ILogger _logger; private readonly GitOptions _options; private readonly IRepository _repo; private readonly ICollection _writtenFiles = new HashSet(); - public GitTxtFileRepository( - ILogger logger, + public GitFileRepository( + ILogger logger, IOptions gitOptions, IRepository repository) { @@ -70,13 +70,20 @@ public async Task AddFileAsync(IFile file, CancellationToken cancellationToken) public void Commit() { - var fileNames = _writtenFiles.Select(f => f.Name).ToList(); - var signature = new Signature(_options.UserName, _options.UserEmail, DateTime.UtcNow); - var message = $"feat(archives): archive {fileNames.Count} file(s){Environment.NewLine}{string.Join(Environment.NewLine, fileNames)}"; - Commands.Stage(_repo, fileNames); - _repo.Commit(message, signature, signature); + if (_writtenFiles.Count > 0) + { + var fileNames = _writtenFiles.Select(f => f.Name).ToList(); + var signature = new Signature(_options.UserName, _options.UserEmail, DateTime.UtcNow); + var message = $"feat(archives): archive {fileNames.Count} file(s){Environment.NewLine}{string.Join(Environment.NewLine, fileNames)}"; + Commands.Stage(_repo, fileNames); + _repo.Commit(message, signature, signature); - _logger.LogInformation("Committed {@FileNames}", fileNames); + _logger.LogInformation("Committed {@FileNames}", fileNames); + } + else + { + _logger.LogInformation("No written files to commit"); + } } public void Dispose()