Remove @ from codeowners when downloading diagnostics (#117825)

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
pull/117841/head
J. Nick Koston 2024-05-20 21:32:07 -10:00 committed by GitHub
parent d0b1ac6918
commit 508cc2e5a1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 6 deletions

View File

@ -23,7 +23,11 @@ from homeassistant.helpers.json import (
)
from homeassistant.helpers.system_info import async_get_system_info
from homeassistant.helpers.typing import ConfigType
from homeassistant.loader import async_get_custom_components, async_get_integration
from homeassistant.loader import (
Manifest,
async_get_custom_components,
async_get_integration,
)
from homeassistant.setup import async_get_domain_setup_times
from homeassistant.util.json import format_unserializable_data
@ -157,6 +161,23 @@ def handle_get(
)
@callback
def async_format_manifest(manifest: Manifest) -> Manifest:
"""Format manifest for diagnostics.
Remove the @ from codeowners so that
when users download the diagnostics and paste
the codeowners into the repository, it will
not notify the users in the codeowners file.
"""
manifest_copy = manifest.copy()
if "codeowners" in manifest_copy:
manifest_copy["codeowners"] = [
codeowner.lstrip("@") for codeowner in manifest_copy["codeowners"]
]
return manifest_copy
async def _async_get_json_file_response(
hass: HomeAssistant,
data: Mapping[str, Any],
@ -182,7 +203,7 @@ async def _async_get_json_file_response(
payload = {
"home_assistant": hass_sys_info,
"custom_components": custom_components,
"integration_manifest": integration.manifest,
"integration_manifest": async_format_manifest(integration.manifest),
"setup_times": async_get_domain_setup_times(hass, domain),
"data": data,
}

View File

@ -1,7 +1,7 @@
"""Test the Diagnostics integration."""
from http import HTTPStatus
from unittest.mock import AsyncMock, Mock
from unittest.mock import AsyncMock, Mock, patch
import pytest
@ -9,6 +9,7 @@ from homeassistant.components.websocket_api.const import TYPE_RESULT
from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import async_get
from homeassistant.helpers.system_info import async_get_system_info
from homeassistant.loader import async_get_integration
from homeassistant.setup import async_setup_component
from . import _get_diagnostics_for_config_entry, _get_diagnostics_for_device
@ -90,8 +91,14 @@ async def test_download_diagnostics(
hass_sys_info = await async_get_system_info(hass)
hass_sys_info["run_as_root"] = hass_sys_info["user"] == "root"
del hass_sys_info["user"]
assert await _get_diagnostics_for_config_entry(hass, hass_client, config_entry) == {
integration = await async_get_integration(hass, "fake_integration")
original_manifest = integration.manifest.copy()
original_manifest["codeowners"] = ["@test"]
with patch.object(integration, "manifest", original_manifest):
response = await _get_diagnostics_for_config_entry(
hass, hass_client, config_entry
)
assert response == {
"home_assistant": hass_sys_info,
"setup_times": {},
"custom_components": {
@ -162,7 +169,7 @@ async def test_download_diagnostics(
},
},
"integration_manifest": {
"codeowners": [],
"codeowners": ["test"],
"dependencies": [],
"domain": "fake_integration",
"is_built_in": True,