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(data-warehouse): add 5 missing GitHub tables (#77301)

Tom Owersb7edbcadf615
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS.md
index b8584f1cf8eb..a029631abfa6 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS.md
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS.md
@@ -188,26 +188,45 @@ while in here.
### GitHub — spec-verified
-Diffed against [github/rest-api-description](https://github.com/github/rest-api-description).
-Ten tables focused on code and CI.
-The gaps make review-latency and issue-lifecycle analysis impossible, which is the main
-engineering-analytics use case.
-
-- [ ] `issues/comments` and `pulls/comments` — no comment data at all, so review latency and discussion volume are unavailable.
-- [ ] `issues/events` — labeled, assigned, closed, reopened transitions. Needed for time-in-state.
-- [ ] Repository metadata itself. There is no `repositories` table, so stars/forks/language/visibility per repo are unavailable even though the source is repo-scoped.
-- [ ] `branches`, `tags`.
-- [ ] `contributors`, `collaborators`.
-- [ ] `labels`, `milestones`.
-- [ ] `deployments`, `environments`.
-- [ ] `traffic/views`, `traffic/clones`, plus referrers and popular paths.
-- [ ] `stats/contributors`, `stats/commit_activity`, `stats/participation`, `stats/code_frequency`.
-- [ ] Check runs and commit statuses — CI signal at commit granularity, complementing `workflow_runs`.
-- [ ] `actions/workflows`, `actions/artifacts`, `actions/runners`, `actions/caches`.
-- [ ] `code-scanning/alerts`, `dependabot/alerts`, `secret-scanning/alerts` — security posture over time.
-- [ ] `forks`, `subscribers` (watchers), `topics`.
-- [ ] `rulesets`, `security-advisories`, `hooks`, `languages`, `community/profile`, `dependency-graph/sbom`.
-- [ ] Discussions.
+Re-diffed 2026-08-04 against [github/rest-api-description](https://github.com/github/rest-api-description)
+`descriptions/api.github.com/api.github.com.2022-11-28.json`, the description for the API version the
+source pins.
+The original ten tables have grown to 54, so everything the first audit flagged now ships except
+Discussions, and the remaining gaps are narrow.
+
+Have: `issues`, `issue_comments`, `issue_events`, `issue_types`, `labels`, `milestones`,
+`pull_requests`, `pull_request_comments`, `reviews`, `commits`, `commit_comments`,
+`commit_statuses`, `check_runs`, `branches`, `tags`, `forks`, `stargazers`, `subscribers`,
+`contributors`, `collaborators`, `teams`, `team_members`, `repository_teams`, `repository`,
+`repository_activity`, `topics`, `languages`, `community_profile`, `releases`, `workflows`,
+`workflow_runs`, `workflow_jobs`, `artifacts`, `runners`, `actions_caches`, `deployments`,
+`deployment_statuses`, `environments`, `code_scanning_alerts`, `dependabot_alerts`,
+`secret_scanning_alerts`, `security_advisories`, `dependency_sbom`, `rulesets`, `hooks`,
+`traffic_views`, `traffic_clones`, `traffic_referrers`, `traffic_paths`, `contributor_stats`,
+`commit_activity_stats`, `participation_stats`, `code_frequency_stats`, `punch_card_stats`.
+
+- [x] `issues/comments` and `pulls/comments` — no comment data at all, so review latency and discussion volume are unavailable.
+- [x] `issues/events` — labeled, assigned, closed, reopened transitions. Needed for time-in-state.
+- [x] Repository metadata itself. There is no `repositories` table, so stars/forks/language/visibility per repo are unavailable even though the source is repo-scoped.
+- [x] `branches`, `tags`.
+- [x] `contributors`, `collaborators`.
+- [x] `labels`, `milestones`.
+- [x] `deployments`, `environments`.
+- [x] `traffic/views`, `traffic/clones`, plus referrers and popular paths.
+- [x] `stats/contributors`, `stats/commit_activity`, `stats/participation`, `stats/code_frequency`.
+- [x] Check runs and commit statuses — CI signal at commit granularity, complementing `workflow_runs`.
+- [x] `actions/workflows`, `actions/artifacts`, `actions/runners`, `actions/caches`.
+- [x] `code-scanning/alerts`, `dependabot/alerts`, `secret-scanning/alerts` — security posture over time.
+- [x] `forks`, `subscribers` (watchers), `topics`.
+- [x] `rulesets`, `security-advisories`, `hooks`, `languages`, `community/profile`, `dependency-graph/sbom`.
+- [ ] Discussions (skipped: GraphQL only. The 2026-08-04 description carries no discussion path at all — repository Discussions have never had a REST endpoint, and the old team-discussion endpoints are gone from both the spec and the REST reference. Reaching them means a second transport, a point-metered rate limit the egress limiter does not model, and a GitHub App permission every existing installation would have to re-accept.)
+- [x] `repos/{repo}/activity` — pushes, force pushes, merges, branch creations and deletions. The only record that a force push or branch deletion happened, since both rewrite the history `commits` reads.
+- [x] `repos/{repo}/comments` — commit comments, the third comment surface next to issue and review comments.
+- [x] `repos/{repo}/issue-types` — lookup for the type an issue carries, which `issues` otherwise stores as an opaque nested object.
+- [x] `repos/{repo}/teams` — the teams granted access to the repository, for ownership analysis without the org grant.
+- [x] `stats/punch_card` — commit counts per weekday and hour, completing the statistics family.
+- [ ] `code-quality/findings` and `pulls/stacks` (skipped: both back GitHub features that are still rolling out, and neither endpoint returns anything on an account without the feature enabled, so they would ship as tables that stay empty or error for nearly everyone. Worth revisiting once the features are generally available).
+- [ ] `repos/{repo}/events` (skipped: GitHub caps this feed at 300 events over 90 days and it restates what `repository_activity`, `issues`, and `pull_requests` already carry).
### HubSpot — our side code-verified, vendor side needs confirmation
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/github/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/github/canonical_descriptions.py
index d2289e8393e8..537f031d2c63 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/github/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/github/canonical_descriptions.py
@@ -288,6 +288,69 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"updated_at": "Time at which the community profile was last updated.",
},
},
+ "repository_activity": {
+ "description": "A change to the repository's git history — a push, force push, merge, or branch creation or deletion — with the commits and user behind it.",
+ "docs_url": "https://docs.github.com/en/rest/repos/repos#list-repository-activities",
+ "columns": {
+ "id": "Unique identifier for the activity.",
+ "node_id": "Global node identifier for the activity.",
+ "before": "SHA of the commit the reference pointed at before the activity.",
+ "after": "SHA of the commit the reference pointed at after the activity.",
+ "ref": "The full git reference the activity happened on, as refs/heads/<branch name>.",
+ "timestamp": "Time at which the activity occurred.",
+ "activity_type": "The kind of activity (push, force_push, branch_creation, branch_deletion, pr_merge, merge_queue_merge).",
+ "actor": "The user who performed the activity.",
+ },
+ },
+ "repository_teams": {
+ "description": "A team that has been granted access to the repository, with the permission level it holds.",
+ "docs_url": "https://docs.github.com/en/rest/repos/repos#list-repository-teams",
+ "columns": {
+ "id": "Unique identifier for the team.",
+ "node_id": "Global node identifier for the team.",
+ "name": "The team's display name.",
+ "slug": "URL-friendly version of the team's name.",
+ "description": "The team's description.",
+ "privacy": "Whether the team is visible to all organization members (closed) or only to its own members (secret).",
+ "notification_setting": "Whether team members are notified when the team is mentioned.",
+ "permission": "The permission the team has on the repository (pull, triage, push, maintain, admin).",
+ "parent": "The parent team, for nested teams.",
+ "html_url": "Web URL for the team on GitHub.",
+ },
+ },
+ "commit_comments": {
+ "description": "A comment left directly on a commit, as opposed to on an issue or a pull request review, across the whole repository.",
+ "docs_url": "https://docs.github.com/en/rest/commits/comments",
+ "columns": {
+ "id": "Unique identifier for the comment.",
+ "node_id": "Global node identifier for the comment.",
+ "commit_id": "SHA of the commit the comment was posted on.",
+ "user": "The user who wrote the comment.",
+ "body": "The comment's text in markdown.",
+ "path": "Path of the file the comment is anchored to, if any.",
+ "position": "Position in the diff the comment is anchored to, if any.",
+ "line": "Line of the file the comment is anchored to, if any.",
+ "author_association": "The commenter's relationship to the repository (e.g. MEMBER, COLLABORATOR, CONTRIBUTOR).",
+ "reactions": "Reaction counts on the comment.",
+ "html_url": "Web URL for the comment on GitHub.",
+ "created_at": "Time at which the comment was created.",
+ "updated_at": "Time at which the comment was last edited.",
+ },
+ },
+ "issue_types": {
+ "description": "An issue type available to the repository, inherited from its organization owner. Decodes the type an issue carries.",
+ "docs_url": "https://docs.github.com/en/rest/repos/issue-types",
+ "columns": {
+ "id": "Unique identifier for the issue type.",
+ "node_id": "Global node identifier for the issue type.",
+ "name": "The issue type's name (e.g. Bug, Feature, Task).",
+ "description": "The issue type's description.",
+ "color": "The color the issue type is displayed in.",
+ "is_enabled": "Whether the issue type can currently be applied to issues.",
+ "created_at": "Time at which the issue type was created.",
+ "updated_at": "Time at which the issue type was last updated.",
+ },
+ },
"issue_comments": {
"description": "A comment on an issue or pull request conversation, across the whole repository.",
"docs_url": "https://docs.github.com/en/rest/issues/comments",
@@ -744,4 +807,13 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"deletions": "Lines deleted in the week, as a negative number.",
},
},
+ "punch_card_stats": {
+ "description": "Commit counts per weekday and hour of day, showing when the repository is worked on. GitHub returns these as positional arrays, so the columns are named on the way in.",
+ "docs_url": "https://docs.github.com/en/rest/metrics/statistics",
+ "columns": {
+ "day": "Day of the week, from 0 (Sunday) to 6 (Saturday).",
+ "hour": "Hour of the day, from 0 to 23.",
+ "commits": "Commits made during that hour on that weekday, in the time zone of each commit.",
+ },
+ },
}
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 2be24c1d827a..ccf09b90b98e 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
@@ -71,9 +71,10 @@ class GithubEmptyRepositoryError(Exception):
class GithubOrgNotFoundError(Exception):
"""GitHub returns 404 on the org-scoped endpoints (``/orgs/{org}/teams`` and the members
fan-out) when the repository owner is a personal account rather than an organization, or the
- token has no org access. There is nothing to sync in that case, so ``_fetch_page`` raises this on
- org-scoped endpoints and the caller syncs zero rows — a benign skip, not a "repository not found"
- that should fail the schema."""
+ token has no org access, and on the ``tolerate_not_found`` endpoints (issue types, repository
+ teams) whose resource simply does not exist for the repository. There is nothing to sync in
+ either case, so ``_fetch_page`` raises this for those endpoints and the caller syncs zero rows —
+ a benign skip, not a "repository not found" that should fail the schema."""
pass
@@ -586,6 +587,18 @@ def _rows_from_code_frequency(body: Any, repository: str) -> list[dict[str, Any]
]
+def _rows_from_punch_card(body: Any, repository: str) -> list[dict[str, Any]]:
+ """/stats/punch_card answers positional arrays ([day, hour, commits]) rather than objects, so
+ the columns are named here. day is 0-6 (Sunday to Saturday) and hour is 0-23."""
+ if not isinstance(body, list):
+ return []
+ return [
+ {"day": entry[0], "hour": entry[1], "commits": entry[2]}
+ for entry in body
+ if isinstance(entry, list | tuple) and len(entry) >= 3
+ ]
+
+
def _rows_from_dependency_sbom(body: Any, repository: str) -> list[dict[str, Any]]:
"""/dependency-graph/sbom answers one SPDX document; its packages are the grain a dependency
inventory is queried at. SPDXID is renamed so the column follows the rest of the source."""
@@ -613,6 +626,7 @@ _BODY_TRANSFORMS: dict[str, Callable[[Any, str], list[dict[str, Any]]]] = {
"community_profile": _rows_from_community_profile,
"participation_stats": _rows_from_participation_stats,
"code_frequency_stats": _rows_from_code_frequency,
+ "punch_card_stats": _rows_from_punch_card,
"dependency_sbom": _rows_from_dependency_sbom,
}
@@ -1028,15 +1042,18 @@ def get_rows(
else:
url = _build_initial_url(config, repository, initial_params)
- org_scoped = endpoint in ORG_SCOPED_ENDPOINTS
+ # A 404 is normally fatal (wrong repository, revoked access), but for the org-scoped tables and
+ # the endpoints flagged tolerate_not_found it just means the resource does not exist for this
+ # repository, so those sync zero rows instead of failing the schema.
+ skip_on_not_found = endpoint in ORG_SCOPED_ENDPOINTS or config.tolerate_not_found
while True:
try:
- response = _fetch_page(url, headers, logger, egress_identity, skip_on_not_found=org_scoped)
+ response = _fetch_page(url, headers, logger, egress_identity, skip_on_not_found=skip_on_not_found)
except GithubEmptyRepositoryError:
logger.debug(f"Github: repository has no commits (empty repository), syncing zero rows: url={url}")
break
except GithubOrgNotFoundError:
- logger.debug(f"Github: no accessible org teams for {endpoint}, syncing zero rows: url={url}")
+ logger.debug(f"Github: {endpoint} not available for this repository, syncing zero rows: url={url}")
break
except GithubRepositoryTooLargeError:
logger.debug(f"Github: repository too large for code frequency stats, syncing zero rows: url={url}")
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/github/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/github/settings.py
index 3e3b18567b63..16b0d9c82771 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/github/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/github/settings.py
@@ -79,6 +79,12 @@ class GithubEndpointConfig:
# checkpoints the watermark assuming ascending order. workflow_runs and deployments are the
# original cases and are matched by name via _ALWAYS_NEWEST_FIRST_ENDPOINTS in github.py.
always_desc: bool = False
+ # A 404 on this endpoint means the resource does not exist for this repository rather than that
+ # the repository or token is wrong, so the sync writes zero rows instead of failing. Issue types
+ # and repository teams only exist under an organization owner, so a user-owned repo 404s on both
+ # even with a perfectly good token. (The org-scoped endpoints predate this flag and are matched
+ # by name via ORG_SCOPED_ENDPOINTS in github.py.)
+ tolerate_not_found: bool = False
def _datetime_field(field: str) -> IncrementalField:
@@ -424,6 +430,38 @@ GITHUB_ENDPOINTS: dict[str, GithubEndpointConfig] = {
primary_key="repository",
param_style="plain",
),
+ "repository_activity": GithubEndpointConfig(
+ name="repository_activity",
+ # Pushes, force pushes, merges, and branch creations and deletions, repo-wide. This is the
+ # only place force pushes and branch deletions are visible at all: they rewrite or remove
+ # history, so nothing in commits or pull_requests records that they happened.
+ # The endpoint takes no `since` filter but answers newest-first, so incremental syncs
+ # paginate down and stop at the watermark, the same way issue_events does.
+ path="/repos/{repository}/activity",
+ partition_key="timestamp", # When the activity happened; immutable.
+ incremental_fields=[_datetime_field("timestamp")],
+ default_incremental_field="timestamp",
+ param_style="plain",
+ # desc is already the endpoint's default, but the descending walk is what makes the
+ # watermark stop correct, so send it rather than depend on the default staying put.
+ extra_params={"direction": "desc"},
+ sort_mode="desc",
+ always_desc=True,
+ ),
+ "repository_teams": GithubEndpointConfig(
+ name="repository_teams",
+ # The teams granted access to this repository, with the permission level each holds. Unlike
+ # the org-wide teams table this is repo-scoped, so it answers "who owns this repo" without
+ # the org membership grant.
+ path="/repos/{repository}/teams",
+ incremental_fields=[],
+ param_style="plain",
+ # GitHub answers 404 rather than 403 when the caller cannot see a repository's teams, and a
+ # user-owned repo has no teams at all, so a default connection could enable a table that
+ # only ever stays empty. Leave it deselected and let org-owned repos opt in.
+ should_sync_default=False,
+ tolerate_not_found=True,
+ ),
# --- Issue and review discussion ------------------------------------------------------
"issue_comments": GithubEndpointConfig(
name="issue_comments",
@@ -445,6 +483,28 @@ GITHUB_ENDPOINTS: dict[str, GithubEndpointConfig] = {
param_style="sorted",
supports_since_param=True,
),
+ "commit_comments": GithubEndpointConfig(
+ name="commit_comments",
+ # The third comment surface, alongside issue_comments and pull_request_comments: comments
+ # left on a commit directly rather than through an issue or a pull request review.
+ path="/repos/{repository}/comments",
+ partition_key="created_at",
+ # Rows come back ordered by ascending id and the endpoint takes no `since` filter or sort,
+ # so an incremental sync would still walk every page. Full refresh only.
+ incremental_fields=[],
+ param_style="plain",
+ ),
+ "issue_types": GithubEndpointConfig(
+ name="issue_types",
+ # Lookup table for the issue type an issue carries (Bug, Feature, Task, plus whatever the
+ # organization defines). issues stores it as a nested object per row, so without this there
+ # is nothing to group by when a type is renamed or retired.
+ path="/repos/{repository}/issue-types",
+ incremental_fields=[],
+ param_style="plain",
+ # Issue types are inherited from the organization owner, so a user-owned repository 404s.
+ tolerate_not_found=True,
+ ),
"issue_events": GithubEndpointConfig(
name="issue_events",
# Labeled / assigned / closed / reopened transitions, repo-wide. The endpoint takes no time
@@ -758,6 +818,15 @@ GITHUB_ENDPOINTS: dict[str, GithubEndpointConfig] = {
primary_key="week",
param_style="plain",
),
+ "punch_card_stats": GithubEndpointConfig(
+ name="punch_card_stats",
+ # Returns positional arrays ([day, hour, commits]); the body transform names them. One row
+ # per weekday/hour bucket, so the whole table is at most 168 rows.
+ path="/repos/{repository}/stats/punch_card",
+ incremental_fields=[],
+ primary_key=["day", "hour"],
+ param_style="plain",
+ ),
}
ENDPOINTS = tuple(GITHUB_ENDPOINTS.keys())
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_repository_endpoints.py b/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_repository_endpoints.py
index 0a991ead9e82..36e055203fbb 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_repository_endpoints.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_repository_endpoints.py
@@ -2,6 +2,7 @@ import json
from datetime import UTC, datetime
from typing import Any
+import pytest
from unittest import mock
import pyarrow as pa
@@ -59,6 +60,39 @@ def _run(
return rows, calls
+def _run_over_transport(endpoint: str) -> list[dict[str, Any]]:
+ """Same walk as `_run`, but through the real `_fetch_page` so the response-status handling is
+ exercised rather than stubbed out."""
+ tables = list(
+ github.get_rows(
+ personal_access_token="tok",
+ repository="acme/widgets",
+ endpoint=endpoint,
+ logger=mock.Mock(),
+ resumable_source_manager=_no_resume(),
+ )
+ )
+
+ rows: list[dict[str, Any]] = []
+ for table in tables:
+ assert isinstance(table, pa.Table)
+ rows.extend(table.to_pylist())
+ return rows
+
+
+def _not_found_response() -> mock.Mock:
+ response = mock.Mock(spec=requests.Response)
+ response.status_code = 404
+ response.ok = False
+ response.headers = {}
+ response.text = "Not Found"
+ response.request = None
+ response.raise_for_status.side_effect = requests.exceptions.HTTPError(
+ "404 Client Error: Not Found for url", response=response
+ )
+ return response
+
+
class TestListParams:
@parameterized.expand(
[
@@ -70,6 +104,11 @@ class TestListParams:
("traffic_views", {"per_page"}),
("issue_events", {"per_page"}),
("forks", {"per_page", "sort"}),
+ # /activity answers 422 on an unknown sort or state, so it must stay a plain read
+ # carrying only the direction that makes the watermark stop correct.
+ ("repository_activity", {"per_page", "direction"}),
+ ("commit_comments", {"per_page"}),
+ ("issue_types", {"per_page"}),
# "sorted" endpoints keep sort/direction but must not send state.
("code_scanning_alerts", {"per_page", "sort", "direction"}),
("security_advisories", {"per_page", "sort", "direction"}),
@@ -124,6 +163,7 @@ class TestListParams:
# rest of the history.
("issue_events", "desc"),
("forks", "desc"),
+ ("repository_activity", "desc"),
# Endpoints without the flag still start ascending and only flip once a cutoff exists.
("issue_comments", "asc"),
("milestones", "asc"),
@@ -168,6 +208,14 @@ class TestBodyTransforms:
{"week": 1336885200, "additions": 3, "deletions": 0},
],
),
+ (
+ "punch_card_stats",
+ [[0, 13, 4], [2, 14, 25]],
+ [
+ {"day": 0, "hour": 13, "commits": 4},
+ {"day": 2, "hour": 14, "commits": 25},
+ ],
+ ),
(
# The weekly counts arrive as arrays; the batcher lands them as their JSON encoding.
"participation_stats",
@@ -222,6 +270,31 @@ class TestBodyTransforms:
assert rows == [{"id": 3, "name": "production"}]
+class TestNotFoundTolerance:
+ @parameterized.expand(
+ [
+ # Issue types and repository teams are inherited from an organization owner, so a
+ # user-owned repository 404s on both even with a perfectly good token. Failing there
+ # would break the whole schema for every personal repository.
+ ("issue_types", True),
+ ("repository_teams", True),
+ # A plain repo-scoped table keeps 404 fatal, so a genuinely wrong or revoked repository
+ # still fails loud instead of quietly syncing an empty table forever.
+ ("labels", False),
+ ]
+ )
+ def test_404_syncs_zero_rows_only_where_the_resource_is_optional(self, endpoint: str, tolerated: bool) -> None:
+ session = mock.Mock()
+ session.request.return_value = _not_found_response()
+
+ with mock.patch.object(github, "make_tracked_session", return_value=session):
+ if not tolerated:
+ with pytest.raises(requests.exceptions.HTTPError):
+ _run_over_transport(endpoint)
+ return
+ assert _run_over_transport(endpoint) == []
+
+
class TestRowMappers:
def test_secret_scanning_alert_never_carries_the_secret(self) -> None:
# The leaked credential itself must never land in a customer's warehouse, whichever API