:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(data-warehouse): GitHub adopts the OAuth account (repository) picker (#70512)
Tom Owers23f40049393c
diff --git a/frontend/src/lib/integrations/integrationAccountsLogic.ts b/frontend/src/lib/integrations/integrationAccountsLogic.tsindex 92ed3dbef92d..164a7b7c038e 100644--- a/frontend/src/lib/integrations/integrationAccountsLogic.ts+++ b/frontend/src/lib/integrations/integrationAccountsLogic.ts@@ -1,4 +1,4 @@-import { kea, key, path, props, reducers } from 'kea'+import { actions, kea, key, listeners, path, props, reducers } from 'kea'import { loaders } from 'kea-loaders'import { ApiConfig } from 'lib/api'@@ -8,12 +8,18 @@ import type { IntegrationAccountApi } from 'products/warehouse_sources/frontend/import type { integrationAccountsLogicType } from './integrationAccountsLogicType'+const SEARCH_DEBOUNCE_MS = 300+export const integrationAccountsLogic = kea<integrationAccountsLogicType>([props({} as { id: number; sourceType: string }),key((props) => `${props.sourceType}/${props.id}`),path((key) => ['lib', 'integrations', 'integrationAccountsLogic', key]),- loaders(({ props }) => ({+ actions({+ setSearch: (search: string) => ({ search }),+ }),++ loaders(({ props, values }) => ({accounts: [[] as IntegrationAccountApi[],{@@ -23,6 +29,9 @@ export const integrationAccountsLogic = kea<integrationAccountsLogicType>([{source_type: props.sourceType,integration_id: props.id,+ // Sources with large resource lists (e.g. GitHub repositories) filter server-side;+ // small-list sources ignore it and the endpoint filters their returned list.+ search: values.search || undefined,})return response.accounts@@ -32,6 +41,7 @@ export const integrationAccountsLogic = kea<integrationAccountsLogicType>([})),reducers({+ search: ['', { setSearch: (_, { search }) => search }],// Surface the backend's actionable 400 message (e.g. "reconnect the integration") instead of// falling back to a generic "no accounts" empty state. Cleared when a fresh load starts or succeeds.accountsError: [@@ -44,4 +54,12 @@ export const integrationAccountsLogic = kea<integrationAccountsLogicType>([},],}),++ listeners(({ actions }) => ({+ setSearch: async (_, breakpoint) => {+ // Debounce keystrokes into a single server-side query.+ await breakpoint(SEARCH_DEBOUNCE_MS)+ actions.loadAccounts()+ },+ })),])diff --git a/products/data_warehouse/frontend/shared/components/forms/InputWithSuggestionsDropdown.tsx b/products/data_warehouse/frontend/shared/components/forms/InputWithSuggestionsDropdown.tsxindex f5e570d88de8..b4189ca2e13c 100644--- a/products/data_warehouse/frontend/shared/components/forms/InputWithSuggestionsDropdown.tsx+++ b/products/data_warehouse/frontend/shared/components/forms/InputWithSuggestionsDropdown.tsx@@ -37,6 +37,9 @@ export interface InputWithSuggestionsDropdownProps {suggestionsLoading?: boolean/** Search input placeholder inside the popover. */searchPlaceholder?: string+ /** Notified as the popover search term changes, for sources that load suggestions server-side+ * (e.g. a large repository list). Client-side filtering of the current suggestions still applies. */+ onSearchChange?: (term: string) => void/** Text shown when `suggestions` is empty after loading. */emptyMessage?: string/** Text shown when the search term filters out every suggestion. Receives the current term. */@@ -67,10 +70,18 @@ export function InputWithSuggestionsDropdown({emptyMessage = 'No suggestions available.',noMatchMessage = (term) => `No suggestions match "${term}".`,loadingMessage = 'Loading…',+ onSearchChange,}: InputWithSuggestionsDropdownProps): JSX.Element {const [open, setOpen] = useState(false)const [searchTerm, setSearchTerm] = useState('')+ // Reset both the local filter and any server-side search state, so reopening the picker+ // doesn't show an empty search box while still requesting the previously filtered list.+ const resetSearch = (): void => {+ setSearchTerm('')+ onSearchChange?.('')+ }+const normalized = useMemo(() => suggestions.map(normalizeSuggestion), [suggestions])const filtered = useMemo(() => {@@ -85,7 +96,7 @@ export function InputWithSuggestionsDropdown({<Popovervisible={open}onClickOutside={() => {- setSearchTerm('')+ resetSearch()setOpen(false)}}placement="bottom-start"@@ -97,7 +108,10 @@ export function InputWithSuggestionsDropdown({size="small"placeholder={searchPlaceholder}value={searchTerm}- onChange={setSearchTerm}+ onChange={(term) => {+ setSearchTerm(term)+ onSearchChange?.(term)+ }}/>{suggestionsLoading ? (<p className="m-0 px-2 py-1 text-xs text-secondary flex items-center gap-1">@@ -120,7 +134,7 @@ export function InputWithSuggestionsDropdown({icon={isCurrent ? <IconCheck /> : undefined}onClick={() => {onChange(suggestion.value)- setSearchTerm('')+ resetSearch()setOpen(false)}}>diff --git a/products/data_warehouse/frontend/shared/components/forms/IntegrationAccountSelector.tsx b/products/data_warehouse/frontend/shared/components/forms/IntegrationAccountSelector.tsxindex f4c7f2b2bb22..2bbe3cd3bb97 100644--- a/products/data_warehouse/frontend/shared/components/forms/IntegrationAccountSelector.tsx+++ b/products/data_warehouse/frontend/shared/components/forms/IntegrationAccountSelector.tsx@@ -86,15 +86,36 @@ function AccountTextField({)}+/** Find the value stored under `key` anywhere in a (possibly nested) payload object. The OAuth id a+ * picker depends on is usually a top-level field, but some sources nest it under a select group+ * (e.g. GitHub's `github_integration_id` lives inside the `auth_method` select), so we look for the+ * field wherever it is rather than assuming the top level. */+function findFieldValue(obj: unknown, key: string): unknown {+ if (!obj || typeof obj !== 'object') {+ return undefined+ }+ const record = obj as Record<string, unknown>+ if (key in record) {+ return record[key]+ }+ for (const nested of Object.values(record)) {+ const found = findFieldValue(nested, key)+ if (found !== undefined) {+ return found+ }+ }+ return undefined+}+function useFormIntegrationId(formLogic: any, formKey: string, integrationField: string): number | undefined {const values = useValues(formLogic) as Record<string, any> | nullif (!values) {return undefined}// Saved job_inputs store the id as a JSONB string; coerce so `integration.id === id` matches.- const raw = values[formKey]?.payload?.[integrationField]+ const raw = findFieldValue(values[formKey]?.payload, integrationField)const id = raw === undefined || raw === null || raw === '' ? undefined : Number(raw)- return id && Number.isFinite(id) ? id : undefined+ return id !== undefined && Number.isFinite(id) ? id : undefined}function IntegrationAccountFieldWithDropdown({@@ -108,7 +129,7 @@ function IntegrationAccountFieldWithDropdown({const { accounts, accountsLoading, accountsError } = useValues(integrationAccountsLogic({ id: integrationId, sourceType }))- const { loadAccounts } = useActions(integrationAccountsLogic({ id: integrationId, sourceType }))+ const { loadAccounts, setSearch } = useActions(integrationAccountsLogic({ id: integrationId, sourceType }))useEffect(() => {loadAccounts()@@ -159,6 +180,7 @@ function IntegrationAccountFieldWithDropdown({onChange={onChange}suggestions={suggestions}suggestionsLoading={accountsLoading}+ onSearchChange={setSearch}searchPlaceholder="Filter accounts…"emptyMessage="No accounts accessible by this integration."loadingMessage="Loading accounts…"diff --git a/products/data_warehouse/frontend/shared/components/forms/SourceForm.tsx b/products/data_warehouse/frontend/shared/components/forms/SourceForm.tsxindex 45905c7c5ec5..b08ae88709f8 100644--- a/products/data_warehouse/frontend/shared/components/forms/SourceForm.tsx+++ b/products/data_warehouse/frontend/shared/components/forms/SourceForm.tsx@@ -36,7 +36,6 @@ import { CDC_SOURCE_TYPES } from '../../cdc'import { isCustomSourceAiBuilderEnabled } from './customSourceManifest'import { CustomSourceManifestBuilder } from './CustomSourceManifestBuilder'import { customSourceManifestBuilderLogic } from './customSourceManifestBuilderLogic'-import { GitHubRepositorySelector } from './GitHubRepositorySelector'import { IntegrationAccountSelector } from './IntegrationAccountSelector'import { SourceIntegrationChoice } from './IntegrationChoice'import { parseConnectionStringForSource } from './parsers'@@ -325,11 +324,6 @@ export const sourceFieldToElement = ()}- if (field.type === 'text' && field.name === 'repository' && sourceConfig.name === 'Github') {- // Special case, this is the GitHub repository field- return <GitHubRepositorySelector key={field.name} />- }-return (<LemonFieldkey={field.name}diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/github/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/github/source.pyindex 6465169a7da4..9ca440e65859 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/github/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/github/source.py@@ -11,6 +11,7 @@ from posthog.schema import (SourceConfig,SourceFieldInputConfig,SourceFieldInputConfigType,+ SourceFieldOauthAccountSelectConfig,SourceFieldOauthConfig,SourceFieldSelectConfig,SourceFieldSelectConfigOption,@@ -149,13 +150,13 @@ class GithubSource(),],),- SourceFieldInputConfig(+ SourceFieldOauthAccountSelectConfig(name="repository",label="Repository",- type=SourceFieldInputConfigType.TEXT,- required=True,+ integrationField="github_integration_id",+ integrationKind="github",placeholder="owner/repo",- secret=False,+ required=True,),],),