: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(jira): accept a pasted atlassian site url as the subdomain (#127991)
Tom Owers2ddd0b6533e9
diff --git a/products/warehouse_sources/sources/jira/jira.py b/products/warehouse_sources/sources/jira/jira.pyindex e616238879d3..dbf949edc87f 100644--- a/products/warehouse_sources/sources/jira/jira.py+++ b/products/warehouse_sources/sources/jira/jira.py@@ -49,6 +49,7 @@ SPRINT_FIELD_SCHEMA = "com.pyxis.greenhopper.jira:gh-sprint"SPRINT_ISSUES_JQL = f'sprint is not EMPTY AND created >= "{JQL_FLOOR_DATETIME}" ORDER BY created ASC'_VALID_SUBDOMAIN = re.compile(r"^[a-zA-Z0-9][a-zA-Z0-9-]*$")+_ATLASSIAN_HOST_SUFFIX = ".atlassian.net"@dataclasses.dataclass(frozen=False)@@ -61,6 +62,17 @@ class JiraResumeConfig:worklog_since: Optional[int] = None+def normalize_subdomain(subdomain: str) -> str:+ """Reduce a pasted host or URL ("https://acme.atlassian.net/jira/your-work") to the bare site name."""+ subdomain = subdomain.strip()+ if "://" in subdomain:+ subdomain = subdomain.split("://", 1)[1]+ subdomain = re.split(r"[/?#]", subdomain, maxsplit=1)[0]+ if subdomain.lower().endswith(_ATLASSIAN_HOST_SUFFIX):+ subdomain = subdomain[: -len(_ATLASSIAN_HOST_SUFFIX)]+ return subdomain++def is_valid_subdomain(subdomain: str) -> bool:return bool(subdomain) and _VALID_SUBDOMAIN.match(subdomain) is not None@@ -592,6 +604,7 @@ def _sprints_source(subdomain: str, email: str, api_token: str, team_id: int, jodef validate_credentials(subdomain: str, email: str, api_token: str) -> tuple[bool, int | None]:"""Probe ``/myself`` to confirm the token is genuine. Returns ``(ok, status_code)``."""+ subdomain = normalize_subdomain(subdomain)if not is_valid_subdomain(subdomain):return False, None@@ -616,6 +629,7 @@ def jira_source(incremental_field: str | None = None,) -> SourceResponse:config = JIRA_ENDPOINTS[endpoint]+ subdomain = normalize_subdomain(subdomain)if endpoint == "worklogs":return _worklogs_source(diff --git a/products/warehouse_sources/sources/jira/source.py b/products/warehouse_sources/sources/jira/source.pyindex 48f08f046fdc..59f866db8d8a 100644--- a/products/warehouse_sources/sources/jira/source.py+++ b/products/warehouse_sources/sources/jira/source.py@@ -5,6 +5,7 @@ from products.warehouse_sources.sources.jira.jira import (JiraResumeConfig,is_valid_subdomain,jira_source,+ normalize_subdomain,validate_credentials as validate_jira_credentials,)from products.warehouse_sources.sources.jira.settings import ENDPOINTS, INCREMENTAL_FIELDS, JIRA_ENDPOINTS@@ -127,9 +128,9 @@ The token authenticates as your Atlassian account, so the data we can sync is lidef validate_credentials(self, config: JiraSourceConfig, team_id: int, schema_name: Optional[str] = None, api_version: str | None = None) -> tuple[bool, str | None]:- if not is_valid_subdomain(config.subdomain):- # A common mistake is pasting the full host or URL; the probe would just return the- # generic "could not connect", so name the fix here instead of a network round-trip.+ if not is_valid_subdomain(normalize_subdomain(config.subdomain)):+ # Anything left after normalizing is not an Atlassian Cloud site; the probe would just return+ # the generic "could not connect", so name the fix here instead of a network round-trip.return False, ('That doesn\'t look like a Jira subdomain. Enter only the subdomain, such as "acme" '"from acme.atlassian.net, not the full domain or URL."diff --git a/products/warehouse_sources/sources/jira/tests/test_jira.py b/products/warehouse_sources/sources/jira/tests/test_jira.pyindex 493c4edec841..c2783f83180c 100644--- a/products/warehouse_sources/sources/jira/tests/test_jira.py+++ b/products/warehouse_sources/sources/jira/tests/test_jira.py@@ -63,6 +63,16 @@ class TestNormalizeIssue:_normalize_issue({"id": "1"})+class TestPastedSiteUrl:+ def test_sync_requests_the_site_named_by_a_pasted_url(self) -> None:+ driver = SourceDriver(+ JiraSource(),+ JiraSourceConfig(subdomain="https://acme.atlassian.net/jira/your-work", email="[email protected]", api_token="token"),+ )+ result = driver.run("issues", [ScriptedResponse(json={"issues": [], "isLast": True})])+ assert {request.origin for request in result.requests} == {"https://acme.atlassian.net"}++class TestTokenPagination:def test_walks_pages_and_lifts_timestamps(self) -> None:result = _driver().run(@@ -167,6 +177,13 @@ class TestValidateCredentials:assert status == status_codeassert [request.path for request in network.requests_log] == ["/rest/api/3/myself"]+ @parameterized.expand([("acme.atlassian.net",), ("https://acme.atlassian.net/jira/your-work?page=1",)])+ def test_probes_the_site_named_by_a_pasted_host_or_url(self, subdomain: str) -> None:+ with scripted_network([ScriptedResponse(status=200, json={})]) as network:+ ok, _ = validate_credentials(subdomain, "[email protected]", "token")+ assert ok is True+ assert [request.origin for request in network.requests_log] == ["https://acme.atlassian.net"]+def _worklog(worklog_id: int, updated: str) -> dict[str, Any]:return {"id": str(worklog_id), "issueId": "10", "created": "2026-01-01T00:00:00.000+0000", "updated": updated}diff --git a/products/warehouse_sources/sources/jira/tests/test_jira_source.py b/products/warehouse_sources/sources/jira/tests/test_jira_source.pyindex cf9b14c16901..9e0561d85b76 100644--- a/products/warehouse_sources/sources/jira/tests/test_jira_source.py+++ b/products/warehouse_sources/sources/jira/tests/test_jira_source.py@@ -36,9 +36,19 @@ class TestJiraSource:assert error_message == expected_messagemock_validate.assert_called_once_with(self.config.subdomain, self.config.email, self.config.api_token)+ @pytest.mark.parametrize(+ "pasted_site",+ ["acme.atlassian.net", "https://acme.atlassian.net", "https://acme.atlassian.net/jira/your-work", " acme "],+ )+ @mock.patch("products.warehouse_sources.sources.jira.source.validate_jira_credentials", return_value=(True, 200))+ def test_validate_credentials_accepts_pasted_site_host_or_url(self, mock_validate, pasted_site) -> None:+ config = JiraSourceConfig(subdomain=pasted_site, email="[email protected]", api_token="token")+ assert self.source.validate_credentials(config, self.team_id) == (True, None)+ mock_validate.assert_called_once()+@pytest.mark.parametrize("bad_subdomain",- ["acme.atlassian.net", "https://acme.atlassian.net", "acme.example.com", ""],+ ["acme.example.com", "https://acme.atlassian.net.example.com", "https://[email protected]", ""],)@mock.patch("products.warehouse_sources.sources.jira.source.validate_jira_credentials")def test_validate_credentials_rejects_malformed_subdomain_without_probing(