refactor: utilizes anonymous gh access and then fallback to our token#2599
refactor: utilizes anonymous gh access and then fallback to our token#2599
Conversation
📝 WalkthroughWalkthroughRefactors GitHub credential handling: workflow now prefers Changes
Sequence Diagram(s)sequenceDiagram
participant Service as TemplateFetcherService
participant Anonymous as Anonymous Octokit
participant Primary as Authenticated Octokit
participant GH as GitHub API
Service->>Service: fetchFileContent(path, ref)
Service->>Anonymous: getContent(path, ref) (no auth)
Anonymous->>GH: HTTP request (unauthenticated)
alt Anonymous returns content
GH-->>Anonymous: 200 + content
Anonymous-->>Service: content (return)
else Anonymous fails (404/403/etc.)
GH-->>Anonymous: error
Anonymous-->>Service: error
Service->>Primary: getContent(path, ref) (with PAT)
Primary->>GH: HTTP request (authenticated)
GH-->>Primary: 200 + content / error
Primary-->>Service: content or error
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@apps/api/src/template/services/template-fetcher/template-fetcher.service.ts`:
- Around line 91-107: The early-return condition in private method
`#fetchFileContentAnonymously` is inverted: change the guard from "if
(!this.#isAnonymousOctokitFailed) return;" to "if
(this.#isAnonymousOctokitFailed) return;" so anonymous fetching is attempted
unless it previously failed; keep using
this.#fetchFileContentUsing(this.#anonymousOctokit, params) and preserve the
catch logic that sets this.#isAnonymousOctokitFailed = true and logs via
this.#logger.warn with the same event, owner, repo, path, ref, and error fields.
🧹 Nitpick comments (2)
apps/api/src/template/services/template-fetcher/template-fetcher.service.ts (1)
160-164: Avoid usinganyreturn type.The return type
Promise<any>violates coding guidelines. Based on usage, this should returnPromise<Template | null>.♻️ Proposed fix
private async processTemplateSource( templateSource: TemplateSource, directoryItems: GithubDirectoryItem[], options: { includeConfigJson?: boolean } - ): Promise<any> { + ): Promise<Template | null> {As per coding guidelines: "Never use type
anyor cast to typeany. Always define the proper TypeScript types."apps/api/src/template/services/template-fetcher/template-fetcher.service.spec.ts (1)
13-82: Consider adding tests for anonymous fallback behavior.The new anonymous-first fetching strategy with fallback to authenticated requests is a key part of this PR. Consider adding tests that verify:
- Anonymous fetch is attempted first
- Fallback to authenticated occurs when anonymous fails
- Once anonymous fails, subsequent calls skip anonymous and go directly to authenticated
This would help catch issues like the inverted condition bug.
apps/api/src/template/services/template-fetcher/template-fetcher.service.ts
Show resolved
Hide resolved
9eb12fd to
4faa647
Compare
Codecov Report❌ Patch coverage is
❌ Your patch status has failed because the patch coverage (79.16%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #2599 +/- ##
==========================================
- Coverage 50.01% 49.69% -0.32%
==========================================
Files 1024 1014 -10
Lines 28976 28636 -340
Branches 6620 6562 -58
==========================================
- Hits 14492 14231 -261
+ Misses 14205 14025 -180
- Partials 279 380 +101
*This pull request uses carry forward flags. Click here to find out more.
🚀 New features to boost your workflow:
|
Why
To fight against gh rate limiting
Summary by CodeRabbit
New Features
Improvements
Tests
✏️ Tip: You can customize this high-level summary in your review settings.