Skip to content

fix: getting tangled stats from our backend#981

Merged
danielroe merged 3 commits intonpmx-dev:mainfrom
fatfingers23:bug/tangled-stats
Feb 5, 2026
Merged

fix: getting tangled stats from our backend#981
danielroe merged 3 commits intonpmx-dev:mainfrom
fatfingers23:bug/tangled-stats

Conversation

@fatfingers23
Copy link
Member

@fatfingers23 fatfingers23 commented Feb 5, 2026

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

@vercel
Copy link

vercel bot commented Feb 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
npmx.dev Ready Ready Preview, Comment Feb 5, 2026 1:06pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs.npmx.dev Ignored Ignored Preview Feb 5, 2026 1:06pm
npmx-lunaria Ignored Ignored Feb 5, 2026 1:06pm

Request Review

@codecov
Copy link

codecov bot commented Feb 5, 2026

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
app/composables/useRepoMeta.ts 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@fatfingers23 fatfingers23 marked this pull request as ready for review February 5, 2026 03:23
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 5, 2026

📝 Walkthrough

Walkthrough

The client-side composable useRepoMeta now calls a server endpoint /api/atproto/tangled-stats/{owner}/{repo} to obtain repository metadata instead of performing HTML scraping or Constellation lookups itself. A new server route server/api/atproto/tangled-stats/[owner]/[...repo].ts was added; it fetches Tangled repo HTML, extracts an initial star count and any at‑uri, and conditionally uses a Constellation lookup to augment stars and forks. The API returns { stars, forks }, defaulting to zeros on fetch, parse or augmentation errors.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The pull request description clearly relates to the changeset, explaining the CORS issue with tangled stats and the decision to move logic to the backend.
Linked Issues check ✅ Passed The PR successfully addresses issue #844 by moving tangled stats fetching from client-side to backend, resolving CORS errors and restoring stars/fork count loading.
Out of Scope Changes check ✅ Passed All changes are scoped to resolving the tangled stats CORS issue; no unrelated modifications are present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'
Copy link
Contributor

@coderabbitai coderabbitai bot Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

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.

Suggested change
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'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore it…

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@trueberryless, understood! I'll skip this suggestion.

Comment on lines +4 to +5
let owner = getRouterParam(event, 'owner')
let repo = getRouterParam(event, 'repo')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

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.

Suggested change
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 }
}

Copy link
Contributor

@trueberryless trueberryless left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎉

Nice refactor. I think the one Rabbit comment can just be resolved 👍

@danielroe danielroe added this pull request to the merge queue Feb 5, 2026
Merged via the queue into npmx-dev:main with commit 115c1c4 Feb 5, 2026
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: tangled.org stars & fork count no longer load in

3 participants