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(github): support GitHub API version 2026-03-10 (#71658)

Tom Owers7e26dd95b821
diff --git a/products/warehouse_sources/backend/github_warehouse_repos.py b/products/warehouse_sources/backend/github_warehouse_repos.py
index 880b540cab9b..7276efbac188 100644
--- a/products/warehouse_sources/backend/github_warehouse_repos.py
+++ b/products/warehouse_sources/backend/github_warehouse_repos.py
@@ -118,14 +118,20 @@ def _reconcile_repo_webhooks(
if added:
if signing_secret:
failures.extend(
- source.ensure_webhooks_for_repositories(new_config, webhook_url, team.pk, added, signing_secret)
+ source.ensure_webhooks_for_repositories(
+ new_config, webhook_url, team.pk, added, signing_secret, api_version=source_model.api_version
+ )
)
else:
failures.append(
"no signing secret is stored for this source's webhook; re-create the webhook to cover the added repositories"
)
if removed:
- failures.extend(source.delete_webhooks_for_repositories(new_config, webhook_url, team.pk, removed))
+ failures.extend(
+ source.delete_webhooks_for_repositories(
+ new_config, webhook_url, team.pk, removed, api_version=source_model.api_version
+ )
+ )
if failures:
logger.warning(
"github_repo_webhook_reconcile_partial",
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 86d72532ae37..ade6adb2b5f2 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
@@ -40,6 +40,12 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.github.set
GITHUB_BASE_URL = "https://api.github.com"
+# GitHub's date-based REST API versions are sent in the X-GitHub-Api-Version header. The header is
+# the only version-dependent part for the endpoints we sync — response shapes are compatible across
+# these versions. Every caller — sync, credential validation, webhook management — passes the
+# source's resolved pin; this constant is only the fallback for callers outside a source instance.
+GITHUB_DEFAULT_API_VERSION = "2022-11-28"
+
# Managing repo webhooks needs the `admin:repo_hook` scope on a classic token, or the
# "Repository webhooks: read and write" permission on a fine-grained token. Name both so
# the error/setup guidance doesn't mislead whichever token type the user connected.
@@ -184,11 +190,13 @@ def _resolve_sort_mode(
return "asc"
-def _get_headers(access_token: str, endpoint: str = "") -> dict[str, str]:
+def _get_headers(
+ access_token: str, endpoint: str = "", api_version: str = GITHUB_DEFAULT_API_VERSION
+) -> dict[str, str]:
headers = {
"Authorization": f"Bearer {access_token}",
"Accept": "application/vnd.github+json",
- "X-GitHub-Api-Version": "2022-11-28",
+ "X-GitHub-Api-Version": api_version,
}
# Stargazers needs this Accept header to include the starred_at timestamp.
if endpoint == "stargazers":
@@ -264,14 +272,12 @@ def _should_stop_desc(
return any(_is_older_than_cutoff(item.get(incremental_field), cutoff) for item in data if item)
-def validate_credentials(personal_access_token: str, repository: str) -> tuple[bool, str | None]:
+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."""
url = f"{GITHUB_BASE_URL}/repos/{repository}"
- headers = {
- "Authorization": f"Bearer {personal_access_token}",
- "Accept": "application/vnd.github+json",
- "X-GitHub-Api-Version": "2022-11-28",
- }
+ headers = _get_headers(personal_access_token, api_version=api_version)
try:
response = make_tracked_session().get(url, headers=headers, timeout=10)
@@ -318,7 +324,10 @@ _ORG_PERMISSION_REASON = (
def check_org_endpoint_permission(
- personal_access_token: str, repository: str, egress_identity: GithubEgressIdentity | None = None
+ personal_access_token: str,
+ repository: str,
+ egress_identity: GithubEgressIdentity | None = None,
+ api_version: str = GITHUB_DEFAULT_API_VERSION,
) -> str | None:
"""Probe the org teams endpoint once. Returns None when reachable, or a short reason when the
org grant is missing. Only a real denial (401/403/404) is a missing scope; rate limits, 5xx,
@@ -336,7 +345,7 @@ def check_org_endpoint_permission(
"GET",
url,
source="warehouse",
- headers=_get_headers(personal_access_token),
+ headers=_get_headers(personal_access_token, api_version=api_version),
installation_id=installation_id,
priority=Priority.NORMAL,
timeout=10,
@@ -629,6 +638,7 @@ def _fan_out_get_rows(
should_use_incremental_field: bool,
db_incremental_field_last_value: Any,
egress_identity: GithubEgressIdentity | None = None,
+ api_version: str = GITHUB_DEFAULT_API_VERSION,
) -> Iterator[Any]:
"""Single-hop parent->child fan-out: walk the parent endpoint and emit every child row for each
parent, substituting the parent's field into the child path (workflow_jobs -> {run_id},
@@ -654,7 +664,7 @@ def _fan_out_get_rows(
# org). Skip only that parent walk — a 404 on a specific team's members is not this benign case
# and should still surface.
parent_org_scoped = child_config.fan_out_parent in ORG_SCOPED_ENDPOINTS
- headers = _get_headers(personal_access_token, endpoint)
+ headers = _get_headers(personal_access_token, endpoint, api_version)
batcher = Batcher(logger=logger, chunk_size=2000, chunk_size_bytes=100 * 1024 * 1024)
# A parent with no incremental fields (teams) has no cursor to bound on, so walk it whole.
@@ -756,6 +766,7 @@ def get_rows(
db_incremental_field_last_value: Any = None,
incremental_field: str | None = None,
egress_identity: GithubEgressIdentity | None = None,
+ api_version: str = GITHUB_DEFAULT_API_VERSION,
) -> Iterator[Any]:
config = GITHUB_ENDPOINTS[endpoint]
if config.fan_out_parent is not None:
@@ -768,10 +779,11 @@ def get_rows(
should_use_incremental_field=should_use_incremental_field,
db_incremental_field_last_value=db_incremental_field_last_value,
egress_identity=egress_identity,
+ api_version=api_version,
)
return
- headers = _get_headers(personal_access_token, endpoint)
+ headers = _get_headers(personal_access_token, endpoint, api_version)
batcher = Batcher(logger=logger, chunk_size=2000, chunk_size_bytes=100 * 1024 * 1024)
actual_sort_mode = _resolve_sort_mode(
@@ -911,6 +923,7 @@ def github_source(
webhook_source_manager: Optional[WebhookSourceManager] = None,
egress_identity: GithubEgressIdentity | None = None,
response_name: str | None = None,
+ api_version: str = GITHUB_DEFAULT_API_VERSION,
) -> SourceResponse:
endpoint_config = GITHUB_ENDPOINTS[endpoint]
@@ -993,6 +1006,7 @@ def github_source(
db_incremental_field_last_value=db_incremental_field_last_value,
incremental_field=incremental_field,
egress_identity=egress_identity,
+ api_version=api_version,
)
return SourceResponse(
@@ -1019,14 +1033,19 @@ def _is_repo_hook_permission_error(response: requests.Response) -> bool:
def create_repo_webhook(
- token: str, repo: str, webhook_url: str, events: list[str], secret: str
+ token: str,
+ repo: str,
+ webhook_url: str,
+ events: list[str],
+ secret: str,
+ api_version: str = GITHUB_DEFAULT_API_VERSION,
) -> WebhookCreationResult:
"""Create a repo webhook via POST /repos/{repo}/hooks.
Returns a failed (not raised) result when the token lacks admin:repo_hook so
the caller can surface a manual-setup caption instead of hard-failing.
"""
- headers = _get_headers(token)
+ headers = _get_headers(token, api_version=api_version)
payload = {
"name": "web",
"active": True,
@@ -1072,6 +1091,7 @@ def ensure_repo_webhook(
events: list[str],
secret: str,
egress_identity: GithubEgressIdentity | None = None,
+ api_version: str = GITHUB_DEFAULT_API_VERSION,
) -> WebhookCreationResult:
"""Idempotently ensure a repo webhook pointing at ``webhook_url`` exists with ``secret``.
@@ -1079,7 +1099,7 @@ def ensure_repo_webhook(
re-created — a bare POST would 422 with "Hook already exists on this repository", which
matters both for retried creates and for reconciling a multi-repo source where some repos
already carry the hook. No match falls through to the plain create."""
- hooks, error = _list_repo_hooks(token, repo, egress_identity)
+ hooks, error = _list_repo_hooks(token, repo, egress_identity, api_version=api_version)
if error == "permission":
return WebhookCreationResult(
success=False,
@@ -1093,7 +1113,7 @@ def ensure_repo_webhook(
hook = _match_hook_by_url(hooks or [], webhook_url)
if hook is None:
- return create_repo_webhook(token, repo, webhook_url, events, secret=secret)
+ return create_repo_webhook(token, repo, webhook_url, events, secret=secret, api_version=api_version)
merged_events = sorted(set(hook.get("events") or []) | set(events))
try:
@@ -1101,7 +1121,7 @@ def ensure_repo_webhook(
"PATCH",
f"{GITHUB_BASE_URL}/repos/{repo}/hooks/{hook['id']}",
source="warehouse",
- headers=_get_headers(token),
+ headers=_get_headers(token, api_version=api_version),
installation_id=egress_identity.installation_id if egress_identity is not None else None,
priority=Priority.NORMAL,
timeout=30,
@@ -1137,7 +1157,10 @@ def ensure_repo_webhook(
def _list_repo_hooks(
- token: str, repo: str, egress_identity: GithubEgressIdentity | None = None
+ token: str,
+ repo: str,
+ egress_identity: GithubEgressIdentity | None = None,
+ api_version: str = GITHUB_DEFAULT_API_VERSION,
) -> tuple[list[dict[str, Any]] | None, str | None]:
"""List repo webhooks via GET /repos/{repo}/hooks. Returns (hooks, error); error is
``"permission"`` when the token lacks admin:repo_hook so callers can fall back to manual setup.
@@ -1153,7 +1176,7 @@ def _list_repo_hooks(
"GET",
f"{GITHUB_BASE_URL}/repos/{repo}/hooks?per_page=100",
source="warehouse",
- headers=_get_headers(token),
+ headers=_get_headers(token, api_version=api_version),
installation_id=installation_id,
priority=Priority.NORMAL,
timeout=30,
@@ -1185,10 +1208,14 @@ def _match_hook_by_url(hooks: list[dict[str, Any]], webhook_url: str) -> dict[st
def _find_repo_hook_id(
- token: str, repo: str, webhook_url: str, egress_identity: GithubEgressIdentity | None = None
+ token: str,
+ repo: str,
+ webhook_url: str,
+ egress_identity: GithubEgressIdentity | None = None,
+ api_version: str = GITHUB_DEFAULT_API_VERSION,
) -> tuple[int | None, str | None]:
"""Return (hook_id, error). Matches on config.url == webhook_url."""
- hooks, error = _list_repo_hooks(token, repo, egress_identity)
+ hooks, error = _list_repo_hooks(token, repo, egress_identity, api_version=api_version)
if error is not None:
return None, error
hook = _match_hook_by_url(hooks or [], webhook_url)
@@ -1196,10 +1223,14 @@ def _find_repo_hook_id(
def delete_repo_webhook(
- token: str, repo: str, webhook_url: str, egress_identity: GithubEgressIdentity | None = None
+ token: str,
+ repo: str,
+ webhook_url: str,
+ egress_identity: GithubEgressIdentity | None = None,
+ api_version: str = GITHUB_DEFAULT_API_VERSION,
) -> WebhookDeletionResult:
"""Find the repo webhook matching webhook_url and DELETE /repos/{repo}/hooks/{id}."""
- hook_id, error = _find_repo_hook_id(token, repo, webhook_url, egress_identity)
+ hook_id, error = _find_repo_hook_id(token, repo, webhook_url, egress_identity, api_version=api_version)
if error == "permission":
return WebhookDeletionResult(
success=False,
@@ -1211,7 +1242,7 @@ def delete_repo_webhook(
# Nothing to delete — treat as success, same as Stripe's no-match path.
return WebhookDeletionResult(success=True)
- headers = _get_headers(token)
+ headers = _get_headers(token, api_version=api_version)
try:
response = make_tracked_session().delete(
f"{GITHUB_BASE_URL}/repos/{repo}/hooks/{hook_id}", headers=headers, timeout=30
@@ -1245,7 +1276,12 @@ def _webhook_update_permission_result(events: list[str]) -> WebhookSyncResult:
def update_repo_webhook(
- token: str, repo: str, webhook_url: str, events: list[str], egress_identity: GithubEgressIdentity | None = None
+ token: str,
+ repo: str,
+ webhook_url: str,
+ events: list[str],
+ egress_identity: GithubEgressIdentity | None = None,
+ api_version: str = GITHUB_DEFAULT_API_VERSION,
) -> WebhookSyncResult:
"""Add ``events`` to the repo webhook matching ``webhook_url``, writing only on drift.
@@ -1255,7 +1291,7 @@ def update_repo_webhook(
if not events:
return WebhookSyncResult(success=True)
- hooks, error = _list_repo_hooks(token, repo, egress_identity)
+ hooks, error = _list_repo_hooks(token, repo, egress_identity, api_version=api_version)
if error == "permission":
return _webhook_update_permission_result(events)
if error is not None:
@@ -1281,7 +1317,7 @@ def update_repo_webhook(
"PATCH",
f"{GITHUB_BASE_URL}/repos/{repo}/hooks/{hook['id']}",
source="warehouse",
- headers=_get_headers(token),
+ headers=_get_headers(token, api_version=api_version),
installation_id=egress_identity.installation_id if egress_identity is not None else None,
priority=Priority.NORMAL,
timeout=30,
@@ -1307,10 +1343,14 @@ def update_repo_webhook(
def get_repo_webhook_info(
- token: str, repo: str, webhook_url: str, egress_identity: GithubEgressIdentity | None = None
+ token: str,
+ repo: str,
+ webhook_url: str,
+ egress_identity: GithubEgressIdentity | None = None,
+ api_version: str = GITHUB_DEFAULT_API_VERSION,
) -> ExternalWebhookInfo:
"""List repo webhooks via GET /repos/{repo}/hooks and match config.url == webhook_url."""
- hooks, error = _list_repo_hooks(token, repo, egress_identity)
+ hooks, error = _list_repo_hooks(token, repo, egress_identity, api_version=api_version)
if error == "permission":
return ExternalWebhookInfo(
exists=False,
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.py
index 232e4a041eb1..8272241d40fc 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
@@ -91,8 +91,8 @@ class GithubSource(
OAuthMixin,
):
lists_tables_without_credentials = True # static endpoint catalog — safe for public docs
- supported_versions = ("2022-11-28",)
- default_version = "2022-11-28"
+ supported_versions = ("2022-11-28", "2026-03-10")
+ default_version = "2026-03-10"
api_docs_url = "https://docs.github.com/en/rest/about-the-rest-api/api-versions"
@property
@@ -462,7 +462,9 @@ If automatic creation failed, your token needs webhook permissions — the **adm
for name, repository in org_endpoints.items():
owner = repository.split("/", 1)[0]
if owner not in reason_by_owner:
- reason_by_owner[owner] = check_org_endpoint_permission(access_token, repository, egress_identity)
+ reason_by_owner[owner] = check_org_endpoint_permission(
+ access_token, repository, egress_identity, api_version=self.resolve_api_version(api_version)
+ )
result[name] = reason_by_owner[owner]
return result
@@ -482,7 +484,9 @@ If automatic creation failed, your token needs webhook permissions — the **adm
repositories = self.effective_repositories(config)
failures: list[str] = []
for repository in repositories[: self.MAX_VALIDATED_REPOSITORIES]:
- is_valid, message = validate_github_credentials(access_token, repository)
+ is_valid, message = validate_github_credentials(
+ access_token, repository, api_version=self.resolve_api_version(api_version)
+ )
if is_valid:
continue
# A 401 is token-level — probing further repos yields the same answer.
@@ -555,7 +559,13 @@ If automatic creation failed, your token needs webhook permissions — the **adm
return list(pool.map(fn, repositories))
def ensure_webhooks_for_repositories(
- self, config: GithubSourceConfig, webhook_url: str, team_id: int, repositories: list[str], secret: str
+ self,
+ config: GithubSourceConfig,
+ webhook_url: str,
+ team_id: int,
+ repositories: list[str],
+ secret: str,
+ api_version: str | None = None,
) -> list[str]:
"""Idempotently create/update hooks in the given repos, pinned to the source's existing
signing secret. Used by the repo-list reconcile for newly added repos. Returns per-repo
@@ -563,10 +573,17 @@ If automatic creation failed, your token needs webhook permissions — the **adm
access_token = self._get_access_token(config, team_id)
egress_identity = self._egress_identity(config, team_id)
events = self.get_desired_webhook_events(config, list(GITHUB_WEBHOOK_RESOURCE_MAP.keys())) or []
+ pinned_version = self.resolve_api_version(api_version)
results = self._map_webhook_repositories(
repositories,
lambda repository: ensure_repo_webhook(
- access_token, repository, webhook_url, events, secret=secret, egress_identity=egress_identity
+ access_token,
+ repository,
+ webhook_url,
+ events,
+ secret=secret,
+ egress_identity=egress_identity,
+ api_version=pinned_version,
),
)
return [
@@ -574,16 +591,22 @@ If automatic creation failed, your token needs webhook permissions — the **adm
]
def delete_webhooks_for_repositories(
- self, config: GithubSourceConfig, webhook_url: str, team_id: int, repositories: list[str]
+ self,
+ config: GithubSourceConfig,
+ webhook_url: str,
+ team_id: int,
+ repositories: list[str],
+ api_version: str | None = None,
) -> list[str]:
"""Delete this source's hook from the given repos (repo-list reconcile, removed repos).
Returns per-repo failure messages (empty on full success)."""
access_token = self._get_access_token(config, team_id)
egress_identity = self._egress_identity(config, team_id)
+ pinned_version = self.resolve_api_version(api_version)
results = self._map_webhook_repositories(
repositories,
lambda repository: delete_repo_webhook(
- access_token, repository, webhook_url, egress_identity=egress_identity
+ access_token, repository, webhook_url, egress_identity=egress_identity, api_version=pinned_version
),
)
return [
@@ -606,10 +629,17 @@ If automatic creation failed, your token needs webhook permissions — the **adm
# hog function anyway, so over-subscribing is harmless while enabling a table later is free.
events = self.get_desired_webhook_events(config, list(GITHUB_WEBHOOK_RESOURCE_MAP.keys())) or []
repositories = self._webhook_repositories(config)
+ pinned_version = self.resolve_api_version(api_version)
results = self._map_webhook_repositories(
repositories,
lambda repository: ensure_repo_webhook(
- access_token, repository, webhook_url, events, secret=secret, egress_identity=egress_identity
+ access_token,
+ repository,
+ webhook_url,
+ events,
+ secret=secret,
+ egress_identity=egress_identity,
+ api_version=pinned_version,
),
)
any_success = any(result.success for result in results)
@@ -643,10 +673,16 @@ If automatic creation failed, your token needs webhook permissions — the **adm
# budget as the data plane; PAT sources resolve to an empty identity (record-only).
desired_events = self.get_desired_webhook_events(config, list(GITHUB_WEBHOOK_RESOURCE_MAP.keys())) or []
repositories = self._webhook_repositories(config)
+ pinned_version = self.resolve_api_version(api_version)
results = self._map_webhook_repositories(
repositories,
lambda repository: update_repo_webhook(
- access_token, repository, webhook_url, desired_events, egress_identity=egress_identity
+ access_token,
+ repository,
+ webhook_url,
+ desired_events,
+ egress_identity=egress_identity,
+ api_version=pinned_version,
),
)
failures = [
@@ -662,10 +698,11 @@ If automatic creation failed, your token needs webhook permissions — the **adm
access_token = self._get_access_token(config, team_id)
egress_identity = self._egress_identity(config, team_id)
repositories = self._webhook_repositories(config)
+ pinned_version = self.resolve_api_version(api_version)
results = self._map_webhook_repositories(
repositories,
lambda repository: delete_repo_webhook(
- access_token, repository, webhook_url, egress_identity=egress_identity
+ access_token, repository, webhook_url, egress_identity=egress_identity, api_version=pinned_version
),
)
failures = [
@@ -687,10 +724,11 @@ If automatic creation failed, your token needs webhook permissions — the **adm
merged_events: set[str] = set()
first_info: ExternalWebhookInfo | None = None
repositories = self._webhook_repositories(config)
+ pinned_version = self.resolve_api_version(api_version)
infos = self._map_webhook_repositories(
repositories,
lambda repository: get_repo_webhook_info(
- access_token, repository, webhook_url, egress_identity=egress_identity
+ access_token, repository, webhook_url, egress_identity=egress_identity, api_version=pinned_version
),
)
for repository, info in zip(repositories, infos):
@@ -760,4 +798,5 @@ If automatic creation failed, your token needs webhook permissions — the **adm
webhook_source_manager=webhook_source_manager,
egress_identity=egress_identity,
response_name=response_name,
+ api_version=self.resolve_api_version(inputs.api_version),
)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_api_version_headers.py b/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_api_version_headers.py
new file mode 100644
index 000000000000..73c0be241b91
--- /dev/null
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_api_version_headers.py
@@ -0,0 +1,82 @@
+from collections.abc import Callable
+from typing import Any
+
+import pytest
+from unittest import mock
+
+from products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.github import (
+ GithubAuthMethodConfig,
+ GithubSourceConfig,
+)
+from products.warehouse_sources.backend.temporal.data_imports.sources.github import github
+from products.warehouse_sources.backend.temporal.data_imports.sources.github.source import GithubSource
+
+_CONFIG = GithubSourceConfig(
+ auth_method=GithubAuthMethodConfig(github_integration_id=None, selection="pat", personal_access_token="t"),
+ repository="acme/widgets",
+ repositories=None,
+)
+_TEAM_ID = 123
+_WEBHOOK_URL = "https://ph.example/webhook"
+
+
+def _response() -> mock.Mock:
+ response = mock.Mock(status_code=200, ok=True, headers={}, text="[]")
+ response.json.return_value = []
+ return response
+
+
+def _run(surface: Callable[[GithubSource, str | None], object], api_version: str | None) -> list[dict[str, str]]:
+ """Drive one non-sync surface and return the headers of every outgoing GitHub request."""
+ headers: list[dict[str, str]] = []
+
+ def record(*args: Any, **kwargs: Any) -> mock.Mock:
+ headers.append(kwargs["headers"])
+ return _response()
+
+ session = mock.Mock()
+ session.get.side_effect = record
+ session.post.side_effect = record
+ session.delete.side_effect = record
+ with mock.patch.object(github, "make_tracked_session", return_value=session):
+ with mock.patch.object(github, "github_request", side_effect=record):
+ surface(GithubSource(), api_version)
+ assert headers, "surface made no GitHub request"
+ return headers
+
+
+_SURFACES: dict[str, Callable[[GithubSource, str | None], object]] = {
+ "validate_credentials": lambda source, version: source.validate_credentials(_CONFIG, _TEAM_ID, api_version=version),
+ "get_endpoint_permissions": lambda source, version: source.get_endpoint_permissions(
+ _CONFIG, _TEAM_ID, ["teams"], api_version=version
+ ),
+ "create_webhook": lambda source, version: source.create_webhook(
+ _CONFIG, _WEBHOOK_URL, _TEAM_ID, api_version=version
+ ),
+ "sync_webhook_events": lambda source, version: source.sync_webhook_events(
+ _CONFIG, _WEBHOOK_URL, _TEAM_ID, ["workflow_runs"], api_version=version
+ ),
+ "delete_webhook": lambda source, version: source.delete_webhook(
+ _CONFIG, _WEBHOOK_URL, _TEAM_ID, api_version=version
+ ),
+ "get_external_webhook_info": lambda source, version: source.get_external_webhook_info(
+ _CONFIG, _WEBHOOK_URL, _TEAM_ID, api_version=version
+ ),
+}
+
+
[email protected]("surface", list(_SURFACES))
+ "api_version,expected_header",
+ [
+ ("2022-11-28", "2022-11-28"),
+ ("2026-03-10", "2026-03-10"),
+ # No pin (pre-creation) resolves to the source's default_version, not the module constant.
+ (None, "2026-03-10"),
+ ],
+)
+def test_non_sync_surfaces_send_resolved_api_version(
+ surface: str, api_version: str | None, expected_header: str
+) -> None:
+ for headers in _run(_SURFACES[surface], api_version):
+ assert headers["X-GitHub-Api-Version"] == expected_header
diff --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.py
index 0d60da09e522..a3f4c318b630 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
@@ -451,6 +451,34 @@ class TestGithubSource:
assert kwargs["endpoint"] == "issues"
assert kwargs["response_name"] == "issues"
+ @pytest.mark.parametrize(
+ "pin,expected",
+ [
+ # An existing source pinned to the legacy version keeps syncing on it — the default flip
+ # must never silently move a customer to the new version.
+ ("2022-11-28", "2022-11-28"),
+ ("2026-03-10", "2026-03-10"),
+ # An unpinned source resolves to the current default — new sources land here. Every
+ # pre-existing row was pinned to the legacy version by the versioning-framework backfill
+ # (migration 0075), and creation stamps the pin since, so the flip only reaches new ones.
+ (None, "2026-03-10"),
+ ],
+ )
+ @mock.patch("products.warehouse_sources.backend.temporal.data_imports.sources.github.source.github_source")
+ def test_source_for_pipeline_threads_resolved_api_version(self, mock_github_source, pin, expected):
+ config = _pat_config(repository="legacy/repo", repositories=["legacy/repo"])
+ inputs = mock.MagicMock()
+ inputs.team_id = self.team_id
+ inputs.schema_name = "issues"
+ inputs.schema_metadata = None
+ inputs.s3_folder_name = "issues"
+ inputs.should_use_incremental_field = False
+ inputs.api_version = pin
+
+ self.source.source_for_pipeline(config, mock.MagicMock(), inputs)
+
+ assert mock_github_source.call_args.kwargs["api_version"] == expected
+
@mock.patch("products.warehouse_sources.backend.temporal.data_imports.sources.github.source.ensure_repo_webhook")
def test_create_webhook_shares_one_secret_across_repos(self, mock_ensure):
from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import WebhookCreationResult
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_teams.py b/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_teams.py
index 7b44c06a7bb0..3c0b5f66d3a3 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_teams.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_teams.py
@@ -210,6 +210,36 @@ def test_org_permission_probe_reports_missing_grant(status_code: int) -> None:
assert "/orgs/acme/teams" in request.call_args.args[1]
+ "api_version,expected_header",
+ [
+ # The pin resolved by the source class must reach the outgoing X-GitHub-Api-Version header for
+ # each supported version; a broken thread-through would silently sync every source on one version.
+ ("2022-11-28", "2022-11-28"),
+ ("2026-03-10", "2026-03-10"),
+ # Omitted (creation-time paths carry no pin) falls back to the legacy default.
+ (None, "2022-11-28"),
+ ],
+)
+def test_get_rows_sends_pinned_api_version_header(api_version: str | None, expected_header: str) -> None:
+ extra: dict[str, Any] = {} if api_version is None else {"api_version": api_version}
+ with mock.patch.object(
+ github, "_fetch_page", side_effect=_fetch_page_by_url({"/repos/acme/widgets": _response([])})
+ ) as fetch:
+ list(
+ github.get_rows(
+ personal_access_token="tok",
+ repository="acme/widgets",
+ endpoint="issues",
+ logger=mock.Mock(),
+ resumable_source_manager=_no_resume(),
+ **extra,
+ )
+ )
+
+ assert fetch.call_args.args[1]["X-GitHub-Api-Version"] == expected_header
+
+
@pytest.mark.parametrize(
"request_behavior",
[