Skip to content

Commit 7de8c99

Browse files
authored
+semver:minor - Log Octokit Requests & Responses (#983)
* Log Octokit Requests & Responses * InnerHandler * InnerHandler
1 parent ce29566 commit 7de8c99

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/ModularPipelines.GitHub/GitHub.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
using Microsoft.Extensions.Http.Logging;
12
using Microsoft.Extensions.Options;
23
using ModularPipelines.GitHub.Options;
4+
using ModularPipelines.Http;
35
using ModularPipelines.Logging;
46
using Octokit;
57
using Octokit.Internal;
@@ -60,8 +62,27 @@ private IGitHubClient InitializeClient()
6062
?? EnvironmentVariables.Token
6163
?? throw new ArgumentException("No GitHub access token or GITHUB_TOKEN found in environment variables.");
6264

63-
var client = new GitHubClient(new ProductHeaderValue("ModularPipelines"),
64-
new InMemoryCredentialStore(new Credentials(token)));
65+
var connection = new Connection(new ProductHeaderValue("ModularPipelines"),
66+
new HttpClientAdapter(() =>
67+
{
68+
var moduleLogger = _moduleLoggerProvider.GetLogger();
69+
70+
return new RequestLoggingHttpHandler(moduleLogger)
71+
{
72+
InnerHandler = new ResponseLoggingHttpHandler(moduleLogger)
73+
{
74+
InnerHandler = new StatusCodeLoggingHttpHandler(moduleLogger)
75+
{
76+
InnerHandler = new HttpClientHandler(),
77+
},
78+
},
79+
};
80+
}));
81+
82+
var client = new GitHubClient(connection)
83+
{
84+
Credentials = new Credentials(token),
85+
};
6586

6687
return client;
6788
}

src/ModularPipelines/ModularPipelines.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
<Description>Write your pipelines in C#!</Description>
77
</PropertyGroup>
88
<ItemGroup>
9+
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
10+
<_Parameter1>ModularPipelines.GitHub</_Parameter1>
11+
</AssemblyAttribute>
912
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
1013
<_Parameter1>ModularPipelines.UnitTests</_Parameter1>
1114
</AssemblyAttribute>

0 commit comments

Comments
 (0)