mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
extract AgentGitHubClient
This commit is contained in:
parent
8b773c9639
commit
76df08bd84
4 changed files with 40 additions and 15 deletions
|
|
@ -4,5 +4,7 @@ public class GitHub
|
|||
{
|
||||
public string ProductHeaderValue { get; set; }
|
||||
public string PersonalAccessToken { get; set; }
|
||||
public string RepositoryOwner { get; set; }
|
||||
public string Repository { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -7,7 +7,6 @@
|
|||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Octokit;
|
||||
|
||||
namespace FilterLists.Agent.Extensions
|
||||
{
|
||||
|
|
@ -20,7 +19,7 @@ public static void RegisterAgentServices(this IServiceCollection services)
|
|||
services.AddMediatR(typeof(Program).Assembly);
|
||||
services.AddHttpClient<AgentHttpClient>();
|
||||
services.AddSingleton<IFilterListsApiClient, FilterListsApiClient>();
|
||||
services.AddGitHubClient();
|
||||
services.AddSingleton<IAgentGitHubClient, AgentGitHubClient>();
|
||||
services.AddTransient<IListInfoRepository, ListInfoRepository>();
|
||||
services.AddTransient<IUrlRepository, UrlRepository>();
|
||||
}
|
||||
|
|
@ -48,17 +47,5 @@ private static void AddLoggingCustom(this IServiceCollection services)
|
|||
b.AddApplicationInsights(appInsightsConfig.Value.InstrumentationKey);
|
||||
});
|
||||
}
|
||||
|
||||
private static void AddGitHubClient(this IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<IGitHubClient>(s =>
|
||||
{
|
||||
var gitHubConfig = s.GetService<IOptions<GitHub>>();
|
||||
return new GitHubClient(new ProductHeaderValue(gitHubConfig.Value.ProductHeaderValue))
|
||||
{
|
||||
Credentials = new Credentials(gitHubConfig.Value.PersonalAccessToken)
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using FilterLists.Agent.AppSettings;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Octokit;
|
||||
|
||||
namespace FilterLists.Agent.Infrastructure.Clients
|
||||
{
|
||||
public interface IAgentGitHubClient
|
||||
{
|
||||
Task<IReadOnlyList<Issue>> GetAllIssues(RepositoryIssueRequest repositoryIssueRequest);
|
||||
}
|
||||
|
||||
public class AgentGitHubClient : IAgentGitHubClient
|
||||
{
|
||||
private readonly GitHubClient _gitHubClient;
|
||||
private readonly GitHub _gitHubOptions;
|
||||
|
||||
public AgentGitHubClient(IOptions<GitHub> gitHubOptions)
|
||||
{
|
||||
_gitHubOptions = gitHubOptions.Value;
|
||||
_gitHubClient = new GitHubClient(new ProductHeaderValue(_gitHubOptions.ProductHeaderValue))
|
||||
{
|
||||
Credentials = new Credentials(_gitHubOptions.PersonalAccessToken)
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyList<Issue>> GetAllIssues(RepositoryIssueRequest repositoryIssueRequest)
|
||||
{
|
||||
return await _gitHubClient.Issue.GetAllForRepository(_gitHubOptions.RepositoryOwner,
|
||||
_gitHubOptions.Repository, repositoryIssueRequest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,6 +7,8 @@
|
|||
},
|
||||
"GitHub": {
|
||||
"ProductHeaderValue": "",
|
||||
"OauthToken:": ""
|
||||
"OauthToken:": "",
|
||||
"RepositoryOwner": "",
|
||||
"Repository": ""
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue