diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b6b0bf76..29730aad 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,6 +21,9 @@ jobs: with: dotnet-version: '8.x.x' + - name: Format + run: dotnet format --verify-no-changes + - name: Build and strong name sign run: dotnet build --no-incremental /p:SignAssembly=true /p:AssemblyOriginatorKeyFile=../key.snk diff --git a/Tests/Client/ClientFactoryTest.cs b/Tests/Client/ClientFactoryTest.cs index 80498751..f417bd01 100644 --- a/Tests/Client/ClientFactoryTest.cs +++ b/Tests/Client/ClientFactoryTest.cs @@ -1,22 +1,22 @@ -using Xunit; using GitHub.Octokit.Client; +using Xunit; public class ClientFactoryTests { - [Fact] - public void Creates_Client_With_Default_Timeout() - { - var clientFactory = ClientFactory.Create(); - Assert.Equal(TimeSpan.FromSeconds(100), clientFactory.Timeout); - } + [Fact] + public void Creates_Client_With_Default_Timeout() + { + var clientFactory = ClientFactory.Create(); + Assert.Equal(TimeSpan.FromSeconds(100), clientFactory.Timeout); + } - [Fact] - public void Creates_Client_Persists_Set_Timeout() - { - var clientFactory = ClientFactory.Create(); - clientFactory.Timeout = TimeSpan.FromSeconds(5); - Assert.Equal(TimeSpan.FromSeconds(5), clientFactory.Timeout); - } + [Fact] + public void Creates_Client_Persists_Set_Timeout() + { + var clientFactory = ClientFactory.Create(); + clientFactory.Timeout = TimeSpan.FromSeconds(5); + Assert.Equal(TimeSpan.FromSeconds(5), clientFactory.Timeout); + } -} \ No newline at end of file +} diff --git a/Tests/Client/RequestAdaptorTest.cs b/Tests/Client/RequestAdaptorTest.cs index 8dd37690..6bbbc698 100644 --- a/Tests/Client/RequestAdaptorTest.cs +++ b/Tests/Client/RequestAdaptorTest.cs @@ -1,32 +1,32 @@ -using Xunit; -using GitHub.Octokit.Client; using GitHub.Octokit.Authentication; +using GitHub.Octokit.Client; using NSubstitute; +using Xunit; public class RequestAdapterTests { - [Fact] - public void Creates_RequestAdaptor_With_Defaults() - { - var requestAdapter = RequestAdapter.Create(new TokenAuthenticationProvider("Octokit.Gen", "JRRTOLKIEN")); - Assert.NotNull(requestAdapter); - } + [Fact] + public void Creates_RequestAdaptor_With_Defaults() + { + var requestAdapter = RequestAdapter.Create(new TokenAuthenticationProvider("Octokit.Gen", "JRRTOLKIEN")); + Assert.NotNull(requestAdapter); + } - [Fact] - public void Creates_RequestAdaptor_With_GenericHttpClient() - { - var httpClient = Substitute.For(); - var requestAdapter = RequestAdapter.Create(new TokenAuthenticationProvider("Octokit.Gen", "JRRTOLKIEN"), httpClient); - Assert.NotNull(requestAdapter); - } + [Fact] + public void Creates_RequestAdaptor_With_GenericHttpClient() + { + var httpClient = Substitute.For(); + var requestAdapter = RequestAdapter.Create(new TokenAuthenticationProvider("Octokit.Gen", "JRRTOLKIEN"), httpClient); + Assert.NotNull(requestAdapter); + } - [Fact] - public void Creates_RequestAdaptor_With_ClientFactory() - { - var clientFactory = ClientFactory.Create(); - var requestAdapter = RequestAdapter.Create(new TokenAuthenticationProvider("Octokit.Gen", "JRRTOLKIEN"), clientFactory); - Assert.NotNull(requestAdapter); - } + [Fact] + public void Creates_RequestAdaptor_With_ClientFactory() + { + var clientFactory = ClientFactory.Create(); + var requestAdapter = RequestAdapter.Create(new TokenAuthenticationProvider("Octokit.Gen", "JRRTOLKIEN"), clientFactory); + Assert.NotNull(requestAdapter); + } -} \ No newline at end of file +} diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 52967d46..093668ea 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -14,6 +14,12 @@ false true + true + true + true + + $(NoWarn);CS0618 diff --git a/script/format.sh b/script/format.sh new file mode 100755 index 00000000..9ff11370 --- /dev/null +++ b/script/format.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +# GitHub Actions performs formatting in .github/workflows/build.yml. +# This script may be used to update files before pushing to a PR check. +dotnet format diff --git a/src/Authentication/TokenAuthenticationProvider.cs b/src/Authentication/TokenAuthenticationProvider.cs index 87b2a41f..6375812d 100644 --- a/src/Authentication/TokenAuthenticationProvider.cs +++ b/src/Authentication/TokenAuthenticationProvider.cs @@ -22,7 +22,7 @@ public class TokenAuthenticationProvider : IAuthenticationProvider /// Gets or sets the client identifier. /// public string ClientId { get; set; } - + /// /// Gets or sets the token. /// diff --git a/src/Client/ClientFactory.cs b/src/Client/ClientFactory.cs index e0039485..aae8627e 100644 --- a/src/Client/ClientFactory.cs +++ b/src/Client/ClientFactory.cs @@ -10,8 +10,8 @@ namespace GitHub.Octokit.Client; /// public static class ClientFactory { - private static readonly Lazy> s_handlers = - new(() => + private static readonly Lazy> s_handlers = + new(() => [ new APIVersionHandler(), new UserAgentHandler(), @@ -79,7 +79,7 @@ public static HttpClient Create(HttpMessageHandler? finalHandler = null) /// The collection of instances to chain. /// The first link in the chain of instances. public static DelegatingHandler? ChainHandlersCollectionAndGetFirstLink( - params DelegatingHandler[] handlers) => + params DelegatingHandler[] handlers) => ChainHandlersCollectionAndGetFirstLink(null, handlers); /// diff --git a/src/Client/RequestAdapter.cs b/src/Client/RequestAdapter.cs index 4d7bfd97..c94bd985 100644 --- a/src/Client/RequestAdapter.cs +++ b/src/Client/RequestAdapter.cs @@ -7,22 +7,22 @@ namespace GitHub.Octokit.Client; public static class RequestAdapter { - /// - /// Represents an adapter for making HTTP requests using HttpClient. - /// - /// TODO: Implement the missing props and methods - public static HttpClientRequestAdapter Create(IAuthenticationProvider authenticationProvider, HttpClient? clientFactory = null) - { - clientFactory ??= ClientFactory.Create(); + /// + /// Represents an adapter for making HTTP requests using HttpClient. + /// + /// TODO: Implement the missing props and methods + public static HttpClientRequestAdapter Create(IAuthenticationProvider authenticationProvider, HttpClient? clientFactory = null) + { + clientFactory ??= ClientFactory.Create(); - var gitHubRequestAdapter = - new HttpClientRequestAdapter( - authenticationProvider, - null, // Node Parser - null, // Serializer - clientFactory, - null); - - return gitHubRequestAdapter; - } + var gitHubRequestAdapter = + new HttpClientRequestAdapter( + authenticationProvider, + null, // Node Parser + null, // Serializer + clientFactory, + null); + + return gitHubRequestAdapter; + } } diff --git a/src/GitHub.Octokit.SDK.csproj b/src/GitHub.Octokit.SDK.csproj index fa3b51dc..86284323 100644 --- a/src/GitHub.Octokit.SDK.csproj +++ b/src/GitHub.Octokit.SDK.csproj @@ -1,41 +1,47 @@ - - - Library - net8.0 - enable - enable - GitHub.Octokit.SDK - 0.0.1-alpha - 0.0.1-alpha - Octokit - - This is an auto-generated SDK for GitHub's REST API, built on Kiota. - - GitHub - GitHub API Octokit dotnet-core - https://github.com/octokit/dotnet-sdk - https://github.com/octokit/dotnet-sdk - octokit.png - MIT - NugetREADME.md - Copyright (c) GitHub 2023 - - - - true - true - true - - - - - - - - - - - - - - + + + Library + net8.0 + enable + enable + GitHub.Octokit.SDK + 0.0.1-alpha + 0.0.1-alpha + Octokit + + This is an auto-generated SDK for GitHub's REST API, built on Kiota. + + GitHub + GitHub API Octokit dotnet-core + https://github.com/octokit/dotnet-sdk + https://github.com/octokit/dotnet-sdk + octokit.png + MIT + NugetREADME.md + Copyright (c) GitHub 2023 + + + + true + true + true + true + true + true + + $(NoWarn);CS0618 + + + + + + + + + + + + + + diff --git a/src/Middleware/Options/APIVersionOptions.cs b/src/Middleware/Options/APIVersionOptions.cs index e83e85c7..659ceac0 100644 --- a/src/Middleware/Options/APIVersionOptions.cs +++ b/src/Middleware/Options/APIVersionOptions.cs @@ -17,4 +17,4 @@ public class APIVersionOptions : IRequestOption private static string GetAPIVersion() => //TODO : Get the version from the generator "2022-11-28"; -} \ No newline at end of file +} diff --git a/src/Middleware/Options/UserAgentOptions.cs b/src/Middleware/Options/UserAgentOptions.cs index 0f5e09b4..56ac333f 100644 --- a/src/Middleware/Options/UserAgentOptions.cs +++ b/src/Middleware/Options/UserAgentOptions.cs @@ -21,4 +21,4 @@ public class UserAgentOptions : IRequestOption public string ProductVersion { get; set; } = GetProductVersion(); private static string GetProductVersion() => "0.0.0"; -} \ No newline at end of file +} diff --git a/src/Middleware/UserAgentHandler.cs b/src/Middleware/UserAgentHandler.cs index 360dd5ca..7097a296 100644 --- a/src/Middleware/UserAgentHandler.cs +++ b/src/Middleware/UserAgentHandler.cs @@ -16,7 +16,7 @@ protected override Task SendAsync(HttpRequestMessage reques var userAgentHandlerOption = request.GetRequestOption() ?? _userAgentOption; - if(!request.Headers.UserAgent.Any(x => userAgentHandlerOption.ProductName.Equals(x.Product?.Name, StringComparison.OrdinalIgnoreCase))) + if (!request.Headers.UserAgent.Any(x => userAgentHandlerOption.ProductName.Equals(x.Product?.Name, StringComparison.OrdinalIgnoreCase))) { request.Headers.UserAgent.Add(new ProductInfoHeaderValue(userAgentHandlerOption.ProductName, userAgentHandlerOption.ProductVersion)); }