Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ 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) |
| ➕ | 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.

Expand Down
8 changes: 8 additions & 0 deletions custom_components/github_pulse/icons.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
10 changes: 9 additions & 1 deletion custom_components/github_pulse/repository_fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down
13 changes: 12 additions & 1 deletion custom_components/github_pulse/sensor_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions custom_components/github_pulse/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@
"expected": "Erwartet"
}
},
"visibility": {
"name": "Sichtbarkeit",
"state": {
"public": "Öffentlich",
"private": "Privat",
"internal": "Intern"
}
},
"watchers": {
"name": "Beobachter"
},
Expand Down
8 changes: 8 additions & 0 deletions custom_components/github_pulse/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@
"expected": "Expected"
}
},
"visibility": {
"name": "Visibility",
"state": {
"public": "Public",
"private": "Private",
"internal": "Internal"
}
},
"watchers": {
"name": "Watchers"
},
Expand Down
1 change: 1 addition & 0 deletions tests/test_icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
Expand Down
29 changes: 29 additions & 0 deletions tests/test_repository_fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"stargazerCount": 42,
"forkCount": 7,
"isArchived": False,
"visibility": "PRIVATE",
"pushedAt": "2026-10-24T10:00:00Z",
"watchers": {"totalCount": 5},
"issues": {"totalCount": 3},
Expand Down Expand Up @@ -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
20 changes: 20 additions & 0 deletions tests/test_repository_sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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"
Loading