Skip to content

feat(web): add PostHog event for askgh repo index trigger#936

Open
msukkari wants to merge 4 commits intomainfrom
michael/askgh-repo-index-triggered-event
Open

feat(web): add PostHog event for askgh repo index trigger#936
msukkari wants to merge 4 commits intomainfrom
michael/askgh-repo-index-triggered-event

Conversation

@msukkari
Copy link
Contributor

@msukkari msukkari commented Feb 25, 2026

Summary

  • Adds a new wa_askgh_repo_index_triggered PostHog event that fires when a user triggers a new repository to be indexed in the Ask GitHub flow
  • Event includes owner, repo, and repoId properties
  • Only fires when the repo is newly created (not when visiting an already-existing repo)

Test plan

  • Visit an askgh page for a repo that hasn't been indexed yet and verify the wa_askgh_repo_index_triggered event appears in PostHog
  • Visit an askgh page for an already-indexed repo and verify the event does NOT fire

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added analytics event tracking for repository indexing in Ask GitHub, capturing when users initiate repository indexing to provide insights into indexing workflow engagement.

Fires `wa_askgh_repo_index_triggered` with owner, repo, and repoId
when a user triggers a new repository to be indexed in the Ask GitHub
flow (i.e., when `addGithubRepo` is called for a repo that doesn't
yet exist).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions

This comment has been minimized.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 25, 2026

Walkthrough

The PR adds PostHog event tracking for when a repository is newly triggered for indexing in Ask GitHub. It introduces a new event definition (wa_askgh_repo_index_triggered), updates the RepoIndexedGuard component to fire this event once upon trigger, and modifies the page logic to track and communicate trigger status.

Changes

Cohort / File(s) Summary
Event Definition & Documentation
CHANGELOG.md, packages/web/src/lib/posthogEvents.ts
Added new PostHog event wa_askgh_repo_index_triggered with repo and repoId fields to track when a repository is newly triggered for indexing.
Component Event Firing
packages/web/src/app/[domain]/askgh/[owner]/[repo]/components/repoIndexedGuard.tsx
Added isNewlyTriggered and repoFullName props to RepoIndexedGuard; implemented useRef and useEffect to fire a one-time PostHog event when a repo is newly triggered.
Page Logic & Props
packages/web/src/app/[domain]/askgh/[owner]/[repo]/page.tsx
Modified repository lookup/creation logic to return { repoId, isNewlyTriggered } instead of just repoId; updated RepoIndexedGuard invocation to pass isNewlyTriggered and repoFullName props.

Sequence Diagram

sequenceDiagram
    participant Page
    participant RepoIndexedGuard
    participant PostHog
    
    Page->>Page: Lookup or create repo
    Note over Page: Determine repoId and isNewlyTriggered
    Page->>RepoIndexedGuard: Render with isNewlyTriggered=true/false
    
    alt isNewlyTriggered = true
        RepoIndexedGuard->>RepoIndexedGuard: useEffect detects trigger
        RepoIndexedGuard->>PostHog: captureEvent(wa_askgh_repo_index_triggered)
        PostHog-->>RepoIndexedGuard: Event recorded
    else isNewlyTriggered = false
        Note over RepoIndexedGuard: No event fired
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • PR #785: Directly modifies the same RepoIndexedGuard component and page.tsx flow to add the isNewlyTriggered and repoFullName props and one-time PostHog event tracking.
  • PR #882: Adds PostHog event capturing and updates to posthogEvents.ts that align with the captureEvent utilities used in this PR's RepoIndexedGuard implementation.
  • PR #933: Modifies the same repoIndexedGuard component and posthogEvents.ts to emit Ask GitHub PostHog events, with this PR handling trigger events and the related PR handling completion events.
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately summarizes the main change: adding a PostHog event for Ask GitHub repository index triggering. The title is concise, specific, and directly reflects the primary objective of the changeset.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch michael/askgh-repo-index-triggered-event

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…dex-triggered-event

# Conflicts:
#	CHANGELOG.md
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.

🧹 Nitpick comments (1)
packages/web/src/app/[domain]/askgh/[owner]/[repo]/page.tsx (1)

25-25: Extract the duplicated `${owner}/${repo}` string.

displayName on line 25 and the inline repoFullName prop on line 54 compute the same string. Hoist it to a shared variable.

♻️ Proposed refactor
-    const displayName = `${owner}/${repo}`;
+    const repoFullName = `${owner}/${repo}`;
     const existingRepo = await prisma.repo.findFirst({
         where: {
             orgId: SINGLE_TENANT_ORG_ID,
-            displayName: displayName,
+            displayName: repoFullName,
             external_codeHostType: 'github',
             external_codeHostUrl: 'https://github.com',
         },
     });
-        <RepoIndexedGuard initialRepoInfo={repoInfo} isNewlyTriggered={isNewlyTriggered} repoFullName={`${owner}/${repo}`}>
+        <RepoIndexedGuard initialRepoInfo={repoInfo} isNewlyTriggered={isNewlyTriggered} repoFullName={repoFullName}>

Also applies to: 54-54

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/web/src/app/`[domain]/askgh/[owner]/[repo]/page.tsx at line 25, The
string interpolation `${owner}/${repo}` is computed twice; consolidate it by
creating a single shared variable (e.g., displayName) and use that variable
wherever the full repo name is needed (replace the inline repoFullName prop
value and any other occurrences), update the existing const displayName =
`${owner}/${repo}` and pass displayName into the component props instead of
recomputing the template string.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/web/src/app/`[domain]/askgh/[owner]/[repo]/page.tsx:
- Line 25: The string interpolation `${owner}/${repo}` is computed twice;
consolidate it by creating a single shared variable (e.g., displayName) and use
that variable wherever the full repo name is needed (replace the inline
repoFullName prop value and any other occurrences), update the existing const
displayName = `${owner}/${repo}` and pass displayName into the component props
instead of recomputing the template string.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6208955 and 3b54729.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • packages/web/src/app/[domain]/askgh/[owner]/[repo]/components/repoIndexedGuard.tsx
  • packages/web/src/app/[domain]/askgh/[owner]/[repo]/page.tsx
  • packages/web/src/lib/posthogEvents.ts

wa_askgh_login_wall_prompted: {},
wa_askgh_repo_index_triggered: {
repo: string,
repoId: number,
Copy link
Contributor

@brendan-kellam brendan-kellam Feb 25, 2026

Choose a reason for hiding this comment

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

nit: I would use repo name instead of the repo's id since it is opaque

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.

2 participants