mirror of
https://github.com/esphome/esphome.git
synced 2025-06-23 08:45:42 +01:00
Add CODEOWNERS mechanism (#1199)
This commit is contained in:
.github/workflows
CODEOWNERSesphome
components
adc
api
async_tcp
bang_bang
binary_sensor
captive_portal
climate
cover
debug
dht
exposure_notifications
fastled_base
globals
gpio
homeassistant
i2c
integration
interval
json
ledc
light
logger
network
ota
output
pid
pn532
power_supply
restart
script
sensor
shutdown
spi
substitutions
sun
switch
time
uart
ultrasonic
version
web_server_base
script
68
script/build_codeowners.py
Executable file
68
script/build_codeowners.py
Executable file
@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env python3
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
from esphome.helpers import write_file_if_changed
|
||||
from esphome.config import get_component
|
||||
from esphome.core import CORE
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--check', help="Check if the CODEOWNERS file is up to date.",
|
||||
action='store_true')
|
||||
args = parser.parse_args()
|
||||
|
||||
# The root directory of the repo
|
||||
root = Path(__file__).parent.parent
|
||||
components_dir = root / 'esphome' / 'components'
|
||||
|
||||
BASE = """
|
||||
# This file is generated by script/build_codeowners.py
|
||||
# People marked here will be automatically requested for a review
|
||||
# when the code that they own is touched.
|
||||
#
|
||||
# Every time an issue is created with a label corresponding to an integration,
|
||||
# the integration's code owner is automatically notified.
|
||||
|
||||
# Core Code
|
||||
setup.py @esphome/core
|
||||
esphome/*.py @esphome/core
|
||||
esphome/core/* @esphome/core
|
||||
|
||||
# Integrations
|
||||
""".strip()
|
||||
|
||||
parts = [BASE]
|
||||
|
||||
# Fake some diretory so that get_component works
|
||||
CORE.config_path = str(root)
|
||||
|
||||
for path in sorted(components_dir.iterdir()):
|
||||
if not path.is_dir():
|
||||
continue
|
||||
if not (path / '__init__.py').is_file():
|
||||
continue
|
||||
name = path.name
|
||||
comp = get_component(name)
|
||||
if comp.codeowners:
|
||||
for owner in comp.codeowners:
|
||||
if not owner.startswith('@'):
|
||||
print(f"Codeowner {owner} for integration {name} must start with an '@' symbol!")
|
||||
sys.exit(1)
|
||||
|
||||
parts.append(f"esphome/components/{name}/* {' '.join(comp.codeowners)}")
|
||||
|
||||
# End newline
|
||||
parts.append('')
|
||||
content = '\n'.join(parts)
|
||||
codeowners_file = root / 'CODEOWNERS'
|
||||
|
||||
if args.check:
|
||||
if codeowners_file.read_text() != content:
|
||||
print("CODEOWNERS file is not up to date.")
|
||||
print("Please run `script/build_codeowners.py`")
|
||||
sys.exit(1)
|
||||
print("CODEOWNERS file is up to date")
|
||||
else:
|
||||
write_file_if_changed(codeowners_file, content)
|
||||
print("Wrote CODEOWNERS")
|
Reference in New Issue
Block a user