2019-04-13 20:17:01 +00:00
|
|
|
"""Generate CODEOWNERS."""
|
|
|
|
from typing import Dict
|
|
|
|
|
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
|
|
|
|
|
|
|
|
# Home Assistant Core
|
|
|
|
setup.py @home-assistant/core
|
|
|
|
homeassistant/*.py @home-assistant/core
|
|
|
|
homeassistant/helpers/* @home-assistant/core
|
|
|
|
homeassistant/util/* @home-assistant/core
|
|
|
|
|
|
|
|
# Other code
|
|
|
|
homeassistant/scripts/check_config.py @kellerza
|
|
|
|
|
|
|
|
# Integrations
|
|
|
|
""".strip()
|
|
|
|
|
|
|
|
INDIVIDUAL_FILES = """
|
|
|
|
# Individual files
|
|
|
|
homeassistant/components/demo/weather @fabaff
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
def generate_and_validate(integrations: Dict[str, Integration]):
|
|
|
|
"""Generate CODEOWNERS."""
|
|
|
|
parts = [BASE]
|
|
|
|
|
|
|
|
for domain in sorted(integrations):
|
|
|
|
integration = integrations[domain]
|
|
|
|
|
|
|
|
if not integration.manifest:
|
|
|
|
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
|
|
|
)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
parts.append(
|
|
|
|
"homeassistant/components/{}/* {}".format(domain, " ".join(codeowners))
|
|
|
|
)
|
2019-04-13 20:17:01 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
parts.append("\n" + INDIVIDUAL_FILES.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
|
|
|
|
|
|
|
|
|
|
|
def validate(integrations: Dict[str, Integration], config: Config):
|
|
|
|
"""Validate CODEOWNERS."""
|
2019-07-31 19:25:30 +00:00
|
|
|
codeowners_path = config.root / "CODEOWNERS"
|
|
|
|
config.cache["codeowners"] = content = generate_and_validate(integrations)
|
2019-04-13 20:17:01 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
with open(str(codeowners_path), "r") as fp:
|
2019-04-13 20:17:01 +00:00
|
|
|
if fp.read().strip() != content:
|
|
|
|
config.add_error(
|
|
|
|
"codeowners",
|
2019-07-31 19:25:30 +00:00
|
|
|
"File CODEOWNERS is not up to date. " "Run python3 -m script.hassfest",
|
|
|
|
fixable=True,
|
2019-04-13 20:17:01 +00:00
|
|
|
)
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
def generate(integrations: Dict[str, Integration], config: Config):
|
|
|
|
"""Generate CODEOWNERS."""
|
2019-07-31 19:25:30 +00:00
|
|
|
codeowners_path = config.root / "CODEOWNERS"
|
|
|
|
with open(str(codeowners_path), "w") as fp:
|
|
|
|
fp.write(config.cache["codeowners"] + "\n")
|