fix: getting tangled stats from our backend#981
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
📝 WalkthroughWalkthroughThe client-side composable 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
server/api/atproto/tangled-stats/[owner]/[...repo].ts (1)
49-51: Consider logging failed Constellation lookups for debugging.Whilst silently failing is appropriate for user-facing behaviour, having no visibility into Constellation failures may make debugging production issues difficult.
💡 Optional: Add debug logging
- } catch { - //failing silently since this is just an enhancement to the information already showing + } catch (e) { + // Failing silently since this is just an enhancement to the information already showing + console.debug('Constellation lookup failed for', atUri, e) }
| @@ -0,0 +1,64 @@ | |||
| import type { CachedFetchFunction } from '#shared/utils/fetch-cache-config' | |||
There was a problem hiding this comment.
Missing imports will cause compilation and runtime errors.
The file uses CachedFetchResult<T> (line 17) and Constellation (line 44) but neither is imported. This will cause TypeScript compilation errors and runtime failures.
🐛 Proposed fix to add missing imports
-import type { CachedFetchFunction } from '#shared/utils/fetch-cache-config'
+import type { CachedFetchFunction, CachedFetchResult } from '#shared/utils/fetch-cache-config'
+import { Constellation } from '#shared/utils/constellation'📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| import type { CachedFetchFunction } from '#shared/utils/fetch-cache-config' | |
| import type { CachedFetchFunction, CachedFetchResult } from '#shared/utils/fetch-cache-config' | |
| import { Constellation } from '#shared/utils/constellation' |
There was a problem hiding this comment.
@trueberryless, understood! I'll skip this suggestion.
| let owner = getRouterParam(event, 'owner') | ||
| let repo = getRouterParam(event, 'repo') |
There was a problem hiding this comment.
Validate owner and repo parameters before use.
getRouterParam can return undefined. Using undefined values directly in the URL (line 27) would result in https://tangled.org/undefined/undefined. Return an error response early if parameters are missing.
🛡️ Proposed fix to validate parameters
- let owner = getRouterParam(event, 'owner')
- let repo = getRouterParam(event, 'repo')
+ const owner = getRouterParam(event, 'owner')
+ const repo = getRouterParam(event, 'repo')
+
+ if (!owner || !repo) {
+ return { stars: 0, forks: 0 }
+ }As per coding guidelines, ensure you write strictly type-safe code, for example by ensuring you always check when accessing values that may be undefined.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| let owner = getRouterParam(event, 'owner') | |
| let repo = getRouterParam(event, 'repo') | |
| const owner = getRouterParam(event, 'owner') | |
| const repo = getRouterParam(event, 'repo') | |
| if (!owner || !repo) { | |
| return { stars: 0, forks: 0 } | |
| } |
cb1f1a8 to
d3e9698
Compare
trueberryless
left a comment
There was a problem hiding this comment.
LGTM 🎉
Nice refactor. I think the one Rabbit comment can just be resolved 👍
Resolves: #844
The easiest way to get a at-uri for a tangled repo is from calling their webpage and parsing it out of the HTML. Moved this to the backend to resolve the current CORS errors.
I debated adding tangled.org to the cached fetch so that the HTML response can be cached, but that seems like a pretty big cached entry and I think in prod API endpoints are cached for a while.
Test repo:
@weaver.sh/editor-collab