mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
feat(archival): ✨ add logging to GitFileArchiver
This commit is contained in:
parent
877478b374
commit
b057a9fcc0
1 changed files with 13 additions and 1 deletions
|
|
@ -5,6 +5,7 @@
|
|||
using System.Threading.Tasks;
|
||||
using FilterLists.Archival.Infrastructure.Options;
|
||||
using LibGit2Sharp;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace FilterLists.Archival.Infrastructure.Persistence
|
||||
|
|
@ -12,11 +13,16 @@ namespace FilterLists.Archival.Infrastructure.Persistence
|
|||
internal class GitFileArchiver : IArchiveFiles
|
||||
{
|
||||
private readonly IList<string> _filePaths = new List<string>();
|
||||
private readonly ILogger<GitFileArchiver> _logger;
|
||||
private readonly GitOptions _options;
|
||||
private readonly IRepository _repository;
|
||||
|
||||
public GitFileArchiver(IOptions<GitOptions> gitOptions, IRepository gitRepository)
|
||||
public GitFileArchiver(
|
||||
ILogger<GitFileArchiver> logger,
|
||||
IOptions<GitOptions> gitOptions,
|
||||
IRepository gitRepository)
|
||||
{
|
||||
_logger = logger;
|
||||
_options = gitOptions.Value;
|
||||
_repository = gitRepository;
|
||||
}
|
||||
|
|
@ -26,9 +32,13 @@ public async Task ArchiveFileAsync(
|
|||
string filePath,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
_logger.LogInformation($"Archiving {filePath}");
|
||||
|
||||
_filePaths.Add(filePath);
|
||||
await using var output = File.OpenWrite(filePath);
|
||||
await fileContents.CopyToAsync(output, cancellationToken);
|
||||
|
||||
_logger.LogInformation($"Archived {filePath}");
|
||||
}
|
||||
|
||||
public void Commit()
|
||||
|
|
@ -37,6 +47,8 @@ public void Commit()
|
|||
var signature = new Signature(_options.UserName, _options.UserEmail, DateTime.UtcNow);
|
||||
var message = $"feat(archives): archive {_filePaths.Count} files{Environment.NewLine}{string.Join(Environment.NewLine, _filePaths)}";
|
||||
_repository.Commit(message, signature, signature);
|
||||
|
||||
_logger.LogInformation($"Committed {string.Join(",", _filePaths)}");
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
|
|
|||
Loading…
Reference in a new issue