2019-04-13 20:17:01 +00:00
|
|
|
"""Generate CODEOWNERS."""
|
2024-03-08 15:36:11 +00:00
|
|
|
|
2021-03-18 21:58:19 +00:00
|
|
|
from __future__ import annotations
|
2019-04-13 20:17:01 +00:00
|
|
|
|
2019-12-09 15:24:03 +00:00
|
|
|
from .model import Config, Integration
|
2019-04-13 20:17:01 +00:00
|
|
|
|
|
|
|
BASE = """
|
2019-10-02 16:34:27 +00:00
|
|
|
# This file is generated by script/hassfest/codeowners.py
|
2019-04-13 20:17:01 +00:00
|
|
|
# People marked here will be automatically requested for a review
|
|
|
|
# when the code that they own is touched.
|
|
|
|
# https://github.com/blog/2392-introducing-code-owners
|
2022-03-29 11:17:49 +00:00
|
|
|
# https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners
|
2019-04-13 20:17:01 +00:00
|
|
|
|
|
|
|
# Home Assistant Core
|
2024-03-28 09:54:10 +00:00
|
|
|
.core_files.yaml @home-assistant/core
|
|
|
|
.git-blame-ignore-revs @home-assistant/core
|
|
|
|
.gitattributes @home-assistant/core
|
|
|
|
.gitignore @home-assistant/core
|
|
|
|
.hadolint.yaml @home-assistant/core
|
|
|
|
.pre-commit-config.yaml @home-assistant/core
|
|
|
|
.prettierignore @home-assistant/core
|
|
|
|
.yamllint @home-assistant/core
|
2022-05-26 00:54:49 +00:00
|
|
|
pyproject.toml @home-assistant/core
|
2024-03-28 09:54:10 +00:00
|
|
|
requirements_test.txt @home-assistant/core
|
|
|
|
/.devcontainer/ @home-assistant/core
|
|
|
|
/.github/ @home-assistant/core
|
|
|
|
/.vscode/ @home-assistant/core
|
2022-03-29 11:17:49 +00:00
|
|
|
/homeassistant/*.py @home-assistant/core
|
2024-03-28 09:54:10 +00:00
|
|
|
/homeassistant/auth/ @home-assistant/core
|
|
|
|
/homeassistant/backports/ @home-assistant/core
|
2022-03-29 11:17:49 +00:00
|
|
|
/homeassistant/helpers/ @home-assistant/core
|
2024-03-28 09:54:10 +00:00
|
|
|
/homeassistant/scripts/ @home-assistant/core
|
2022-03-29 11:17:49 +00:00
|
|
|
/homeassistant/util/ @home-assistant/core
|
2024-03-28 09:54:10 +00:00
|
|
|
/pylint/ @home-assistant/core
|
|
|
|
/script/ @home-assistant/core
|
2019-04-13 20:17:01 +00:00
|
|
|
|
2020-11-02 10:54:16 +00:00
|
|
|
# Home Assistant Supervisor
|
2024-03-28 09:54:10 +00:00
|
|
|
.dockerignore @home-assistant/supervisor
|
2020-11-02 10:54:16 +00:00
|
|
|
build.json @home-assistant/supervisor
|
2022-03-29 11:17:49 +00:00
|
|
|
/machine/ @home-assistant/supervisor
|
|
|
|
/rootfs/ @home-assistant/supervisor
|
|
|
|
/Dockerfile @home-assistant/supervisor
|
2020-11-02 10:54:16 +00:00
|
|
|
|
2019-04-13 20:17:01 +00:00
|
|
|
# Other code
|
2022-03-29 11:17:49 +00:00
|
|
|
/homeassistant/scripts/check_config.py @kellerza
|
2019-04-13 20:17:01 +00:00
|
|
|
|
|
|
|
# Integrations
|
|
|
|
""".strip()
|
|
|
|
|
|
|
|
INDIVIDUAL_FILES = """
|
|
|
|
# Individual files
|
2022-03-29 11:17:49 +00:00
|
|
|
/homeassistant/components/demo/weather.py @fabaff
|
|
|
|
"""
|
|
|
|
|
|
|
|
REMOVE_CODEOWNERS = """
|
|
|
|
# Remove codeowners from files
|
|
|
|
/homeassistant/components/*/translations/
|
2019-04-13 20:17:01 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
2022-11-23 18:05:31 +00:00
|
|
|
def generate_and_validate(integrations: dict[str, Integration], config: Config) -> str:
|
2019-04-13 20:17:01 +00:00
|
|
|
"""Generate CODEOWNERS."""
|
|
|
|
parts = [BASE]
|
|
|
|
|
|
|
|
for domain in sorted(integrations):
|
|
|
|
integration = integrations[domain]
|
|
|
|
|
2022-11-29 20:57:58 +00:00
|
|
|
if integration.integration_type == "virtual":
|
2019-04-13 20:17:01 +00:00
|
|
|
continue
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
codeowners = integration.manifest["codeowners"]
|
2019-04-13 20:17:01 +00:00
|
|
|
|
|
|
|
if not codeowners:
|
|
|
|
continue
|
|
|
|
|
|
|
|
for owner in codeowners:
|
2019-07-31 19:25:30 +00:00
|
|
|
if not owner.startswith("@"):
|
2019-04-13 20:17:01 +00:00
|
|
|
integration.add_error(
|
2019-07-31 19:25:30 +00:00
|
|
|
"codeowners", "Code owners need to be valid GitHub handles."
|
2019-04-13 20:17:01 +00:00
|
|
|
)
|
|
|
|
|
2022-03-29 11:17:49 +00:00
|
|
|
parts.append(f"/homeassistant/components/{domain}/ {' '.join(codeowners)}")
|
2019-04-13 20:17:01 +00:00
|
|
|
|
2022-03-20 21:04:55 +00:00
|
|
|
if (config.root / "tests/components" / domain / "__init__.py").exists():
|
2022-03-29 11:17:49 +00:00
|
|
|
parts.append(f"/tests/components/{domain}/ {' '.join(codeowners)}")
|
2021-12-17 15:21:32 +00:00
|
|
|
|
2020-04-04 21:09:34 +00:00
|
|
|
parts.append(f"\n{INDIVIDUAL_FILES.strip()}")
|
2022-03-29 11:17:49 +00:00
|
|
|
parts.append(f"\n{REMOVE_CODEOWNERS.strip()}")
|
2019-04-13 20:17:01 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
return "\n".join(parts)
|
2019-04-13 20:17:01 +00:00
|
|
|
|
|
|
|
|
2022-11-23 18:05:31 +00:00
|
|
|
def validate(integrations: dict[str, Integration], config: Config) -> None:
|
2019-04-13 20:17:01 +00:00
|
|
|
"""Validate CODEOWNERS."""
|
2019-07-31 19:25:30 +00:00
|
|
|
codeowners_path = config.root / "CODEOWNERS"
|
2021-12-17 15:21:32 +00:00
|
|
|
config.cache["codeowners"] = content = generate_and_validate(integrations, config)
|
2019-04-13 20:17:01 +00:00
|
|
|
|
2020-04-16 16:00:04 +00:00
|
|
|
if config.specific_integrations:
|
|
|
|
return
|
|
|
|
|
2024-09-06 09:33:01 +00:00
|
|
|
if codeowners_path.read_text() != content + "\n":
|
|
|
|
config.add_error(
|
|
|
|
"codeowners",
|
|
|
|
"File CODEOWNERS is not up to date. Run python3 -m script.hassfest",
|
|
|
|
fixable=True,
|
|
|
|
)
|
2019-04-13 20:17:01 +00:00
|
|
|
|
|
|
|
|
2022-11-23 18:05:31 +00:00
|
|
|
def generate(integrations: dict[str, Integration], config: Config) -> None:
|
2019-04-13 20:17:01 +00:00
|
|
|
"""Generate CODEOWNERS."""
|
2019-07-31 19:25:30 +00:00
|
|
|
codeowners_path = config.root / "CODEOWNERS"
|
2024-09-06 09:33:01 +00:00
|
|
|
codeowners_path.write_text(f"{config.cache['codeowners']}\n")
|