: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(gitlab): guide users to group/project when a URL or bare name is entered (#77186)
Tom Owersa62a7efabf0d
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/gitlab/gitlab.py b/products/warehouse_sources/backend/temporal/data_imports/sources/gitlab/gitlab.pyindex d171fcdaaaf5..2ce7eb355f90 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/gitlab/gitlab.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/gitlab/gitlab.py@@ -190,6 +190,16 @@ def validate_credentials(if not project or not project.strip():return False, "Missing project id or path"+ # GitLab addresses a project by its numeric id or a group/project path. A pasted URL or a bare+ # group name otherwise URL-encodes into a nonsense path, 404s, and gets reported as "not found+ # or not accessible with this token" — which points the user at the token rather than the format.+ project_ref = project.strip()+ if "://" in project_ref or ("/" not in project_ref and not project_ref.isdigit()):+ return (+ False,+ "Enter the project as group/project (for example, mygroup/myproject) or its numeric project ID, not a full URL.",+ )+host_only = _host_only(host)if not host_only:return False, "Invalid GitLab host"diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/gitlab/tests/test_gitlab.py b/products/warehouse_sources/backend/temporal/data_imports/sources/gitlab/tests/test_gitlab.pyindex 7338f8855a3a..6e96a8a7c474 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/gitlab/tests/test_gitlab.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/gitlab/tests/test_gitlab.py@@ -280,6 +280,29 @@ class TestValidateCredentials:assert valid is Falseassert msg == expected_msg+ @pytest.mark.parametrize(+ "project",+ [+ "https://gitlab.com/mygroup/", # pasted URL+ "mygroup", # bare group, no project and not a numeric id+ "some-dashboard", # bare name+ ],+ )+ def test_malformed_project_gets_format_guidance(self, project):+ # Guards the pre-request format check: without it these URL-encode into a nonsense path,+ # 404, and get the misleading "not found or not accessible" message.+ valid, msg = validate_credentials("https://gitlab.com", "tok", project)+ assert valid is False+ assert "group/project" in (msg or "")++ def test_numeric_project_id_is_not_rejected_as_malformed(self):+ # A bare numeric id is a valid GitLab project reference, so it must reach the API rather+ # than trip the format check for bare names.+ with self._patch_session(_response(status_code=200)) as patched:+ valid, _ = validate_credentials("https://gitlab.com", "tok", "114682853")+ assert valid is True+ patched.return_value.get.assert_called_once()+def test_request_exception_returns_failure(self):import requests