Skip to content

: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.

fix(github): guide users to owner/repo when a URL or bare name is entered (#77185)

Tom Owers6f5d91ab9d15
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/github/github.py b/products/warehouse_sources/backend/temporal/data_imports/sources/github/github.py
index 9bded0fe46a8..2be24c1d827a 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/github/github.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/github/github.py
@@ -312,6 +312,17 @@ def validate_credentials(
personal_access_token: str, repository: str, api_version: str = GITHUB_DEFAULT_API_VERSION
) -> tuple[bool, str | None]:
"""Validate GitHub API credentials by making a test request to the repository."""
+ # A pasted clone URL (github.com/owner/repo.git) or a bare owner name otherwise reaches the API
+ # as a nonsense path, 404s, and gets reported as "not found or not accessible" — which points the
+ # user at permissions rather than the real problem, the identifier format. Catch the wrong shape
+ # before the request so the message names the fix.
+ repo = repository.strip()
+ if repo.count("/") != 1 or not all(repo.split("/")):
+ return (
+ False,
+ "Enter the repository as owner/repo (for example, posthog/posthog), not a full URL or just the owner name.",
+ )
+
url = f"{GITHUB_BASE_URL}/repos/{repository}"
headers = _get_headers(personal_access_token, api_version=api_version)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_validate_credentials.py b/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_validate_credentials.py
index 9ba07efdcc2f..91d78c56e3bf 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_validate_credentials.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_validate_credentials.py
@@ -44,3 +44,21 @@ def test_json_error_message_is_surfaced():
is_valid, message = _validate_with(_response(422, json_body={"message": "Validation failed"}))
assert is_valid is False
assert message == "Validation failed"
+
+
+ "repository",
+ [
+ "https://github.com/owner/repo.git", # pasted clone URL
+ "owner", # bare owner, no repo
+ "owner/repo/extra", # too many path segments
+ "/repo", # missing owner
+ ],
+)
+def test_malformed_repository_gets_format_guidance(repository):
+ # Guards the pre-request format check: without it these reach the API, 404, and get the
+ # misleading "not found or not accessible" message instead of format guidance.
+ is_valid, message = github.validate_credentials("token", repository)
+ assert is_valid is False
+ assert message is not None
+ assert "owner/repo" in message