maintainers.py 889 B

123456789101112131415161718192021222324252627
  1. from pathlib import Path
  2. from qmk.json_schema import json_load
  3. def maintainers(file):
  4. """Yields maintainers for a file.
  5. """
  6. from codeowners import CodeOwners
  7. codeowners_file = Path('CODEOWNERS')
  8. codeowners = CodeOwners(codeowners_file.read_text())
  9. maintainers = [owner[1] for owner in codeowners.of(str(file))]
  10. file_dir = file if file.is_dir() else file.parent
  11. cur_path = Path('.')
  12. for path_part in file_dir.parts:
  13. cur_path = cur_path / path_part
  14. info_file = cur_path / 'info.json'
  15. if info_file.exists():
  16. new_info_data = json_load(info_file)
  17. maintainers = new_info_data.get('maintainer').replace(',', ' ').split()
  18. maintainers = ['@' + maintainer for maintainer in maintainers]
  19. for maintainer in maintainers:
  20. yield '@qmk/collaborators' if maintainer == 'qmk' else maintainer