mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
initial add BuildGitHubIssueBody
This commit is contained in:
parent
d1e6649df8
commit
ec77db54f2
2 changed files with 59 additions and 7 deletions
50
src/FilterLists.Agent/Features/Urls/BuildGitHubIssueBody.cs
Normal file
50
src/FilterLists.Agent/Features/Urls/BuildGitHubIssueBody.cs
Normal file
|
|
@ -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<string>
|
||||
{
|
||||
public Command(IEnumerable<DataFileUrlValidationResults> dataFileUrlValidationResults)
|
||||
{
|
||||
DataFileUrlValidationResults = dataFileUrlValidationResults;
|
||||
}
|
||||
|
||||
public IEnumerable<DataFileUrlValidationResults> DataFileUrlValidationResults { get; }
|
||||
}
|
||||
|
||||
public class Handler : RequestHandler<Command, string>
|
||||
{
|
||||
private const string IssueHeader =
|
||||
"<p>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.</p><p>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.</p><p>Thanks for your contributions!</p>";
|
||||
|
||||
protected override string Handle(Command request)
|
||||
{
|
||||
var body = new StringBuilder();
|
||||
body.Append(IssueHeader);
|
||||
foreach (var fileReults in request.DataFileUrlValidationResults)
|
||||
{
|
||||
body.Append($"<h1>{fileReults.DataFileName}</h1>");
|
||||
body.Append("<ul>");
|
||||
foreach (var result in fileReults.Results)
|
||||
{
|
||||
body.Append($"<li>[{result.Url.AbsolutePath}]({result.Url.AbsolutePath})");
|
||||
body.Append("<ul>");
|
||||
foreach (var message in result.Messages)
|
||||
body.Append($"<li>{message}</li>");
|
||||
body.Append("</ul>");
|
||||
body.Append("</li>");
|
||||
}
|
||||
|
||||
body.Append("</ul>");
|
||||
}
|
||||
|
||||
return body.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -27,16 +27,18 @@ public class Handler : AsyncRequestHandler<Command>
|
|||
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<Issue> GetOpenIssueOrNull()
|
||||
|
|
@ -56,15 +58,15 @@ private async Task<Issue> CreateBaseIssue()
|
|||
return await _gitHubClient.CreateIssue(newIssue);
|
||||
}
|
||||
|
||||
private async Task UpdateIssue(Issue issue)
|
||||
private async Task UpdateIssue(Issue issue,
|
||||
IEnumerable<DataFileUrlValidationResults> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue