feat: add askgh_repo_index_requested PostHog event - #1658
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Essentials Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review. WalkthroughThe web worker API now emits ChangesRepository indexing telemetry
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Feature Suggested reviewers: Merge Risk: ⚪ Minimal · up to The endpoint now records repository-indexing requests while preserving response validation. No actionable merge-blocking risk remains. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Emit a new PostHog event when Ask GH requests a repo index via POST /api/experimental/add-github-repo. The event includes: - owner: GitHub repo owner - repo: GitHub repo name - repoName: Combined owner/repo string - isAnonymous: Whether the requester is authenticated - anonymousCreatorId: Anonymous session ID (when anonymous) - repoId: Created repo ID This enables tracking who requested indexing of repos through Ask GH. Co-authored-by: Michael Sukkarieh <msukkari@users.noreply.github.com>
Remove identity properties (isAnonymous, anonymousCreatorId, userId, email) since PostHog's built-in distinct_id from captureEvent already handles requester identification. Keep only repo fields: owner, repo, repoName, repoId. Co-authored-by: Michael Sukkarieh <msukkari@users.noreply.github.com>
a86cf5b to
f374239
Compare
|
@cursor[bot] your pull request is missing a changelog! |
Keep only repo identity fields: owner, repo, repoName. Co-authored-by: Michael Sukkarieh <msukkari@users.noreply.github.com>
…able Move captureEvent above schema parse and return schema.parse(data) directly. Co-authored-by: Michael Sukkarieh <msukkari@users.noreply.github.com>
There was a problem hiding this comment.
1 issue found across 1 file (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/web/src/features/workerApi/actions.ts">
<violation number="1" location="packages/web/src/features/workerApi/actions.ts:38">
P3: The `askgh_repo_index_requested` event now fires before the response body is parsed/validated, whereas it previously fired only after `schema.parse(data)` succeeded. If `response.json()` or the zod parse throws (malformed 2xx body), `addGithubRepo` fails for the caller but the event still records the index as requested, skewing analytics. The move appears to be an unintended side effect of removing the intermediate `result` variable — restore the original order so the event only fires on a fully successful index request.</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
| repoName: `${owner}/${repo}`, | ||
| }); | ||
|
|
||
| const data = await response.json(); |
There was a problem hiding this comment.
P3: The askgh_repo_index_requested event now fires before the response body is parsed/validated, whereas it previously fired only after schema.parse(data) succeeded. If response.json() or the zod parse throws (malformed 2xx body), addGithubRepo fails for the caller but the event still records the index as requested, skewing analytics. The move appears to be an unintended side effect of removing the intermediate result variable — restore the original order so the event only fires on a fully successful index request.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/web/src/features/workerApi/actions.ts, line 38:
<comment>The `askgh_repo_index_requested` event now fires before the response body is parsed/validated, whereas it previously fired only after `schema.parse(data)` succeeded. If `response.json()` or the zod parse throws (malformed 2xx body), `addGithubRepo` fails for the caller but the event still records the index as requested, skewing analytics. The move appears to be an unintended side effect of removing the intermediate `result` variable — restore the original order so the event only fires on a fully successful index request.</comment>
<file context>
@@ -29,19 +29,17 @@ export const addGithubRepo = async (owner: string, repo: string) => sew(() =>
});
- return result;
+ const data = await response.json();
+ const schema = z.object({
+ jobId: z.string(),
</file context>
Fixes SOU-2252
Related: https://linear.app/sourcebot/issue/SOU-2252/add-ability-to-track-who-caused-a-repo-to-be-indexed-in-public-saas
Summary
Add a new PostHog event (
askgh_repo_index_requested) that fires when Ask GH requests that a repo be indexed through thePOST /api/experimental/add-github-repoendpoint.Problem
On the public app (app.sourcebot.dev), repos can be indexed via Ask GH but there was no PostHog event that attributes who requested the index. We couldn't answer "who requested indexing of torvalds/linux?"
Solution
Emit a PostHog event at the moment an Ask GH index is requested. Requester identity is handled automatically by PostHog's
distinct_id(viacaptureEvent/tryGetPostHogDistinctId), so the event payload only needs repo context.Event Name
askgh_repo_index_requestedProperties
ownerreporepoNameowner/repostring for easy filteringRequester identity (signed-in vs anonymous) is inferred from PostHog's built-in
distinct_id.Querying in PostHog
Find all index requests for a specific repo:
Find requests by a specific user:
Filter by
distinct_id(user id for signed-in, install id for anonymous).Where it fires
packages/web/src/features/workerApi/actions.ts- in theaddGithubReposerver action, after the backend successfully processes the repo index request.Testing
captureEventhelper which automatically handles identity viatryGetPostHogDistinctIdSummary by cubic
Tracks successful Ask GH repo index requests in PostHog so we can attribute who requested indexing.
askgh_repo_index_requestedafter the index request is processed, capturingowner,repo, andrepoName.captureEvent, so no custom identity properties are tracked.Written for commit 3add2ba. Summary will update on new commits.
Summary by CodeRabbit