2019-04-13 13:17:01 -07:00
|
|
|
"""Generate CODEOWNERS."""
|
2021-03-18 22:58:19 +01:00
|
|
|
from __future__ import annotations
|
2019-04-13 13:17:01 -07:00
|
|
|
|
2019-12-09 16:24:03 +01:00
|
|
|
from .model import Config, Integration
|
2019-04-13 13:17:01 -07:00
|
|
|
|
|
|
|
BASE = """
|
2019-10-02 18:34:27 +02:00
|
|
|
# This file is generated by script/hassfest/codeowners.py
|
2019-04-13 13:17:01 -07: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
|
|
|
|
|
|
|
|
# Home Assistant Core
|
|
|
|
setup.py @home-assistant/core
|
|
|
|
homeassistant/*.py @home-assistant/core
|
|
|
|
homeassistant/helpers/* @home-assistant/core
|
|
|
|
homeassistant/util/* @home-assistant/core
|
|
|
|
|
2020-11-02 11:54:16 +01:00
|
|
|
# Home Assistant Supervisor
|
|
|
|
build.json @home-assistant/supervisor
|
|
|
|
machine/* @home-assistant/supervisor
|
|
|
|
rootfs/* @home-assistant/supervisor
|
|
|
|
Dockerfile @home-assistant/supervisor
|
|
|
|
|
2019-04-13 13:17:01 -07:00
|
|
|
# Other code
|
|
|
|
homeassistant/scripts/check_config.py @kellerza
|
|
|
|
|
|
|
|
# Integrations
|
|
|
|
""".strip()
|
|
|
|
|
|
|
|
INDIVIDUAL_FILES = """
|
|
|
|
# Individual files
|
|
|
|
homeassistant/components/demo/weather @fabaff
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2021-12-17 16:21:32 +01:00
|
|
|
def generate_and_validate(integrations: dict[str, Integration], config: Config):
|
2019-04-13 13:17:01 -07:00
|
|
|
"""Generate CODEOWNERS."""
|
|
|
|
parts = [BASE]
|
|
|
|
|
|
|
|
for domain in sorted(integrations):
|
|
|
|
integration = integrations[domain]
|
|
|
|
|
|
|
|
if not integration.manifest:
|
|
|
|
continue
|
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
codeowners = integration.manifest["codeowners"]
|
2019-04-13 13:17:01 -07:00
|
|
|
|
|
|
|
if not codeowners:
|
|
|
|
continue
|
|
|
|
|
|
|
|
for owner in codeowners:
|
2019-07-31 12:25:30 -07:00
|
|
|
if not owner.startswith("@"):
|
2019-04-13 13:17:01 -07:00
|
|
|
integration.add_error(
|
2019-07-31 12:25:30 -07:00
|
|
|
"codeowners", "Code owners need to be valid GitHub handles."
|
2019-04-13 13:17:01 -07:00
|
|
|
)
|
|
|
|
|
2020-04-05 17:48:55 +02:00
|
|
|
parts.append(f"homeassistant/components/{domain}/* {' '.join(codeowners)}")
|
2019-04-13 13:17:01 -07:00
|
|
|
|
2021-12-17 16:21:32 +01:00
|
|
|
if (config.root / "tests/components" / domain).exists():
|
|
|
|
parts.append(f"tests/components/{domain}/* {' '.join(codeowners)}")
|
|
|
|
|
2020-04-04 23:09:34 +02:00
|
|
|
parts.append(f"\n{INDIVIDUAL_FILES.strip()}")
|
2019-04-13 13:17:01 -07:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
return "\n".join(parts)
|
2019-04-13 13:17:01 -07:00
|
|
|
|
|
|
|
|
2021-03-18 22:58:19 +01:00
|
|
|
def validate(integrations: dict[str, Integration], config: Config):
|
2019-04-13 13:17:01 -07:00
|
|
|
"""Validate CODEOWNERS."""
|
2019-07-31 12:25:30 -07:00
|
|
|
codeowners_path = config.root / "CODEOWNERS"
|
2021-12-17 16:21:32 +01:00
|
|
|
config.cache["codeowners"] = content = generate_and_validate(integrations, config)
|
2019-04-13 13:17:01 -07:00
|
|
|
|
2020-04-16 09:00:04 -07:00
|
|
|
if config.specific_integrations:
|
|
|
|
return
|
|
|
|
|
2020-04-05 12:49:57 +02:00
|
|
|
with open(str(codeowners_path)) as fp:
|
2019-04-13 13:17:01 -07:00
|
|
|
if fp.read().strip() != content:
|
|
|
|
config.add_error(
|
|
|
|
"codeowners",
|
2020-01-02 21:17:10 +02:00
|
|
|
"File CODEOWNERS is not up to date. Run python3 -m script.hassfest",
|
2019-07-31 12:25:30 -07:00
|
|
|
fixable=True,
|
2019-04-13 13:17:01 -07:00
|
|
|
)
|
|
|
|
return
|
|
|
|
|
|
|
|
|
2021-03-18 22:58:19 +01:00
|
|
|
def generate(integrations: dict[str, Integration], config: Config):
|
2019-04-13 13:17:01 -07:00
|
|
|
"""Generate CODEOWNERS."""
|
2019-07-31 12:25:30 -07:00
|
|
|
codeowners_path = config.root / "CODEOWNERS"
|
|
|
|
with open(str(codeowners_path), "w") as fp:
|
2020-04-04 20:17:11 +02:00
|
|
|
fp.write(f"{config.cache['codeowners']}\n")
|