: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
fix(github): surface repo-picker listing failures as a 400 (#71776)
Tom Owers208565e7eac0
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 38581f310133..7dccdf8cd194 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@@ -17,7 +17,7 @@ from posthog.schema import (SourceFieldSelectConfigOption,)-from posthog.models.integration import GitHubIntegration+from posthog.models.integration import GitHubIntegration, GitHubIntegrationErrorfrom products.warehouse_sources.backend.temporal.data_imports.naming_convention import NamingConventionfrom products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline.typings import (@@ -264,9 +264,19 @@ If automatic creation failed, your token needs webhook permissions — the **adm# `repository` is `owner/repo`. Repo lists can be large, so push the search down to the cache# query (server-side) and cap the page — the picker searches as the user types rather than# loading every repo at once.- repositories, _has_more = GitHubIntegration(integration).list_cached_repositories(- search=search or "", limit=100, offset=0- )+ try:+ repositories, _has_more = GitHubIntegration(integration).list_cached_repositories(+ search=search or "", limit=100, offset=0+ )+ except GitHubIntegrationError as e:+ # The refresh talks to GitHub, which can reject the credentials, report a suspended+ # installation, or return a transient non-JSON/5xx body from its edge. None of these are+ # server bugs, so surface an actionable 400 rather than a 500 that only adds noise.+ raise IntegrationAccountListingError(+ "Couldn't load your GitHub repositories. GitHub may be temporarily unavailable, or your "+ "connection may need refreshing. Please try again, and reconnect your GitHub account if the "+ "problem persists."+ ) from ereturn [IntegrationAccount(value=repo["full_name"], display_name=repo["full_name"])for repo in repositoriesdiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_source_class.py b/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_source_class.pyindex 77ef1d174795..aceeeed090ee 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_source_class.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_source_class.py@@ -1,6 +1,8 @@import pytestfrom unittest import mock+from posthog.models.integration import GitHubIntegrationError+from products.warehouse_sources.backend.temporal.data_imports.sources.common.integration_accounts import (IntegrationAccountListingError,)@@ -83,6 +85,17 @@ class TestGithubSource:with pytest.raises(IntegrationAccountListingError):self.source.get_oauth_accounts(999, self.team_id)+ @mock.patch(_GITHUB_INTEGRATION_PATH)+ @mock.patch.object(GithubSource, "get_oauth_integration")+ def test_get_oauth_accounts_maps_github_listing_failure(self, mock_get_oauth, mock_github_integration):+ mock_get_oauth.return_value = mock.MagicMock()+ mock_github_integration.return_value.list_cached_repositories.side_effect = GitHubIntegrationError(+ "GitHubIntegration: list_repositories non-JSON response"+ )++ with pytest.raises(IntegrationAccountListingError):+ self.source.get_oauth_accounts(1, self.team_id)+@pytest.mark.parametrize("expected_key",[