|
1 | | -import { |
2 | | - buildTeamRepositoryOptions, |
3 | | - normalizeRepositoryNames, |
4 | | - repositoryLoadWarning, |
5 | | - repositoryOptionsEqual, |
6 | | -} from "@posthog/core/integrations/repositories"; |
| 1 | +import { combineGithubRepositories } from "@posthog/core/integrations/repositories"; |
7 | 2 | import { useQuery } from "@tanstack/react-query"; |
8 | 3 | import { useEffect, useMemo } from "react"; |
9 | 4 | import { useAuthStore } from "@/features/auth"; |
10 | 5 | import { getPostHogApiClient } from "@/lib/posthogApiClient"; |
11 | 6 | import { useRepositoryCacheStore } from "../stores/repositoryCacheStore"; |
| 7 | +import { |
| 8 | + buildRepositoryOptions, |
| 9 | + repositoryLoadWarning, |
| 10 | + repositoryOptionsEqual, |
| 11 | +} from "../utils/repositorySelection"; |
12 | 12 |
|
13 | 13 | export const integrationKeys = { |
14 | 14 | all: ["integrations"] as const, |
@@ -58,9 +58,11 @@ export function useIntegrations(options: UseIntegrationsOptions = {}) { |
58 | 58 | const results = await Promise.allSettled( |
59 | 59 | githubIntegrations.map(async (integration) => ({ |
60 | 60 | integrationId: integration.id, |
61 | | - repositories: normalizeRepositoryNames( |
62 | | - await getPostHogApiClient().getGithubRepositories(integration.id), |
63 | | - ), |
| 61 | + repositories: ( |
| 62 | + await getPostHogApiClient().getGithubRepositories(integration.id) |
| 63 | + ) |
| 64 | + .map((repository) => repository.toLowerCase()) |
| 65 | + .filter(Boolean), |
64 | 66 | })), |
65 | 67 | ); |
66 | 68 |
|
@@ -89,16 +91,27 @@ export function useIntegrations(options: UseIntegrationsOptions = {}) { |
89 | 91 |
|
90 | 92 | const repositoriesByIntegration = |
91 | 93 | repositoriesQuery.data?.repositoriesByIntegration ?? {}; |
92 | | - const repositories = Object.values(repositoriesByIntegration).flat().sort(); |
| 94 | + const repositories = Object.keys( |
| 95 | + combineGithubRepositories( |
| 96 | + githubIntegrations.map((integration) => ({ |
| 97 | + data: { |
| 98 | + integrationId: integration.id, |
| 99 | + repos: repositoriesByIntegration[integration.id] ?? [], |
| 100 | + }, |
| 101 | + isPending: repositoriesQuery.isPending, |
| 102 | + isError: false, |
| 103 | + isRefetching: repositoriesQuery.isRefetching, |
| 104 | + })), |
| 105 | + ).repositoryMap, |
| 106 | + ).sort(); |
93 | 107 |
|
94 | 108 | // Memoize the derived options list keyed on the underlying query data so |
95 | 109 | // its reference is stable across renders when the data hasn't actually |
96 | 110 | // changed. Without this, every render produces a fresh array — which both |
97 | 111 | // churns the cache-write effect below AND defeats downstream React.memo / |
98 | 112 | // useMemo callers that depend on `repositoryOptions`. |
99 | 113 | const liveRepositoryOptions = useMemo( |
100 | | - () => |
101 | | - buildTeamRepositoryOptions(githubIntegrations, repositoriesByIntegration), |
| 114 | + () => buildRepositoryOptions(githubIntegrations, repositoriesByIntegration), |
102 | 115 | [githubIntegrations, repositoriesByIntegration], |
103 | 116 | ); |
104 | 117 |
|
|
0 commit comments