Skip to content

feat(code): unify git integration to use git store and always use new git user integration#2050

Open
k11kirky wants to merge 1 commit intomainfrom
05-06-feat_code_unify_git_integration_to_use_git_store_and_always_use_new_git_user_integration
Open

feat(code): unify git integration to use git store and always use new git user integration#2050
k11kirky wants to merge 1 commit intomainfrom
05-06-feat_code_unify_git_integration_to_use_git_store_and_always_use_new_git_user_integration

Conversation

@k11kirky
Copy link
Copy Markdown
Contributor

@k11kirky k11kirky commented May 6, 2026

Problem

GitHub connection state (connecting, timed-out, error) was duplicated across DataSourceSetup and GitHubIntegrationSection, each managing their own polling timers, error handling, and toast notifications independently.

Changes

Extracted the GitHub OAuth connect flow into a shared useGithubUserConnect hook that owns the connection state machine (idle, connecting, timed-out, error) and exposes connect, reset, and a describeGithubConnectError helper.

Both DataSourceSetup and GitHubIntegrationSection now consume this hook instead of managing their own polling refs and state. Error and timeout messages are surfaced inline in the UI rather than via toasts, and the connect button label changes to "Try again" when the flow fails or times out so users can retry without reloading.

Copy link
Copy Markdown
Contributor Author

k11kirky commented May 6, 2026

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

greptile-apps Bot commented May 6, 2026

Comments Outside Diff (2)

  1. apps/code/src/renderer/features/integrations/hooks/useGithubUserConnect.ts, line 156 (link)

    P1 Stale cloudRegion guard blocks the connect flow silently. The new implementation calls client.startGithubUserIntegrationConnect(projectId)cloudRegion is no longer passed to any API, so checking !cloudRegion here is dead code left over from the old trpcClient.githubIntegration.startFlow.mutate({ region: cloudRegion, ... }). If cloudRegion happens to be falsy (e.g. during initial auth hydration or in some environments), the button click will silently do nothing with no user-visible feedback.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: apps/code/src/renderer/features/integrations/hooks/useGithubUserConnect.ts
    Line: 156
    
    Comment:
    Stale `cloudRegion` guard blocks the connect flow silently. The new implementation calls `client.startGithubUserIntegrationConnect(projectId)``cloudRegion` is no longer passed to any API, so checking `!cloudRegion` here is dead code left over from the old `trpcClient.githubIntegration.startFlow.mutate({ region: cloudRegion, ... })`. If `cloudRegion` happens to be falsy (e.g. during initial auth hydration or in some environments), the button click will silently do nothing with no user-visible feedback.
    
    
    
    How can I resolve this? If you propose a fix, please make it concise.
  2. apps/code/src/renderer/features/integrations/hooks/useGithubUserConnect.ts, line 98-100 (link)

    P2 With the !cloudRegion guard removed, this useAuthStateValue subscription is now unused and can be dropped.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: apps/code/src/renderer/features/integrations/hooks/useGithubUserConnect.ts
    Line: 98-100
    
    Comment:
    With the `!cloudRegion` guard removed, this `useAuthStateValue` subscription is now unused and can be dropped.
    
    
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
Fix the following 5 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 5
apps/code/src/renderer/features/integrations/hooks/useGithubUserConnect.ts:156
Stale `cloudRegion` guard blocks the connect flow silently. The new implementation calls `client.startGithubUserIntegrationConnect(projectId)``cloudRegion` is no longer passed to any API, so checking `!cloudRegion` here is dead code left over from the old `trpcClient.githubIntegration.startFlow.mutate({ region: cloudRegion, ... })`. If `cloudRegion` happens to be falsy (e.g. during initial auth hydration or in some environments), the button click will silently do nothing with no user-visible feedback.

```suggestion
    if (projectId === null || !client) return;
```

### Issue 2 of 5
apps/code/src/renderer/features/integrations/hooks/useGithubUserConnect.ts:98-100
With the `!cloudRegion` guard removed, this `useAuthStateValue` subscription is now unused and can be dropped.

```suggestion
  const client = useOptionalAuthenticatedClient();
  const queryClient = useQueryClient();
```

### Issue 3 of 5
apps/code/src/renderer/features/inbox/components/DataSourceSetup.tsx:193-196
Calling `resetConnect()` immediately before `handleConnectGitHub()` is redundant. The `connect()` function in `useGithubUserConnect` already calls `stopPolling()` and `setError(null)` before transitioning to `"connecting"`, so the prior `reset` call is a superfluous state round-trip. The same pattern is also repeated in `GitHubIntegrationSection.tsx`.

