diff --git a/src/FilterLists.Agent/Features/Urls/DataFileUrlValidationResults.cs b/src/FilterLists.Agent/Features/Urls/DataFileUrlValidationResults.cs new file mode 100644 index 000000000..3ad609128 --- /dev/null +++ b/src/FilterLists.Agent/Features/Urls/DataFileUrlValidationResults.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; + +namespace FilterLists.Agent.Features.Urls +{ + public class DataFileUrlValidationResults + { + public DataFileUrlValidationResults(string dataFileName, IEnumerable results) + { + DataFileName = dataFileName; + Results = results; + } + + public string DataFileName { get; } + + public IEnumerable Results { get; } + } +} \ No newline at end of file diff --git a/src/FilterLists.Agent/Features/Urls/ValidateAllUrls.cs b/src/FilterLists.Agent/Features/Urls/ValidateAllUrls.cs index 6bd7647dd..25e307b7c 100644 --- a/src/FilterLists.Agent/Features/Urls/ValidateAllUrls.cs +++ b/src/FilterLists.Agent/Features/Urls/ValidateAllUrls.cs @@ -1,4 +1,6 @@ -using System.Threading; +using System.Collections.Generic; +using System.Linq; +using System.Threading; using System.Threading.Tasks; using FilterLists.Agent.Core.Interfaces; using FilterLists.Agent.Features.Urls.Models; @@ -25,12 +27,32 @@ public Handler(IMediator mediator, IUrlsRepository urlsRepository) protected override async Task Handle(Command request, CancellationToken cancellationToken) { + var results = new List(); + + var licenseUrls = await _repo.GetAllAsync(); + var licenseUrlErrors = (await _mediator.Send(new ValidateUrls.Command(licenseUrls), cancellationToken)).ToList(); + if (licenseUrlErrors.Any()) + results.Add(new DataFileUrlValidationResults("License.json", licenseUrlErrors)); + + var listUrls = await _repo.GetAllAsync(); + var listUrlErrors = (await _mediator.Send(new ValidateUrls.Command(listUrls), cancellationToken)).ToList(); + if (listUrlErrors.Any()) + results.Add(new DataFileUrlValidationResults("FilterList.json", listUrlErrors)); + var maintainerUrls = await _repo.GetAllAsync(); - var errors = await _mediator.Send(new ValidateUrls.Command(maintainerUrls), cancellationToken); + var maintainerUrlErrors = (await _mediator.Send(new ValidateUrls.Command(maintainerUrls), cancellationToken)).ToList(); + if (maintainerUrlErrors.Any()) + results.Add(new DataFileUrlValidationResults("Maintainer.json", maintainerUrlErrors)); - //TODO: validate if http can be changed to https + var softwareUrls = await _repo.GetAllAsync(); + var softwareUrlErrors = (await _mediator.Send(new ValidateUrls.Command(softwareUrls), cancellationToken)).ToList(); + if (softwareUrlErrors.Any()) + results.Add(new DataFileUrlValidationResults("Software.json", softwareUrlErrors)); - //TODO: iterate through each IEntityUrl impl + var syntaxUrls = await _repo.GetAllAsync(); + var syntaxUrlErrors = (await _mediator.Send(new ValidateUrls.Command(syntaxUrls), cancellationToken)).ToList(); + if (syntaxUrlErrors.Any()) + results.Add(new DataFileUrlValidationResults("Syntax.json", syntaxUrlErrors)); //TODO: create or edit GitHub issue with results } diff --git a/src/FilterLists.Agent/Program.cs b/src/FilterLists.Agent/Program.cs index ded98d9e3..dc432e1eb 100644 --- a/src/FilterLists.Agent/Program.cs +++ b/src/FilterLists.Agent/Program.cs @@ -16,8 +16,8 @@ public static async Task Main() { BuildServiceProvider(); var mediator = _serviceProvider.GetService(); - //await mediator.Send(new CaptureLists.Command()); - await mediator.Send(new ValidateAllUrls.Command()); + await mediator.Send(new CaptureLists.Command()); + //await mediator.Send(new ValidateAllUrls.Command()); } private static void BuildServiceProvider()