diff --git a/homeassistant/components/diagnostics/__init__.py b/homeassistant/components/diagnostics/__init__.py index 481c02bad68..1c65b49fe0f 100644 --- a/homeassistant/components/diagnostics/__init__.py +++ b/homeassistant/components/diagnostics/__init__.py @@ -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, } diff --git a/tests/components/diagnostics/test_init.py b/tests/components/diagnostics/test_init.py index 5704131aa23..85f0b8fe788 100644 --- a/tests/components/diagnostics/test_init.py +++ b/tests/components/diagnostics/test_init.py @@ -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,