From 7fbf6ed11a2179b78699c3a0e33e4c1c15d04b77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jeffry=20W=C3=BCrmli?= Date: Thu, 3 Dec 2026 13:08:55 +0100 Subject: [PATCH 1/2] HGP-70: Show repository visibility by default --- CHANGELOG.md | 6 ++++ README.md | 2 +- custom_components/github_pulse/icons.json | 8 +++++ .../github_pulse/repository_fetch.py | 10 ++++++- .../github_pulse/sensor_repository.py | 13 ++++++++- .../github_pulse/translations/de.json | 8 +++++ .../github_pulse/translations/en.json | 8 +++++ tests/test_icons.py | 1 + tests/test_repository_fetch.py | 29 +++++++++++++++++++ tests/test_repository_sensors.py | 20 +++++++++++++ 10 files changed, 102 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a227e6..9fd0d85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to this project are documented here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project uses [Semantic Versioning](https://semver.org/). +## [Unreleased] + +### Added + +- A **Visibility** sensor for every tracked repository, on by default, showing whether the repository is public, private or internal. It also appears for repositories you already track. + ## [1.6.0] - 2026-11-27 ### Added diff --git a/README.md b/README.md index 75b7d5c..499b3b9 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ To replace the token, open the integration, choose **Reconfigure** and enter the | | Part | Entities | |----|------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 👤 | Profile | Contributions, commits and pull requests this month; change versus last month and last year (like for like); busiest month; current and longest streak; top language and language shift (estimated) | -| 📁 | Repositories | One device per repository: stars, forks, open issues and pull requests, latest release, CI state of the default branch; commits and active days this month and the change versus last month and last year (like for like); pull requests and issues created this month; all counting every author | +| 📁 | Repositories | One device per repository: stars, forks, open issues and pull requests, visibility (public, private or internal), latest release, CI state of the default branch; commits and active days this month and the change versus last month and last year (like for like); pull requests and issues created this month; all counting every author | | ⚙️ | Workflow runs | Per repository, if you turn on **Track workflow runs**: last result, runs today, queued runs, failure rate over 7 and 30 days, average duration, and a binary sensor while a workflow runs | | 🔔 | Events | Event entities per repository (workflow failed or recovered, release published) and for your account (review requested, pull request merged), also fired on the event bus | | 🧪 | Custom queries | Your own read-only GraphQL query as a sensor, added under **Add custom query**. Rendered with templates over `value_json`. Presets included; see the [guide](docs/custom-queries.md) | diff --git a/custom_components/github_pulse/icons.json b/custom_components/github_pulse/icons.json index 6ba98ac..4b3bce4 100644 --- a/custom_components/github_pulse/icons.json +++ b/custom_components/github_pulse/icons.json @@ -45,6 +45,14 @@ "expected": "mdi:clock-outline" } }, + "visibility": { + "default": "mdi:eye-lock-outline", + "state": { + "public": "mdi:earth", + "private": "mdi:lock", + "internal": "mdi:office-building" + } + }, "unique_visitors_14d": {"default": "mdi:account-group-outline"}, "views_14d": {"default": "mdi:eye-outline"}, "unique_cloners_14d": {"default": "mdi:account-arrow-down-outline"}, diff --git a/custom_components/github_pulse/repository_fetch.py b/custom_components/github_pulse/repository_fetch.py index 474cd9c..3a7e148 100644 --- a/custom_components/github_pulse/repository_fetch.py +++ b/custom_components/github_pulse/repository_fetch.py @@ -24,12 +24,13 @@ ) from .const import LOGGER +VISIBILITIES = ["public", "private", "internal"] BATCH_SIZE = 10 COMMIT_PAGE = 100 _TIME = "%Y-%m-%dT%H:%M:%SZ" _FIELDS = """ - nameWithOwner stargazerCount forkCount isArchived pushedAt + nameWithOwner stargazerCount forkCount isArchived visibility pushedAt watchers { totalCount } issues(states: OPEN) { totalCount } pullRequests(states: OPEN) { totalCount } @@ -96,6 +97,7 @@ class RepositorySnapshot: activity: RepositoryActivity | None = None pull_requests_this_month: int | None = None issues_this_month: int | None = None + visibility: str | None = None def _history(alias: str, rng: DateRange, zone: ZoneInfo, *, nodes: bool) -> str: @@ -204,6 +206,11 @@ def _issue_count(raw: dict[str, Any] | None) -> int | None: return None if raw is None else raw["issueCount"] +def _visibility(raw: str | None) -> str | None: + value = (raw or "").lower() + return value if value in VISIBILITIES else None + + def parse_snapshot( raw: dict[str, Any], today: date, @@ -232,6 +239,7 @@ def parse_snapshot( last_commit_at=_time(commit.get("committedDate")), ci_state=rollup.get("state"), latest_release=_release(raw.get("latestRelease")), + visibility=_visibility(raw.get("visibility")), activity=_activity(commit, today, zone), pull_requests_this_month=_issue_count(pull_requests), issues_this_month=_issue_count(issues), diff --git a/custom_components/github_pulse/sensor_repository.py b/custom_components/github_pulse/sensor_repository.py index 9845505..74d7508 100644 --- a/custom_components/github_pulse/sensor_repository.py +++ b/custom_components/github_pulse/sensor_repository.py @@ -25,7 +25,11 @@ visitor_trend, ) from .repository_coordinator import GROUP_DOWNLOADS, GROUP_OVERVIEW, GROUP_TRAFFIC -from .repository_fetch import RepositoryActivity, RepositorySnapshot +from .repository_fetch import ( + VISIBILITIES, + RepositoryActivity, + RepositorySnapshot, +) CI_STATES = ["success", "failure", "pending", "error", "expected"] @@ -327,6 +331,13 @@ def _traffic_description( options=CI_STATES, value_fn=_ci_state, ), + RepositorySensorDescription( + key="visibility", + translation_key="visibility", + device_class=SensorDeviceClass.ENUM, + options=VISIBILITIES, + value_fn=lambda view: view.snapshot.visibility, + ), RepositorySensorDescription( key="watchers", translation_key="watchers", diff --git a/custom_components/github_pulse/translations/de.json b/custom_components/github_pulse/translations/de.json index fba710b..95a7a2f 100644 --- a/custom_components/github_pulse/translations/de.json +++ b/custom_components/github_pulse/translations/de.json @@ -176,6 +176,14 @@ "expected": "Erwartet" } }, + "visibility": { + "name": "Sichtbarkeit", + "state": { + "public": "Öffentlich", + "private": "Privat", + "internal": "Intern" + } + }, "watchers": { "name": "Beobachter" }, diff --git a/custom_components/github_pulse/translations/en.json b/custom_components/github_pulse/translations/en.json index f5dd1ee..c5fe6cb 100644 --- a/custom_components/github_pulse/translations/en.json +++ b/custom_components/github_pulse/translations/en.json @@ -176,6 +176,14 @@ "expected": "Expected" } }, + "visibility": { + "name": "Visibility", + "state": { + "public": "Public", + "private": "Private", + "internal": "Internal" + } + }, "watchers": { "name": "Watchers" }, diff --git a/tests/test_icons.py b/tests/test_icons.py index 54729fa..f34e82a 100644 --- a/tests/test_icons.py +++ b/tests/test_icons.py @@ -11,6 +11,7 @@ PACKAGE = Path(__file__).parents[1] / "custom_components/github_pulse" STATE_ICON_KEYS = { ("sensor", "ci_state"), + ("sensor", "visibility"), ("sensor", "actions_last_result"), ("binary_sensor", "actions_running"), } diff --git a/tests/test_repository_fetch.py b/tests/test_repository_fetch.py index 23e647c..21d526c 100644 --- a/tests/test_repository_fetch.py +++ b/tests/test_repository_fetch.py @@ -53,6 +53,7 @@ "stargazerCount": 42, "forkCount": 7, "isArchived": False, + "visibility": "PRIVATE", "pushedAt": "2026-10-24T10:00:00Z", "watchers": {"totalCount": 5}, "issues": {"totalCount": 3}, @@ -413,3 +414,31 @@ async def test_without_repositories_no_coordinator_is_created( def test_the_listing_query_is_valid_graphql() -> None: assert parse_query(_LIST_QUERY).declared_variables == frozenset() + + +def test_query_asks_for_the_visibility() -> None: + query, _ = build_query(["a/b"], TODAY, ZONE) + + assert "visibility" in query + + +@pytest.mark.parametrize( + ("raw", "expected"), + [ + ("PUBLIC", "public"), + ("PRIVATE", "private"), + ("INTERNAL", "internal"), + ("SOMETHING_NEW", None), + (None, None), + ], +) +async def test_snapshot_reads_the_visibility( + raw: str | None, expected: str | None +) -> None: + client = _client(r0={**RAW, "visibility": raw}) + + snapshots = await fetch_snapshots(client, ["a/b"], today=TODAY, zone=ZONE) + + snapshot = snapshots["a/b"] + assert snapshot is not None + assert snapshot.visibility == expected diff --git a/tests/test_repository_sensors.py b/tests/test_repository_sensors.py index c0da25e..84c431b 100644 --- a/tests/test_repository_sensors.py +++ b/tests/test_repository_sensors.py @@ -5,6 +5,7 @@ from collections.abc import Callable from datetime import UTC, datetime from typing import Any +from unittest.mock import patch import pytest from custom_components.github_pulse.const import ( @@ -397,3 +398,22 @@ async def test_traffic_sensors_are_unavailable_without_push_access( for key in TRAFFIC_KEYS: assert _state(hass, "Octocat/Hello-World", key).state == "unavailable", key assert _state(hass, "Octocat/Hello-World", "stars").state == "42" + + +async def test_visibility_is_shown_by_default_and_follows_github( + hass: HomeAssistant, patch_session: Callable[[FakeSession], None] +) -> None: + entry = await _setup(hass, patch_session) + repo = "Octocat/Hello-World" + + state = _state(hass, repo, "visibility") + assert state.state == "private" + assert state.attributes["options"] == ["public", "private", "internal"] + + coordinator = entry.runtime_data.repositories + assert coordinator is not None + with patch.dict(RAW, {"visibility": "PUBLIC"}): + await coordinator.async_refresh() + await hass.async_block_till_done() + + assert _state(hass, repo, "visibility").state == "public" From ca426f4c02c27b95a6605e0b724eeb464955979d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jeffry=20W=C3=BCrmli?= Date: Thu, 3 Dec 2026 13:09:58 +0100 Subject: [PATCH 2/2] HGP-70: Mention the visibility state icon in the README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 499b3b9..9d71177 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ To replace the token, open the integration, choose **Reconfigure** and enter the | 🧪 | Custom queries | Your own read-only GraphQL query as a sensor, added under **Add custom query**. Rendered with templates over `value_json`. Presets included; see the [guide](docs/custom-queries.md) | | ➕ | Optional sensors | Reviews, issues, active days, strongest weekday, watchers, release downloads, days since last commit or release, pull requests awaiting your review, most active hour and night-owl score (approximate, from GitHub's last 300 events), average time to merge (last 50 merged pull requests), stale pull requests (open, untouched for 14 days), year in review (one-line summary with the details as attributes), followers and following counts, repository traffic (unique visitors and cloners and page views and clones over the last 14 days, peak visitor day, top referrer and page, visitor trend, cloners per visitor; needs write access, see [Access token](#-access-token)) | -Every entity has its own icon. The CI state, the last workflow result and the "workflow running" binary sensor change their icon with their state, and custom query sensors use a code icon. You can still override any icon per entity in Home Assistant. +Every entity has its own icon. The CI state, the repository visibility, the last workflow result and the "workflow running" binary sensor change their icon with their state, and custom query sensors use a code icon. You can still override any icon per entity in Home Assistant. Everything marked optional is created disabled. GitHub Pulse only fetches data that an enabled entity needs, so unused sensors cost no API calls.