mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
flesh out support of Issue create & update
This commit is contained in:
parent
76df08bd84
commit
25c7653914
2 changed files with 54 additions and 6 deletions
|
|
@ -1,8 +1,9 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using FilterLists.Agent.Features.Urls.Models.ValidationResults;
|
||||
using FilterLists.Agent.Infrastructure.Clients;
|
||||
using MediatR;
|
||||
using Octokit;
|
||||
|
||||
|
|
@ -22,16 +23,49 @@ public Command(IEnumerable<DataFileUrlValidationResults> dataFileUrlValidationRe
|
|||
|
||||
public class Handler : AsyncRequestHandler<Command>
|
||||
{
|
||||
private readonly IGitHubClient _gitHubClient;
|
||||
private const string AgentBotLabel = "agent bot";
|
||||
private const string HelpWantedLabel = "help wanted";
|
||||
private const string IssueTitle = "Url Validation Errors";
|
||||
private readonly IAgentGitHubClient _gitHubClient;
|
||||
|
||||
public Handler(IGitHubClient gitHubClient)
|
||||
public Handler(IAgentGitHubClient agentGitHubClient)
|
||||
{
|
||||
_gitHubClient = gitHubClient;
|
||||
_gitHubClient = agentGitHubClient;
|
||||
}
|
||||
|
||||
protected override async Task Handle(Command request, CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var issue = await GetOpenIssueOrNull() ?? await CreateBaseIssue();
|
||||
await UpdateIssue(issue);
|
||||
}
|
||||
|
||||
private async Task<Issue> GetOpenIssueOrNull()
|
||||
{
|
||||
var issueRequest = new RepositoryIssueRequest
|
||||
{
|
||||
Filter = IssueFilter.All,
|
||||
State = ItemStateFilter.Open,
|
||||
Labels = {AgentBotLabel}
|
||||
};
|
||||
return (await _gitHubClient.GetAllIssues(issueRequest)).FirstOrDefault();
|
||||
}
|
||||
|
||||
private async Task<Issue> CreateBaseIssue()
|
||||
{
|
||||
var newIssue = new NewIssue(IssueTitle);
|
||||
return await _gitHubClient.CreateIssue(newIssue);
|
||||
}
|
||||
|
||||
private async Task UpdateIssue(Issue issue)
|
||||
{
|
||||
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.";
|
||||
|
||||
await _gitHubClient.UpdateIssue(issue.Number, updateIssue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ namespace FilterLists.Agent.Infrastructure.Clients
|
|||
public interface IAgentGitHubClient
|
||||
{
|
||||
Task<IReadOnlyList<Issue>> GetAllIssues(RepositoryIssueRequest repositoryIssueRequest);
|
||||
Task<Issue> CreateIssue(NewIssue newIssue);
|
||||
Task<Issue> UpdateIssue(int issueNumber, IssueUpdate updateIssue);
|
||||
}
|
||||
|
||||
public class AgentGitHubClient : IAgentGitHubClient
|
||||
|
|
@ -30,5 +32,17 @@ public async Task<IReadOnlyList<Issue>> GetAllIssues(RepositoryIssueRequest repo
|
|||
return await _gitHubClient.Issue.GetAllForRepository(_gitHubOptions.RepositoryOwner,
|
||||
_gitHubOptions.Repository, repositoryIssueRequest);
|
||||
}
|
||||
|
||||
public async Task<Issue> CreateIssue(NewIssue newIssue)
|
||||
{
|
||||
return await _gitHubClient.Issue.Create(_gitHubOptions.RepositoryOwner, _gitHubOptions.Repository,
|
||||
newIssue);
|
||||
}
|
||||
|
||||
public async Task<Issue> UpdateIssue(int issueNumber, IssueUpdate updateIssue)
|
||||
{
|
||||
return await _gitHubClient.Issue.Update(_gitHubOptions.RepositoryOwner, _gitHubOptions.Repository,
|
||||
issueNumber, updateIssue);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue