Validate component usage (#23037)
* Update manifest validator * Update circle * Update text * Typo * fix link to codeowners * Merge CODEOWNERS into hassfest * Annotate errors with fixable * Convert error to warning * Lint * Make abs path * Python 3.5... * Typo * Fix tests
This commit is contained in:
parent
fc481133e7
commit
e8343452cd
19 changed files with 415 additions and 220 deletions
85
script/hassfest/codeowners.py
Executable file
85
script/hassfest/codeowners.py
Executable file
|
@ -0,0 +1,85 @@
|
|||
"""Generate CODEOWNERS."""
|
||||
from typing import Dict
|
||||
|
||||
from .model import Integration, Config
|
||||
|
||||
BASE = """
|
||||
# This file is generated by script/manifest/codeowners.py
|
||||
# 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
|
||||
|
||||
# Virtualization
|
||||
Dockerfile @home-assistant/docker
|
||||
virtualization/Docker/* @home-assistant/docker
|
||||
|
||||
# Other code
|
||||
homeassistant/scripts/check_config.py @kellerza
|
||||
|
||||
# Integrations
|
||||
""".strip()
|
||||
|
||||
INDIVIDUAL_FILES = """
|
||||
# Individual files
|
||||
homeassistant/components/group/cover @cdce8p
|
||||
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
|
||||
|
||||
codeowners = integration.manifest['codeowners']
|
||||
|
||||
if not codeowners:
|
||||
continue
|
||||
|
||||
for owner in codeowners:
|
||||
if not owner.startswith('@'):
|
||||
integration.add_error(
|
||||
'codeowners',
|
||||
'Code owners need to be valid GitHub handles.',
|
||||
)
|
||||
|
||||
parts.append("homeassistant/components/{}/* {}".format(
|
||||
domain, ' '.join(codeowners)))
|
||||
|
||||
parts.append('\n' + INDIVIDUAL_FILES.strip())
|
||||
|
||||
return '\n'.join(parts)
|
||||
|
||||
|
||||
def validate(integrations: Dict[str, Integration], config: Config):
|
||||
"""Validate CODEOWNERS."""
|
||||
codeowners_path = config.root / 'CODEOWNERS'
|
||||
config.cache['codeowners'] = content = generate_and_validate(integrations)
|
||||
|
||||
with open(str(codeowners_path), 'r') as fp:
|
||||
if fp.read().strip() != content:
|
||||
config.add_error(
|
||||
"codeowners",
|
||||
"File CODEOWNERS is not up to date. "
|
||||
"Run python3 -m script.hassfest",
|
||||
fixable=True
|
||||
)
|
||||
return
|
||||
|
||||
|
||||
def generate(integrations: Dict[str, Integration], config: Config):
|
||||
"""Generate CODEOWNERS."""
|
||||
codeowners_path = config.root / 'CODEOWNERS'
|
||||
with open(str(codeowners_path), 'w') as fp:
|
||||
fp.write(config.cache['codeowners'] + '\n')
|
Loading…
Add table
Add a link
Reference in a new issue