Skip to content

Commit 38ca863

Browse files
mohnjilesclaude
andcommitted
Use Octokit for the docs tree fetch instead of a custom Refit client
The app already ships Octokit; Git.Tree.GetRecursive covers what the hand-rolled IGitHubContentApi + GitHubTreeResponse did, so both are removed along with their Refit registration. Page markdown still comes from raw.githubusercontent.com, which is not subject to the anonymous API rate limit. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 4141738 commit 38ca863

4 files changed

Lines changed: 14 additions & 86 deletions

File tree

StabilityMatrix.Avalonia/App.axaml.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -842,15 +842,6 @@ internal static IServiceCollection ConfigureServices(bool disableMessagePipeInte
842842
})
843843
.AddPolicyHandler(retryPolicy);
844844

845-
services
846-
.AddRefitClient<IGitHubContentApi>(defaultRefitSettings)
847-
.ConfigureHttpClient(c =>
848-
{
849-
c.BaseAddress = new Uri("https://api.github.com");
850-
c.Timeout = TimeSpan.FromMinutes(1);
851-
})
852-
.AddPolicyHandler(retryPolicy);
853-
854845
services
855846
.AddRefitClient<IHuggingFaceApi>(defaultRefitSettings) // Assuming defaultRefitSettings is suitable
856847
.ConfigureHttpClient(c =>

StabilityMatrix.Core/Api/IGitHubContentApi.cs

Lines changed: 0 additions & 25 deletions
This file was deleted.

StabilityMatrix.Core/Models/Api/GitHubTreeResponse.cs

Lines changed: 0 additions & 41 deletions
This file was deleted.

StabilityMatrix.Core/Services/DocumentationService.cs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
using System.Threading.Tasks;
1010
using Injectio.Attributes;
1111
using Microsoft.Extensions.Logging;
12-
using Refit;
13-
using StabilityMatrix.Core.Api;
14-
using StabilityMatrix.Core.Models.Api;
12+
using Octokit;
1513
using StabilityMatrix.Core.Models.Documentation;
1614
using StabilityMatrix.Core.Models.FileInterfaces;
1715

@@ -20,7 +18,7 @@ namespace StabilityMatrix.Core.Services;
2018
[RegisterSingleton<IDocumentationService, DocumentationService>]
2119
public class DocumentationService(
2220
ILogger<DocumentationService> logger,
23-
IGitHubContentApi gitHubContentApi,
21+
IGitHubClient gitHubClient,
2422
IHttpClientFactory httpClientFactory
2523
) : IDocumentationService
2624
{
@@ -135,27 +133,32 @@ public async Task<string> GetPageMarkdownAsync(
135133

136134
private async Task<List<string>> FetchDocsPathsAsync(CancellationToken cancellationToken)
137135
{
138-
GitHubTreeResponse tree;
136+
// Octokit calls don't take a CancellationToken; the tree response is small and
137+
// the surrounding cache logic still honors cancellation.
138+
TreeResponse tree;
139139
try
140140
{
141-
tree = await gitHubContentApi
142-
.GetTree(
141+
tree = await gitHubClient
142+
.Git.Tree.GetRecursive(
143143
DocumentationConstants.Owner,
144144
DocumentationConstants.Repo,
145-
DocumentationConstants.Branch,
146-
cancellationToken: cancellationToken
145+
DocumentationConstants.Branch
147146
)
148147
.ConfigureAwait(false);
149148
}
150-
catch (ApiException e) when (e.StatusCode == HttpStatusCode.NotFound)
149+
catch (NotFoundException e)
151150
{
152151
throw new DocumentationNotAvailableException("Documentation repository or branch not found.", e);
153152
}
154153

154+
cancellationToken.ThrowIfCancellationRequested();
155+
155156
var prefix = DocumentationConstants.DocsRoot + "/";
156157

157158
var paths = tree
158-
.Tree.Where(item => item.IsBlob && item.Path.StartsWith(prefix, StringComparison.Ordinal))
159+
.Tree.Where(item =>
160+
item.Type == TreeType.Blob && item.Path.StartsWith(prefix, StringComparison.Ordinal)
161+
)
159162
.Select(item => item.Path[prefix.Length..])
160163
.Where(IsDocPage)
161164
.ToList();

0 commit comments

Comments
 (0)