Remove @ from codeowners when downloading diagnostics (#117825)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
parent
d0b1ac6918
commit
508cc2e5a1
2 changed files with 34 additions and 6 deletions
|
@ -23,7 +23,11 @@ from homeassistant.helpers.json import (
|
||||||
)
|
)
|
||||||
from homeassistant.helpers.system_info import async_get_system_info
|
from homeassistant.helpers.system_info import async_get_system_info
|
||||||
from homeassistant.helpers.typing import ConfigType
|
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.setup import async_get_domain_setup_times
|
||||||
from homeassistant.util.json import format_unserializable_data
|
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(
|
async def _async_get_json_file_response(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
data: Mapping[str, Any],
|
data: Mapping[str, Any],
|
||||||
|
@ -182,7 +203,7 @@ async def _async_get_json_file_response(
|
||||||
payload = {
|
payload = {
|
||||||
"home_assistant": hass_sys_info,
|
"home_assistant": hass_sys_info,
|
||||||
"custom_components": custom_components,
|
"custom_components": custom_components,
|
||||||
"integration_manifest": integration.manifest,
|
"integration_manifest": async_format_manifest(integration.manifest),
|
||||||
"setup_times": async_get_domain_setup_times(hass, domain),
|
"setup_times": async_get_domain_setup_times(hass, domain),
|
||||||
"data": data,
|
"data": data,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""Test the Diagnostics integration."""
|
"""Test the Diagnostics integration."""
|
||||||
|
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
from unittest.mock import AsyncMock, Mock
|
from unittest.mock import AsyncMock, Mock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ from homeassistant.components.websocket_api.const import TYPE_RESULT
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.device_registry import async_get
|
from homeassistant.helpers.device_registry import async_get
|
||||||
from homeassistant.helpers.system_info import async_get_system_info
|
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 homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from . import _get_diagnostics_for_config_entry, _get_diagnostics_for_device
|
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 = await async_get_system_info(hass)
|
||||||
hass_sys_info["run_as_root"] = hass_sys_info["user"] == "root"
|
hass_sys_info["run_as_root"] = hass_sys_info["user"] == "root"
|
||||||
del hass_sys_info["user"]
|
del hass_sys_info["user"]
|
||||||
|
integration = await async_get_integration(hass, "fake_integration")
|
||||||
assert await _get_diagnostics_for_config_entry(hass, hass_client, config_entry) == {
|
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,
|
"home_assistant": hass_sys_info,
|
||||||
"setup_times": {},
|
"setup_times": {},
|
||||||
"custom_components": {
|
"custom_components": {
|
||||||
|
@ -162,7 +169,7 @@ async def test_download_diagnostics(
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"integration_manifest": {
|
"integration_manifest": {
|
||||||
"codeowners": [],
|
"codeowners": ["test"],
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
"domain": "fake_integration",
|
"domain": "fake_integration",
|
||||||
"is_built_in": True,
|
"is_built_in": True,
|
||||||
|
|
Loading…
Add table
Reference in a new issue