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.

feat(bitrise): sync pipelines, branches, organizations and members (#99803)

Tom Owersd31c901365f3
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
index 470cce152637..939c3ba3d886 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
@@ -832,14 +832,14 @@ pull request in one walk, so it costs one request per page instead of one per pu
## Bitrise — gaps
-Today (4): `apps`, `artifacts`, `builds`, `workflows`
+Today (8): `apps`, `artifacts`, `branches`, `builds`, `organization_members`, `organizations`, `pipelines`, `workflows`
Diffed against: <https://api-docs.bitrise.io/docs/swagger.json>
-- [ ] `/apps/{app-slug}/pipelines (and /pipelines)` — pipeline runs are Bitrise's modern CI execution unit; we sync builds and workflows but not pipeline executions (high)
-- [ ] `/organizations/{org-slug}/members` — org membership records for attributing builds to people (medium)
-- [ ] `/organizations` — lookup resolving the org that owns each app we already sync (medium)
-- [ ] `/apps/{app-slug}/branches` — branch lookup for grouping build history (medium)
+- [x] `/apps/{app-slug}/pipelines (and /pipelines)` — pipeline runs are Bitrise's modern CI execution unit; we sync builds and workflows but not pipeline executions (high). Synced per app, which is the only variant with an `after` time filter; the account-wide `/pipelines` returns the same runs with no filter.
+- [x] `/organizations/{org-slug}/members` — org membership records for attributing builds to people (medium)
+- [x] `/organizations` — lookup resolving the org that owns each app we already sync (medium)
+- [x] `/apps/{app-slug}/branches` — branch lookup for grouping build history (medium)
- [ ] `/apps/{app-slug}/archived-builds` — extends build history past the live builds window (medium)
- [ ] `/apps/{app-slug}/build-requests` — queued/pending build requests reveal CI backlog (low)
- [ ] `/me/activities` — account-level activity event feed (low)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bitrise/bitrise.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bitrise/bitrise.py
index 26831f209bf5..ab9615043065 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bitrise/bitrise.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bitrise/bitrise.py
@@ -1,4 +1,5 @@
import dataclasses
+from collections.abc import Callable
from datetime import UTC, date, datetime, timedelta
from typing import Any, Optional
from urllib.parse import urlencode
@@ -34,7 +35,7 @@ PAGE_LIMIT = 50
INCREMENTAL_LOOKBACK = timedelta(hours=24)
[email protected](frozen=False)
class BitriseResumeConfig:
# Fan-out bookmark: retained only so pre-migration saved state still parses via
# `dataclass(**saved)`. New runs never populate it; fan-out resume now lives in `fanout_state`.
@@ -42,7 +43,8 @@ class BitriseResumeConfig:
# `next` paging anchor for the flat apps listing. None means "start at the first page".
next: str | None = None
# Framework fan-out resume snapshot ({"completed": [...], "current": ..., "child_state": ...})
- # for the single-hop parent-app -> child-endpoint dependent resources (builds, workflows).
+ # for the single-hop parent-app -> child-endpoint dependent resources (builds, pipelines,
+ # workflows, branches).
fanout_state: dict[str, Any] | None = None
@@ -77,6 +79,14 @@ def _build_after_param(should_use_incremental_field: bool, db_incremental_field_
return max(0, timestamp - int(INCREMENTAL_LOOKBACK.total_seconds()))
+def _build_after_rfc3339_param(should_use_incremental_field: bool, db_incremental_field_last_value: Any) -> str | None:
+ """The pipelines endpoint takes `after` as RFC3339, not the Unix timestamp builds expects."""
+ timestamp = _build_after_param(should_use_incremental_field, db_incremental_field_last_value)
+ if timestamp is None:
+ return None
+ return datetime.fromtimestamp(timestamp, tz=UTC).strftime("%Y-%m-%dT%H:%M:%SZ")
+
+
def validate_credentials(api_token: str) -> bool:
"""Confirm the token is genuine with a cheap probe.
@@ -103,10 +113,11 @@ def _client_config(api_token: str) -> ClientConfig:
}
-def _cursor_paginator() -> JSONResponseCursorPaginator:
- # Bitrise signals more pages with a `paging.next` anchor passed back as `?next=`; absent on the
- # final page.
- return JSONResponseCursorPaginator(cursor_path="paging.next", cursor_param="next")
+def _cursor_paginator(cursor_param: str = "next") -> JSONResponseCursorPaginator:
+ # Bitrise signals more pages with a `paging.next` anchor; absent on the final page. Most
+ # endpoints take the anchor back as `?next=`, but the pipelines endpoints renamed that param to
+ # `before` and deprecated `next`.
+ return JSONResponseCursorPaginator(cursor_path="paging.next", cursor_param=cursor_param)
def _apps_resource() -> EndpointResource:
@@ -121,6 +132,18 @@ def _apps_resource() -> EndpointResource:
}
+def _organizations_resource() -> EndpointResource:
+ # The organizations listing takes no params and returns every org in one body.
+ return {
+ "name": "organizations",
+ "endpoint": {
+ "path": "/organizations",
+ "data_selector": "data",
+ "paginator": SinglePagePaginator(),
+ },
+ }
+
+
def _builds_child_params(after: int | None) -> dict[str, Any]:
params: dict[str, Any] = {
"app_slug": {"type": "resolve", "resource": "apps", "field": "slug"},
@@ -232,35 +255,149 @@ def _builds_source(
return _single_hop_fanout_source(api_token, team_id, job_id, resumable_source_manager, child_resource)
-def _workflows_explode(row: dict[str, Any]) -> list[dict[str, Any]]:
- # build-workflows returns bare workflow-name strings under `data`; explode them into one row per
- # workflow, carrying the injected parent app slug.
- app_slug = row.get("_apps_slug")
- return [{"app_slug": app_slug, "workflow": name} for name in row.get("data") or []]
+def _pipelines_source(
+ api_token: str,
+ team_id: int,
+ job_id: str,
+ resumable_source_manager: ResumableSourceManager[BitriseResumeConfig],
+ after: str | None,
+) -> Resource:
+ params: dict[str, Any] = {
+ "app_slug": {"type": "resolve", "resource": "apps", "field": "slug"},
+ "limit": PAGE_LIMIT,
+ }
+ if after is not None:
+ params["after"] = after
+
+ child_resource: EndpointResource = {
+ "name": "pipelines",
+ "include_from_parent": ["slug"],
+ "endpoint": {
+ "path": "/apps/{app_slug}/pipelines",
+ "params": params,
+ "data_selector": "data",
+ # The anchor comes back as `paging.next` but is sent as `?before=`; `?next=` is the
+ # deprecated spelling of the same param.
+ "paginator": _cursor_paginator(cursor_param="before"),
+ "response_actions": [{"status_code": 404, "action": "ignore"}],
+ },
+ "data_map": rename_parent_fields("apps", {"slug": "app_slug"}),
+ }
+ return _single_hop_fanout_source(api_token, team_id, job_id, resumable_source_manager, child_resource)
+
+
+def _explode_app_name_list(column: str) -> Callable[[dict[str, Any]], list[dict[str, Any]]]:
+ """Explode a `{"data": ["a", "b"]}` body into one row per bare name, keyed on the parent app."""
+ def _explode(row: dict[str, Any]) -> list[dict[str, Any]]:
+ app_slug = row.get("_apps_slug")
+ return [{"app_slug": app_slug, column: name} for name in row.get("data") or []]
-def _workflows_source(
+ return _explode
+
+
+def _app_name_list_source(
api_token: str,
team_id: int,
job_id: str,
resumable_source_manager: ResumableSourceManager[BitriseResumeConfig],
+ name: str,
+ path: str,
+ column: str,
) -> Resource:
child_resource: EndpointResource = {
- "name": "workflows",
+ "name": name,
"include_from_parent": ["slug"],
"endpoint": {
- "path": "/apps/{app_slug}/build-workflows",
+ "path": path,
"params": {"app_slug": {"type": "resolve", "resource": "apps", "field": "slug"}},
# No data_selector: the whole `{"data": [...]}` body is yielded as one row, then the
- # data_map explodes it into one row per bare workflow name.
+ # data_map explodes it into one row per bare name.
"paginator": SinglePagePaginator(),
"response_actions": [{"status_code": 404, "action": "ignore"}],
},
- "data_map": _workflows_explode,
+ "data_map": _explode_app_name_list(column),
}
return _single_hop_fanout_source(api_token, team_id, job_id, resumable_source_manager, child_resource)
+def _organizations_source(
+ api_token: str,
+ team_id: int,
+ job_id: str,
+) -> Resource:
+ rest_config: RESTAPIConfig = {
+ "client": _client_config(api_token),
+ "resources": [_organizations_resource()],
+ }
+ return rest_api_resource(rest_config, team_id, job_id, None)
+
+
+def _organization_members_source(
+ api_token: str,
+ team_id: int,
+ job_id: str,
+) -> Resource:
+ """Fan out over organizations without resume.
+
+ An account belongs to a handful of organizations and each membership listing is one page, so a
+ retry re-fetches the whole table cheaply and merge dedupes it.
+ """
+ child_resource: EndpointResource = {
+ "name": "organization_members",
+ "include_from_parent": ["slug"],
+ "endpoint": {
+ "path": "/organizations/{org_slug}/members",
+ "params": {"org_slug": {"type": "resolve", "resource": "organizations", "field": "slug"}},
+ # The members listing returns a bare JSON array, not a `{"data": [...]}` envelope.
+ "data_selector": "$",
+ "paginator": SinglePagePaginator(),
+ "response_actions": [{"status_code": 404, "action": "ignore"}],
+ },
+ "data_map": rename_parent_fields("organizations", {"slug": "org_slug"}),
+ }
+ rest_config: RESTAPIConfig = {
+ "client": _client_config(api_token),
+ "resources": [_organizations_resource(), child_resource],
+ }
+ resources = rest_api_resources(rest_config, team_id, job_id, None)
+ return next(resource for resource in resources if getattr(resource, "name", None) == "organization_members")
+
+
+def _workflows_source(
+ api_token: str,
+ team_id: int,
+ job_id: str,
+ resumable_source_manager: ResumableSourceManager[BitriseResumeConfig],
+) -> Resource:
+ return _app_name_list_source(
+ api_token,
+ team_id,
+ job_id,
+ resumable_source_manager,
+ name="workflows",
+ path="/apps/{app_slug}/build-workflows",
+ column="workflow",
+ )
+
+
+def _branches_source(
+ api_token: str,
+ team_id: int,
+ job_id: str,
+ resumable_source_manager: ResumableSourceManager[BitriseResumeConfig],
+) -> Resource:
+ return _app_name_list_source(
+ api_token,
+ team_id,
+ job_id,
+ resumable_source_manager,
+ name="branches",
+ path="/apps/{app_slug}/branches",
+ column="branch",
+ )
+
+
def _artifacts_source(
api_token: str,
team_id: int,
@@ -328,8 +465,22 @@ def bitrise_source(
resource = _apps_source(api_token, team_id, job_id, resumable_source_manager)
elif endpoint == "builds":
resource = _builds_source(api_token, team_id, job_id, resumable_source_manager, after)
+ elif endpoint == "pipelines":
+ resource = _pipelines_source(
+ api_token,
+ team_id,
+ job_id,
+ resumable_source_manager,
+ _build_after_rfc3339_param(should_use_incremental_field, db_incremental_field_last_value),
+ )
elif endpoint == "workflows":
resource = _workflows_source(api_token, team_id, job_id, resumable_source_manager)
+ elif endpoint == "branches":
+ resource = _branches_source(api_token, team_id, job_id, resumable_source_manager)
+ elif endpoint == "organizations":
+ resource = _organizations_source(api_token, team_id, job_id)
+ elif endpoint == "organization_members":
+ resource = _organization_members_source(api_token, team_id, job_id)
elif endpoint == "artifacts":
resource = _artifacts_source(api_token, team_id, job_id, after)
else:
@@ -340,9 +491,9 @@ def bitrise_source(
name=endpoint,
items=lambda: resource,
primary_keys=endpoint_config.primary_keys,
- # Bitrise returns builds newest-first and the fan-out walks app by app, so rows never arrive
- # in ascending timestamp order. desc mode persists the incremental watermark only at
- # successful job end, which is the only safe point for a fan-out stream.
+ # Bitrise returns builds and pipelines newest-first and the fan-out walks app by app, so
+ # rows never arrive in ascending timestamp order. desc mode persists the incremental
+ # watermark only at successful job end, which is the only safe point for a fan-out stream.
sort_mode="desc",
partition_count=1,
partition_size=1,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bitrise/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bitrise/canonical_descriptions.py
index 1bc8576c54e1..16a3cbbc0378 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bitrise/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bitrise/canonical_descriptions.py
@@ -59,6 +59,68 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"workflow": "Name of the workflow.",
},
},
+ "pipelines": {
+ "description": "A pipeline or standalone build run of an app. Pipelines are Bitrise's "
+ "multi-stage execution unit, running several workflows together.",
+ "docs_url": "https://api-docs.bitrise.io/#/pipelines",
+ "columns": {
+ "app_slug": "Identifier of the app the pipeline belongs to (added by PostHog during sync).",
+ "slug": "Unique identifier of the pipeline run.",
+ "build_number": "Sequential number of the pipeline run within the app.",
+ "status": "Numeric run status (0 running, 1 successful, 2 failed, 3 aborted with failure, 4 aborted with success).",
+ "is_pipeline": "Whether the run is a pipeline rather than a standalone build.",
+ "is_on_hold": "Whether the run is queued waiting for a free concurrency slot.",
+ "is_processed": "Whether Bitrise has finished processing the run.",
+ "rebuildable": "Whether the run can be rebuilt.",
+ "utility": "Whether the run is a utility run rather than a user-triggered one.",
+ "credit_cost": "Credits the run consumed.",
+ "branch": "Git branch the run was triggered on.",
+ "tag": "Git tag that triggered the run, if any.",
+ "commit_hash": "Hash of the commit the run ran against.",
+ "commit_message": "Message of the commit the run ran against.",
+ "triggered_workflow": "Name of the workflow the run started with.",
+ "triggered_by": "What triggered the run (e.g. webhook, manual).",
+ "triggered_at": "When the run was triggered.",
+ "started_at": "When the run started.",
+ "finished_at": "When the run finished.",
+ "pull_request_id": "Identifier of the pull request that triggered the run, if any.",
+ "pull_request_target_branch": "Target branch of the triggering pull request.",
+ "artifacts": "Artifacts the run produced, with their type, title and version.",
+ "build_tool_invocations": "Build tools the run invoked, with their version and invocation id.",
+ "trigger_params": "Full set of parameters the trigger supplied to the run.",
+ "local_config": "Host and username of the machine that triggered a locally started run.",
+ },
+ },
+ "branches": {
+ "description": "A branch of an app's repository that has builds on Bitrise, one row per app "
+ "and branch name. Branches with no builds are not listed.",
+ "docs_url": "https://api-docs.bitrise.io/#/application",
+ "columns": {
+ "app_slug": "Identifier of the app the branch belongs to (added by PostHog during sync).",
+ "branch": "Name of the branch.",
+ },
+ },
+ "organizations": {
+ "description": "A Bitrise organization (workspace) the token's account belongs to.",
+ "docs_url": "https://api-docs.bitrise.io/#/organization",
+ "columns": {
+ "slug": "Unique identifier of the organization.",
+ "name": "Display name of the organization.",
+ "avatar_icon_url": "URL of the organization's avatar image.",
+ "concurrency_count": "Number of builds the organization can run at the same time.",
+ "owners": "Accounts that own the organization, with email, slug and username.",
+ },
+ },
+ "organization_members": {
+ "description": "A member of a Bitrise organization, one row per organization and member.",
+ "docs_url": "https://api-docs.bitrise.io/#/organization",
+ "columns": {
+ "org_slug": "Identifier of the organization the membership belongs to (added by PostHog during sync).",
+ "slug": "Unique identifier of the member's Bitrise account.",
+ "username": "Username of the member.",
+ "email": "Email address of the member.",
+ },
+ },
"artifacts": {
"description": "A file produced by a build (e.g. an IPA, APK, or log archive).",
"docs_url": "https://api-docs.bitrise.io/#/build-artifact",
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bitrise/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bitrise/settings.py
index 60f5fdcba8d7..2ddf4f88a02d 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bitrise/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bitrise/settings.py
@@ -14,9 +14,11 @@ class BitriseEndpointConfig:
# Bitrise's builds endpoint accepts a server-side `after` Unix-timestamp filter (builds run after
-# the given time), which gives an honest incremental sync on `triggered_at`. Artifacts inherit
-# that filter through their parent build fan-out, keyed on the injected `build_triggered_at`.
-# Apps and workflows are small listings with no server-side time filter, so they stay full refresh.
+# the given time), which gives an honest incremental sync on `triggered_at`. The pipelines endpoint
+# takes the same filter as an RFC3339 date. Artifacts inherit the builds filter through their parent
+# build fan-out, keyed on the injected `build_triggered_at`. Apps, workflows, branches,
+# organizations and organization members are small listings with no server-side time filter, so
+# they stay full refresh.
BITRISE_ENDPOINTS: dict[str, BitriseEndpointConfig] = {
"apps": BitriseEndpointConfig(
name="apps",
@@ -56,6 +58,33 @@ BITRISE_ENDPOINTS: dict[str, BitriseEndpointConfig] = {
},
],
),
+ "pipelines": BitriseEndpointConfig(
+ name="pipelines",
+ # Pipeline slugs share the build slug namespace, which Bitrise doesn't document as global.
+ primary_keys=["app_slug", "slug"],
+ partition_key="triggered_at",
+ incremental_fields=[
+ {
+ "label": "triggered_at",
+ "type": IncrementalFieldType.DateTime,
+ "field": "triggered_at",
+ "field_type": IncrementalFieldType.DateTime,
+ },
+ ],
+ ),
+ "branches": BitriseEndpointConfig(
+ name="branches",
+ # The branches endpoint returns bare branch names, unique per app only.
+ primary_keys=["app_slug", "branch"],
+ ),
+ "organizations": BitriseEndpointConfig(
+ name="organizations",
+ ),
+ "organization_members": BitriseEndpointConfig(
+ name="organization_members",
+ # A member slug identifies the Bitrise account, which can belong to several organizations.
+ primary_keys=["org_slug", "slug"],
+ ),
}
ENDPOINTS = tuple(BITRISE_ENDPOINTS.keys())
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bitrise/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bitrise/source.py
index 176d0b475e7f..720e39687de2 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bitrise/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bitrise/source.py
@@ -102,6 +102,8 @@ You can create a personal access token in your [Bitrise security settings](https
"Fetches artifacts for every build, one request per build. "
"Disabled by default because of the API cost"
)
+ if endpoint == "branches":
+ return "Only branches that already have builds on Bitrise are listed"
return None
def _build_schema(endpoint: str) -> SourceSchema:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bitrise/tests/test_bitrise.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bitrise/tests/test_bitrise.py
index 277cdc19f953..bc1ae50f7eed 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bitrise/tests/test_bitrise.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bitrise/tests/test_bitrise.py
@@ -11,6 +11,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.bitrise.bi
INCREMENTAL_LOOKBACK,
BitriseResumeConfig,
_build_after_param,
+ _build_after_rfc3339_param,
_to_unix_timestamp,
bitrise_source,
validate_credentials,
@@ -29,7 +30,7 @@ BITRISE_SESSION_PATCH = (
)
-def _response(body: dict[str, Any], status_code: int = 200) -> Response:
+def _response(body: Any, status_code: int = 200) -> Response:
resp = Response()
resp.status_code = status_code
resp._content = json.dumps(body).encode()
@@ -109,6 +110,16 @@ class TestBuildAfterParam:
assert _build_after_param(should_use_incremental_field, last_value) is None
+class TestBuildAfterRfc3339Param:
+ def test_formats_the_lookback_cutoff_as_rfc3339(self):
+ after = _build_after_rfc3339_param(True, datetime(2026, 1, 2, 3, 4, 5, tzinfo=UTC))
+ # 24h lookback subtracted from the watermark, rendered in the format pipelines expects.
+ assert after == "2026-01-01T03:04:05Z"
+
+ def test_no_filter_without_a_watermark(self):
+ assert _build_after_rfc3339_param(False, datetime(2026, 1, 2, tzinfo=UTC)) is None
+
+
class TestValidateCredentials:
@mock.patch(BITRISE_SESSION_PATCH)
def test_valid_personal_access_token(self, mock_session):
@@ -339,6 +350,151 @@ class TestWorkflows:
]
+class TestPipelines:
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_fans_out_over_apps_and_injects_app_slug(self, MockSession):
+ session = MockSession.return_value
+ _params, urls = _wire(
+ session,
+ [
+ _response({"data": [{"slug": "app1"}], "paging": {}}),
+ _response({"data": [{"slug": "p1", "triggered_at": "2026-01-01T00:00:00Z"}], "paging": {}}),
+ ],
+ )
+
+ rows = _rows(_source("pipelines", _make_manager()))
+
+ assert [(row["slug"], row["app_slug"]) for row in rows] == [("p1", "app1")]
+ assert urls[1].endswith("/apps/app1/pipelines")
+
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_paginates_via_the_before_param(self, MockSession):
+ session = MockSession.return_value
+ params, _urls = _wire(
+ session,
+ [
+ _response({"data": [{"slug": "app1"}], "paging": {}}),
+ _response({"data": [{"slug": "p1"}], "paging": {"next": "2026-01-01T00:00:00Z"}}),
+ _response({"data": [{"slug": "p2"}], "paging": {}}),
+ ],
+ )
+
+ rows = _rows(_source("pipelines", _make_manager()))
+
+ assert [row["slug"] for row in rows] == ["p1", "p2"]
+ # Bitrise renamed the pipelines paging param to `before`; `next` is its deprecated spelling.
+ assert params[2]["before"] == "2026-01-01T00:00:00Z"
+ assert "next" not in params[2]
+
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_incremental_passes_an_rfc3339_after_param(self, MockSession):
+ session = MockSession.return_value
+ params, _urls = _wire(
+ session,
+ [
+ _response({"data": [{"slug": "app1"}], "paging": {}}),
+ _response({"data": [], "paging": {}}),
+ ],
+ )
+
+ _rows(
+ _source(
+ "pipelines",
+ _make_manager(),
+ should_use_incremental_field=True,
+ db_incremental_field_last_value=datetime(2026, 1, 2, tzinfo=UTC),
+ )
+ )
+
+ # Unlike builds, the pipelines filter is a date string rather than a Unix timestamp.
+ assert params[1]["after"] == "2026-01-01T00:00:00Z"
+
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_full_refresh_has_no_after_param(self, MockSession):
+ session = MockSession.return_value
+ params, _urls = _wire(
+ session,
+ [
+ _response({"data": [{"slug": "app1"}], "paging": {}}),
+ _response({"data": [], "paging": {}}),
+ ],
+ )
+
+ _rows(_source("pipelines", _make_manager()))
+
+ assert "after" not in params[1]
+
+
+class TestBranches:
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_maps_branch_names_to_rows(self, MockSession):
+ session = MockSession.return_value
+ _params, urls = _wire(
+ session,
+ [
+ _response({"data": [{"slug": "app1"}], "paging": {}}),
+ _response({"data": ["main", "release/1.0"]}),
+ ],
+ )
+
+ rows = _rows(_source("branches", _make_manager()))
+
+ assert rows == [
+ {"app_slug": "app1", "branch": "main"},
+ {"app_slug": "app1", "branch": "release/1.0"},
+ ]
+ assert urls[1].endswith("/apps/app1/branches")
+
+
+class TestOrganizations:
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_reads_the_single_page_listing(self, MockSession):
+ session = MockSession.return_value
+ _params, urls = _wire(session, [_response({"data": [{"slug": "org1", "name": "Acme"}]})])
+
+ rows = _rows(_source("organizations", _make_manager()))
+
+ assert rows == [{"slug": "org1", "name": "Acme"}]
+ assert urls[0].endswith("/organizations")
+
+
+class TestOrganizationMembers:
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_fans_out_over_organizations_and_injects_org_slug(self, MockSession):
+ session = MockSession.return_value
+ _params, urls = _wire(
+ session,
+ [
+ _response({"data": [{"slug": "org1"}, {"slug": "org2"}]}),
+ # The members listing answers with a bare array, not a `data` envelope.
+ _response([{"slug": "u1", "username": "ada", "email": "[email protected]"}]),
+ _response([{"slug": "u2", "username": "grace", "email": "[email protected]"}]),
+ ],
+ )
+
+ rows = _rows(_source("organization_members", _make_manager()))
+
+ assert [(row["slug"], row["org_slug"]) for row in rows] == [("u1", "org1"), ("u2", "org2")]
+ assert urls[1].endswith("/organizations/org1/members")
+ assert urls[2].endswith("/organizations/org2/members")
+
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_deleted_organization_404_is_skipped(self, MockSession):
+ session = MockSession.return_value
+ _wire(
+ session,
+ [
+ _response({"data": [{"slug": "org1"}, {"slug": "org2"}]}),
+ _response({"message": "Not Found"}, status_code=404),
+ _response([{"slug": "u2"}]),
+ ],
+ )
+
+ rows = _rows(_source("organization_members", _make_manager()))
+
+ assert [(row["slug"], row["org_slug"]) for row in rows] == [("u2", "org2")]
+
+
class TestArtifacts:
@mock.patch(CLIENT_SESSION_PATCH)
def test_fans_out_over_builds_and_injects_parent_identifiers(self, MockSession):
@@ -416,3 +572,6 @@ class TestSourceResponse:
assert BITRISE_ENDPOINTS["builds"].primary_keys == ["app_slug", "slug"]
assert BITRISE_ENDPOINTS["workflows"].primary_keys == ["app_slug", "workflow"]
assert BITRISE_ENDPOINTS["artifacts"].primary_keys == ["app_slug", "build_slug", "slug"]
+ assert BITRISE_ENDPOINTS["pipelines"].primary_keys == ["app_slug", "slug"]
+ assert BITRISE_ENDPOINTS["branches"].primary_keys == ["app_slug", "branch"]
+ assert BITRISE_ENDPOINTS["organization_members"].primary_keys == ["org_slug", "slug"]
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bitrise/tests/test_bitrise_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bitrise/tests/test_bitrise_source.py
index a6e62df5b022..18a4b32e3991 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bitrise/tests/test_bitrise_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bitrise/tests/test_bitrise_source.py
@@ -44,9 +44,9 @@ class TestBitriseSource:
assert {schema.name for schema in schemas} == set(ENDPOINTS)
incremental = {schema.name for schema in schemas if schema.supports_incremental}
- # Only builds (and artifacts, through their parent build fan-out) can be filtered
- # server-side via the `after` Unix-timestamp param.
- assert incremental == {"builds", "artifacts"}
+ # Only builds (and artifacts, through their parent build fan-out) and pipelines can be
+ # filtered server-side via the `after` param.
+ assert incremental == {"builds", "artifacts", "pipelines"}
def test_incremental_schemas_advertise_their_fields(self):
schemas = {schema.name: schema for schema in self.source.get_schemas(self.config, self.team_id)}
@@ -54,6 +54,7 @@ class TestBitriseSource:
assert schemas["builds"].incremental_fields == INCREMENTAL_FIELDS["builds"]
assert [f["field"] for f in schemas["builds"].incremental_fields] == ["triggered_at"]
assert [f["field"] for f in schemas["artifacts"].incremental_fields] == ["build_triggered_at"]
+ assert [f["field"] for f in schemas["pipelines"].incremental_fields] == ["triggered_at"]
assert schemas["apps"].incremental_fields == []
# Builds mutate after creation, so append mode is never offered.
assert all(schema.supports_append is False for schema in schemas.values())