Skip to content

feat(code): unify GitHub connect to auto-pick team vs user flow#2059

Merged
k11kirky merged 1 commit intomainfrom
posthog-code/seamless-github-connect
May 6, 2026
Merged

feat(code): unify GitHub connect to auto-pick team vs user flow#2059
k11kirky merged 1 commit intomainfrom
posthog-code/seamless-github-connect

Conversation

@k11kirky
Copy link
Copy Markdown
Contributor

@k11kirky k11kirky commented May 6, 2026

Problem

When a user with org admin privileges connects GitHub on a project that doesn't yet have a team-level integration, they should go through the team OAuth flow rather than the personal user flow. Previously, all "Connect GitHub" surfaces unconditionally used the user-level flow, meaning admins had no path to set up the shared team integration from within the app.

Changes

  • Extracts org admin role detection into a dedicated useIsOrgAdmin hook (with the ORGANIZATION_ADMIN_LEVEL constant moved there), replacing the inline membership level comparison in App.tsx.
  • Introduces useGithubConnect, a new hook that wraps the existing useGithubUserConnect logic and selects between the team-level OAuth flow (via trpcClient.githubIntegration.startFlow) and the user-level flow based on whether the current user is an org admin and whether the project already has a team integration.
  • Refactors the internal state management of useGithubUserConnect into a useConnectStateMachine helper, making the connect logic composable and reusable across both flows.
  • Replaces all call sites of useGithubUserConnect in DataSourceSetup, GitHubConnectionBanner, GitIntegrationStep, GitHubIntegrationSection, and CloudGithubMissingNotice with useGithubConnect, passing the relevant projectHasTeamIntegration flag so each surface correctly routes admins to the team flow when appropriate.

Copy link
Copy Markdown
Contributor Author

k11kirky commented May 6, 2026

@k11kirky k11kirky marked this pull request as ready for review May 6, 2026 15:32
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 6, 2026

Comments Outside Diff (1)

  1. apps/code/src/renderer/features/onboarding/components/GitIntegrationStep.tsx, line 509-515 (link)

    P1 "Add another GitHub org" triggers team flow for admins

    The "Add another GitHub org" button calls handleConnectGitHub, which comes from useGithubConnect. The hook's own JSDoc says: "For purely user-scoped surfaces ('Add another GitHub org') use useGithubUserConnect directly." When selectedProject?.hasGithubIntegration is false and the current user is an org admin, shouldUseTeamFlow will be true, so clicking this button silently initiates the team-level OAuth instead of adding another personal GitHub org — the opposite of what the label says.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: apps/code/src/renderer/features/onboarding/components/GitIntegrationStep.tsx
    Line: 509-515
    
    Comment:
    **"Add another GitHub org" triggers team flow for admins**
    
    The "Add another GitHub org" button calls `handleConnectGitHub`, which comes from `useGithubConnect`. The hook's own JSDoc says: _"For purely user-scoped surfaces ('Add another GitHub org') use `useGithubUserConnect` directly."_ When `selectedProject?.hasGithubIntegration` is `false` and the current user is an org admin, `shouldUseTeamFlow` will be `true`, so clicking this button silently initiates the team-level OAuth instead of adding another personal GitHub org — the opposite of what the label says.
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
apps/code/src/renderer/features/onboarding/components/GitIntegrationStep.tsx:509-515
**"Add another GitHub org" triggers team flow for admins**

The "Add another GitHub org" button calls `handleConnectGitHub`, which comes from `useGithubConnect`. The hook's own JSDoc says: _"For purely user-scoped surfaces ('Add another GitHub org') use `useGithubUserConnect` directly."_ When `selectedProject?.hasGithubIntegration` is `false` and the current user is an org admin, `shouldUseTeamFlow` will be `true`, so clicking this button silently initiates the team-level OAuth instead of adding another personal GitHub org — the opposite of what the label says.

Reviews (1): Last reviewed commit: "feat(code): unify GitHub connect to auto..." | Re-trigger Greptile

Copy link
Copy Markdown
Contributor Author

k11kirky commented May 6, 2026

Merge activity

  • May 6, 4:56 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • May 6, 5:08 PM UTC: Graphite rebased this pull request as part of a merge.
  • May 6, 5:17 PM UTC: @k11kirky merged this pull request with Graphite.

@k11kirky k11kirky changed the base branch from 05-06-feat_code_fix_flakey_tesk to graphite-base/2059 May 6, 2026 16:57
@k11kirky k11kirky changed the base branch from graphite-base/2059 to main May 6, 2026 17:07
One Connect GitHub button across onboarding, settings, inbox, and task
surfaces — the hook picks the team-level flow when the user is an org
admin and the project has no team integration yet, otherwise the
user-level flow. The team-level flow on PostHog Cloud also creates the
admin's UserIntegration in the same round-trip, so admins finish
onboarding with both records and proactive features start working
immediately. Non-admins still get a working personal connection;
features that require the team integration stay gated by
hasGithubIntegration as before.

Generated-By: PostHog Code
Task-Id: 891f7f13-159c-4ae7-b7e9-cef32fe012b0
@k11kirky k11kirky force-pushed the posthog-code/seamless-github-connect branch from 404a336 to 31a0c50 Compare May 6, 2026 17:08
@k11kirky k11kirky merged commit 0179e2b into main May 6, 2026
16 checks passed
@k11kirky k11kirky deleted the posthog-code/seamless-github-connect branch May 6, 2026 17:17
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