diff --git a/src/FilterLists.Agent/Features/Urls/BuildGitHubIssueBody.cs b/src/FilterLists.Agent/Features/Urls/BuildGitHubIssueBody.cs new file mode 100644 index 000000000..0e3249b8c --- /dev/null +++ b/src/FilterLists.Agent/Features/Urls/BuildGitHubIssueBody.cs @@ -0,0 +1,50 @@ +using System.Collections.Generic; +using System.Text; +using FilterLists.Agent.Features.Urls.Models.ValidationResults; +using MediatR; + +namespace FilterLists.Agent.Features.Urls +{ + public static class BuildGitHubIssueBody + { + public class Command : IRequest + { + public Command(IEnumerable dataFileUrlValidationResults) + { + DataFileUrlValidationResults = dataFileUrlValidationResults; + } + + public IEnumerable DataFileUrlValidationResults { get; } + } + + public class Handler : RequestHandler + { + private const string IssueHeader = + "

This issue is auto-generated by the [FilterLists.Agent](https://github.com/collinbarrett/FilterLists/tree/master/src/FilterLists.Agent). If it is still open at 9am UTC daily, it is updated around that time.

We rely on the help of the community to ensure that the FilterLists site data remains up-to-date. The URLs listed below have been automatically flagged and may [need to be updated](https://github.com/collinbarrett/FilterLists/tree/master/data). Please consider submitting a PR against this issue updating some or all of the URLs accordingly.

Thanks for your contributions!

"; + + protected override string Handle(Command request) + { + var body = new StringBuilder(); + body.Append(IssueHeader); + foreach (var fileReults in request.DataFileUrlValidationResults) + { + body.Append($"

{fileReults.DataFileName}

"); + body.Append("
    "); + foreach (var result in fileReults.Results) + { + body.Append($"
  • [{result.Url.AbsolutePath}]({result.Url.AbsolutePath})"); + body.Append("
      "); + foreach (var message in result.Messages) + body.Append($"
    • {message}
    • "); + body.Append("
    "); + body.Append("
  • "); + } + + body.Append("
"); + } + + return body.ToString(); + } + } + } +} \ No newline at end of file diff --git a/src/FilterLists.Agent/Features/Urls/CreateOrUpdateGitHubIssue.cs b/src/FilterLists.Agent/Features/Urls/CreateOrUpdateGitHubIssue.cs index bb4472d14..86054b8ce 100644 --- a/src/FilterLists.Agent/Features/Urls/CreateOrUpdateGitHubIssue.cs +++ b/src/FilterLists.Agent/Features/Urls/CreateOrUpdateGitHubIssue.cs @@ -27,16 +27,18 @@ public class Handler : AsyncRequestHandler private const string HelpWantedLabel = "help wanted"; private const string IssueTitle = "Url Validation Errors"; private readonly IAgentGitHubClient _gitHubClient; + private readonly IMediator _mediator; - public Handler(IAgentGitHubClient agentGitHubClient) + public Handler(IAgentGitHubClient agentGitHubClient, IMediator mediator) { _gitHubClient = agentGitHubClient; + _mediator = mediator; } protected override async Task Handle(Command request, CancellationToken cancellationToken) { var issue = await GetOpenIssueOrNull() ?? await CreateBaseIssue(); - await UpdateIssue(issue); + await UpdateIssue(issue, request.DataFileUrlValidationResults, cancellationToken); } private async Task GetOpenIssueOrNull() @@ -56,15 +58,15 @@ private async Task CreateBaseIssue() return await _gitHubClient.CreateIssue(newIssue); } - private async Task UpdateIssue(Issue issue) + private async Task UpdateIssue(Issue issue, + IEnumerable dataFileUrlValidationResults, + CancellationToken cancellationToken) { var updateIssue = issue.ToUpdate(); updateIssue.AddLabel(AgentBotLabel); updateIssue.AddLabel(HelpWantedLabel); - - //TODO: set real body from request - updateIssue.Body = "Testing update of auto-issue from FilterLists.Agent."; - + updateIssue.Body = await _mediator.Send(new BuildGitHubIssueBody.Command(dataFileUrlValidationResults), + cancellationToken); await _gitHubClient.UpdateIssue(issue.Number, updateIssue); } }