feat(integrations): filter integrations by kind server-side#1954
feat(integrations): filter integrations by kind server-side#1954VojtechBartos wants to merge 1 commit intomainfrom
Conversation
Use the new `kind` query parameter on the integrations endpoint to fetch only GitHub integrations from the desktop app, instead of pulling every integration kind and filtering client-side. Backend support: PostHog/posthog#57135. The client-side `kind === "github"` filter in `integrationStore` is kept as a safety net for self-hosted PostHog instances that pre-date that PR. Generated-By: PostHog Code Task-Id: d6eddcca-1d82-4d29-8a3e-baead66e19df
Prompt To Fix All With AIFix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
apps/code/src/renderer/hooks/useIntegrations.ts:41
**Magic string `"github"` duplicated across call sites**
The string literal `"github"` is now hardcoded in three separate files (`useIntegrations.ts`, `usePrefetchSignalData.ts`, `DataSourceSetup.tsx`) as the `kind` argument. This violates the OnceAndOnlyOnce principle — if the kind identifier ever changes, all three sites need updating. Consider exporting a shared constant (e.g. `GITHUB_INTEGRATION_KIND = "github"`) from `integrationStore.ts` and referencing it at every call site and in the existing `i.kind === "github"` guards.
### Issue 2 of 2
apps/code/src/renderer/api/posthogClient.ts:1349-1355
**No test coverage for the new `kind` query parameter**
`posthogClient.test.ts` has no test for `getIntegrations` / `getIntegrationsForProject`. The new `kind` parameter changes the URL that is fetched (appending `?kind=github`), but no test verifies that the query string is correctly set — or omitted when `kind` is `undefined`. A parameterised test covering both the filtered and unfiltered cases would prevent a silent regression if the URL-building logic is touched later.
Reviews (1): Last reviewed commit: "feat(integrations): filter integrations ..." | Re-trigger Greptile |
| const query = useAuthenticatedQuery( | ||
| integrationKeys.list(), | ||
| (client) => client.getIntegrations() as Promise<Integration[]>, | ||
| (client) => client.getIntegrations("github") as Promise<Integration[]>, |
There was a problem hiding this comment.
Magic string
"github" duplicated across call sites
The string literal "github" is now hardcoded in three separate files (useIntegrations.ts, usePrefetchSignalData.ts, DataSourceSetup.tsx) as the kind argument. This violates the OnceAndOnlyOnce principle — if the kind identifier ever changes, all three sites need updating. Consider exporting a shared constant (e.g. GITHUB_INTEGRATION_KIND = "github") from integrationStore.ts and referencing it at every call site and in the existing i.kind === "github" guards.
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/code/src/renderer/hooks/useIntegrations.ts
Line: 41
Comment:
**Magic string `"github"` duplicated across call sites**
The string literal `"github"` is now hardcoded in three separate files (`useIntegrations.ts`, `usePrefetchSignalData.ts`, `DataSourceSetup.tsx`) as the `kind` argument. This violates the OnceAndOnlyOnce principle — if the kind identifier ever changes, all three sites need updating. Consider exporting a shared constant (e.g. `GITHUB_INTEGRATION_KIND = "github"`) from `integrationStore.ts` and referencing it at every call site and in the existing `i.kind === "github"` guards.
How can I resolve this? If you propose a fix, please make it concise.| async getIntegrationsForProject(projectId: number, kind?: string) { | ||
| const url = new URL( | ||
| `${this.api.baseUrl}/api/environments/${projectId}/integrations/`, | ||
| ); | ||
| if (kind) { | ||
| url.searchParams.set("kind", kind); | ||
| } |
There was a problem hiding this comment.
No test coverage for the new
kind query parameter
posthogClient.test.ts has no test for getIntegrations / getIntegrationsForProject. The new kind parameter changes the URL that is fetched (appending ?kind=github), but no test verifies that the query string is correctly set — or omitted when kind is undefined. A parameterised test covering both the filtered and unfiltered cases would prevent a silent regression if the URL-building logic is touched later.
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/code/src/renderer/api/posthogClient.ts
Line: 1349-1355
Comment:
**No test coverage for the new `kind` query parameter**
`posthogClient.test.ts` has no test for `getIntegrations` / `getIntegrationsForProject`. The new `kind` parameter changes the URL that is fetched (appending `?kind=github`), but no test verifies that the query string is correctly set — or omitted when `kind` is `undefined`. A parameterised test covering both the filtered and unfiltered cases would prevent a silent regression if the URL-building logic is touched later.
How can I resolve this? If you propose a fix, please make it concise.
Summary
Use the new
kindquery parameter onGET /api/environments/{projectId}/integrations/so the desktop app fetches only GitHub integrations instead of pulling every integration kind and filtering client-side.Backend support: PostHog/posthog#57135.
The client-side
kind === "github"filter inintegrationStoreis kept as a safety net for self-hosted PostHog instances that pre-date that PR.Test plan
pnpm --filter code typecheckpassesposthogClient.test.tspasses…/integrations/?kind=githubin the network panel and that GitHub repos still load in the inbox / onboarding flows