```suggestion
              onClick={() => {
                void handleConnectGitHub();
              }}
```

### Issue 4 of 5
apps/code/src/renderer/features/settings/components/sections/GitHubIntegrationSection.tsx:102-107
Same redundant `resetConnect()` pattern as in `DataSourceSetup.tsx``connect()` already handles the cleanup before transitioning to `"connecting"`. Both call sites can simply call `handleConnect()` directly.

```suggestion
            onClick={() => {
              void handleConnect();
            }}
          >
            Update in GitHub
```

### Issue 5 of 5
apps/code/src/renderer/features/settings/components/sections/GitHubIntegrationSection.tsx:114-119
Same redundant `resetConnect()` before `connect()` — see the other button in this file.

```suggestion
          onClick={() => {
            void handleConnect();
          }}
        >
          {hasConnectError || timedOut ? "Try again" : "Connect GitHub"}
```

Reviews (1): Last reviewed commit: "feat(code): unify git integration to use..." | Re-trigger Greptile

Comment on lines +193 to +196
onClick={() => {
if (hasConnectError || timedOut) resetConnect();
void handleConnectGitHub();
}}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Calling resetConnect() immediately before handleConnectGitHub() is redundant. The connect() function in useGithubUserConnect already calls stopPolling() and setError(null) before transitioning to "connecting", so the prior reset call is a superfluous state round-trip. The same pattern is also repeated in GitHubIntegrationSection.tsx.

Suggested change
onClick={() => {
if (hasConnectError || timedOut) resetConnect();
void handleConnectGitHub();
}}
onClick={() => {
void handleConnectGitHub();
}}
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/code/src/renderer/features/inbox/components/DataSourceSetup.tsx
Line: 193-196

Comment:
Calling `resetConnect()` immediately before `handleConnectGitHub()` is redundant. The `connect()` function in `useGithubUserConnect` already calls `stopPolling()` and `setError(null)` before transitioning to `"connecting"`, so the prior `reset` call is a superfluous state round-trip. The same pattern is also repeated in `GitHubIntegrationSection.tsx`.

```suggestion
              onClick={() => {
                void handleConnectGitHub();
              }}
```

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines 102 to 107
onClick={() => {
if (hasConnectError || timedOut) resetConnect();
void handleConnect();
}}
>
Update in GitHub
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Same redundant resetConnect() pattern as in DataSourceSetup.tsxconnect() already handles the cleanup before transitioning to "connecting". Both call sites can simply call handleConnect() directly.

Suggested change
onClick={() => {
if (hasConnectError || timedOut) resetConnect();
void handleConnect();
}}
>
Update in GitHub
onClick={() => {
void handleConnect();
}}
>
Update in GitHub
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/code/src/renderer/features/settings/components/sections/GitHubIntegrationSection.tsx
Line: 102-107

Comment:
Same redundant `resetConnect()` pattern as in `DataSourceSetup.tsx``connect()` already handles the cleanup before transitioning to `"connecting"`. Both call sites can simply call `handleConnect()` directly.

```suggestion
            onClick={() => {
              void handleConnect();
            }}
          >
            Update in GitHub
```

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +114 to +119
onClick={() => {
if (hasConnectError || timedOut) resetConnect();
void handleConnect();
}}
>
{hasConnectError || timedOut ? "Try again" : "Connect GitHub"}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Same redundant resetConnect() before connect() — see the other button in this file.

Suggested change
onClick={() => {
if (hasConnectError || timedOut) resetConnect();
void handleConnect();
}}
>
{hasConnectError || timedOut ? "Try again" : "Connect GitHub"}
onClick={() => {
void handleConnect();
}}
>
{hasConnectError || timedOut ? "Try again" : "Connect GitHub"}
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/code/src/renderer/features/settings/components/sections/GitHubIntegrationSection.tsx
Line: 114-119

Comment:
Same redundant `resetConnect()` before `connect()` — see the other button in this file.

```suggestion
          onClick={() => {
            void handleConnect();
          }}
        >
          {hasConnectError || timedOut ? "Try again" : "Connect GitHub"}
```

How can I resolve this? If you propose a fix, please make it concise.

@k11kirky k11kirky force-pushed the 05-06-feat_code_unify_git_integration_to_use_git_store_and_always_use_new_git_user_integration branch from 05a5621 to e01d637 Compare May 6, 2026 07:29
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