From 2da9f7ca82a3ecd3faa9ed8ef32c4660eba99f72 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 25 Jan 2021 17:23:04 -0500 Subject: [PATCH] Fix GitHubAccessToken never being used --- .../Core/GitHubClientFactory.cs | 46 +++++++++++-------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/src/Tgstation.Server.Host/Core/GitHubClientFactory.cs b/src/Tgstation.Server.Host/Core/GitHubClientFactory.cs index 218a19bf4f..90423ac8d4 100644 --- a/src/Tgstation.Server.Host/Core/GitHubClientFactory.cs +++ b/src/Tgstation.Server.Host/Core/GitHubClientFactory.cs @@ -1,5 +1,7 @@ using System; +using Microsoft.Extensions.Options; using Octokit; +using Tgstation.Server.Host.Configuration; using Tgstation.Server.Host.System; namespace Tgstation.Server.Host.Core @@ -12,35 +14,43 @@ namespace Tgstation.Server.Host.Core /// readonly IAssemblyInformationProvider assemblyInformationProvider; + /// + /// The for the . + /// + readonly GeneralConfiguration generalConfiguration; + /// /// Construct a /// - /// The value of - public GitHubClientFactory(IAssemblyInformationProvider assemblyInformationProvider) + /// The value of . + /// + public GitHubClientFactory(IAssemblyInformationProvider assemblyInformationProvider, IOptions generalConfigurationOptions) { this.assemblyInformationProvider = assemblyInformationProvider ?? throw new ArgumentNullException(nameof(assemblyInformationProvider)); + generalConfiguration = generalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(generalConfigurationOptions)); } /// - /// Create a + /// Create a . /// + /// Optional access token to use as credentials. /// A new - GitHubClient CreateBaseClient() => new GitHubClient( - new ProductHeaderValue( - assemblyInformationProvider.ProductInfoHeaderValue.Product.Name, - assemblyInformationProvider.ProductInfoHeaderValue.Product.Version)); - - /// - public IGitHubClient CreateClient() => CreateBaseClient(); - - /// - public IGitHubClient CreateClient(string accessToken) + GitHubClient CreateClientImpl(string accessToken) { - if (accessToken == null) - throw new ArgumentNullException(nameof(accessToken)); - var result = CreateBaseClient(); - result.Credentials = new Credentials(accessToken); - return result; + var client = new GitHubClient( + new ProductHeaderValue( + assemblyInformationProvider.ProductInfoHeaderValue.Product.Name, + assemblyInformationProvider.ProductInfoHeaderValue.Product.Version)); + if (accessToken != null) + client.Credentials = new Credentials(accessToken); + + return client; } + + /// + public IGitHubClient CreateClient() => CreateClientImpl(generalConfiguration.GitHubAccessToken); + + /// + public IGitHubClient CreateClient(string accessToken) => CreateClientImpl(accessToken ?? throw new ArgumentNullException(nameof(accessToken))); } }