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

- **Reconfigure** can now replace the access token. The new token is checked against the enabled modules and must belong to the same GitHub account; leave the field empty to keep the current one.

## [1.4.0] - 2026-11-23

### Added
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ You need **one** token. It serves every module you enable. A classic token with

The setup checks the token against every module you select and tells you what is missing. The full endpoint list is in the [permission matrix](docs/permission-matrix.md).

To replace the token, open the integration, choose **Reconfigure** and enter the new token. It must belong to the same GitHub account. Leave the field empty to keep the current token.

> [!IMPORTANT]
> Fine-grained tokens belong to a single owner and cannot read Packages. Use a classic token if you need more.

Expand Down
19 changes: 14 additions & 5 deletions custom_components/github_pulse/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@
{probatio.Required(CONF_ACCESS_TOKEN): _TOKEN_SELECTOR}
)
STEP_RECONFIGURE_SCHEMA = probatio.Schema(
{probatio.Required(CONF_MODULES): _MODULES_SELECTOR}
{
probatio.Required(CONF_MODULES): _MODULES_SELECTOR,
probatio.Optional(CONF_ACCESS_TOKEN): _TOKEN_SELECTOR,
}
)


Expand Down Expand Up @@ -330,7 +333,7 @@ async def async_step_reauth_confirm(
async def async_step_reconfigure(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Change which modules are enabled, keeping the stored token."""
"""Change which modules are enabled and, optionally, replace the token."""
errors: dict[str, str] = {}
placeholders: dict[str, str] = {}
entry = self._get_reconfigure_entry()
Expand All @@ -340,24 +343,30 @@ async def async_step_reconfigure(
if not modules:
errors["base"] = "no_modules"
else:
new_token = user_input.get(CONF_ACCESS_TOKEN, "").strip()
token = new_token or entry.data[CONF_ACCESS_TOKEN]
verified = await _verify(
self.hass,
entry.data[CONF_ACCESS_TOKEN],
token,
modules,
expected_login=entry.data[CONF_OWNER],
)
errors = verified.errors
placeholders |= verified.placeholders
if verified.info:
updates: dict[str, Any] = {CONF_MODULES: modules}
if new_token:
updates[CONF_ACCESS_TOKEN] = new_token
updates[CONF_TOKEN_TYPE] = verified.info.token_type.value
return self.async_update_reload_and_abort(
entry, data_updates={CONF_MODULES: modules}
entry, data_updates=updates
)

return self.async_show_form(
step_id="reconfigure",
data_schema=self.add_suggested_values_to_schema(
STEP_RECONFIGURE_SCHEMA,
user_input or {CONF_MODULES: entry.data[CONF_MODULES]},
{CONF_MODULES: (user_input or entry.data)[CONF_MODULES]},
),
errors=errors,
description_placeholders=placeholders,
Expand Down
9 changes: 5 additions & 4 deletions custom_components/github_pulse/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
}
},
"reconfigure": {
"title": "Erfasste Daten ändern",
"description": "Das gespeicherte Token wird für jedes gewählte Modul geprüft.",
"title": "Erfassung oder Token ändern",
"description": "Das Token wird für jedes gewählte Modul geprüft. Lass das Token leer, um das aktuelle zu behalten; ein neues Token muss zum selben GitHub-Konto gehören.",
"data": {
"modules": "Was möchtest du erfassen?"
"modules": "Was möchtest du erfassen?",
"access_token": "Neues Zugriffstoken (optional)"
}
}
},
Expand All @@ -38,7 +39,7 @@
"abort": {
"already_configured": "Dieses GitHub-Konto ist bereits eingerichtet.",
"reauth_successful": "Das neue Token wurde gespeichert.",
"reconfigure_successful": "Die erfassten Module wurden aktualisiert."
"reconfigure_successful": "Die Einstellungen wurden aktualisiert."
}
},
"options": {
Expand Down
9 changes: 5 additions & 4 deletions custom_components/github_pulse/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
}
},
"reconfigure": {
"title": "Change what is tracked",
"description": "The stored token is checked against every module you select.",
"title": "Change tracking or token",
"description": "The stored token is checked against every module you select. Leave the token empty to keep the current one; a new token must belong to the same GitHub account.",
"data": {
"modules": "What do you want to track?"
"modules": "What do you want to track?",
"access_token": "New access token (optional)"
}
}
},
Expand All @@ -38,7 +39,7 @@
"abort": {
"already_configured": "This GitHub account is already configured.",
"reauth_successful": "The new token was saved.",
"reconfigure_successful": "The tracked modules were updated."
"reconfigure_successful": "The settings were updated."
}
},
"options": {
Expand Down
66 changes: 66 additions & 0 deletions tests/test_config_flow_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,72 @@ async def test_reconfigure_changes_the_modules(
assert entry.data[CONF_ACCESS_TOKEN] == "ghp_old"


async def test_reconfigure_replaces_the_token(
hass: HomeAssistant, patch_session: Callable[[FakeSession], None]
) -> None:
patch_session(FakeSession(USER_OK, GRAPHQL_OK))
entry = _entry(hass)

result = await entry.start_reconfigure_flow(hass)
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{CONF_MODULES: ["profile"], CONF_ACCESS_TOKEN: " ghp_new "},
)

assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "reconfigure_successful"
assert entry.data[CONF_ACCESS_TOKEN] == "ghp_new"
assert entry.data[CONF_TOKEN_TYPE] == "classic"
assert entry.data[CONF_OWNER] == "octocat"


async def test_reconfigure_keeps_the_token_when_the_field_is_blank(
hass: HomeAssistant, patch_session: Callable[[FakeSession], None]
) -> None:
patch_session(FakeSession(USER_OK, GRAPHQL_OK))
entry = _entry(hass)

result = await entry.start_reconfigure_flow(hass)
result = await hass.config_entries.flow.async_configure(
result["flow_id"], {CONF_MODULES: ["profile"], CONF_ACCESS_TOKEN: " "}
)

assert result["reason"] == "reconfigure_successful"
assert entry.data[CONF_ACCESS_TOKEN] == "ghp_old"


async def test_reconfigure_rejects_a_token_of_another_account(
hass: HomeAssistant, patch_session: Callable[[FakeSession], None]
) -> None:
patch_session(FakeSession(OTHER_USER))
entry = _entry(hass)

result = await entry.start_reconfigure_flow(hass)
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{CONF_MODULES: ["profile"], CONF_ACCESS_TOKEN: "ghp_new"},
)

assert result["errors"] == {"base": "wrong_account"}
assert entry.data[CONF_ACCESS_TOKEN] == "ghp_old"


async def test_reconfigure_rejects_an_invalid_new_token(
hass: HomeAssistant, patch_session: Callable[[FakeSession], None]
) -> None:
patch_session(FakeSession(BAD_CREDENTIALS))
entry = _entry(hass)

result = await entry.start_reconfigure_flow(hass)
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{CONF_MODULES: ["profile"], CONF_ACCESS_TOKEN: "ghp_bad"},
)

assert result["errors"] == {"base": "invalid_auth"}
assert entry.data[CONF_ACCESS_TOKEN] == "ghp_old"


async def test_reconfigure_rejects_a_module_the_token_cannot_serve(
hass: HomeAssistant, patch_session: Callable[[FakeSession], None]
) -> None:
Expand Down
Loading