maintainers.py 877 B

12345678910111213141516171819202122232425262728
  1. from pathlib import Path
  2. from codeowners import CodeOwners
  3. from qmk.json_schema import json_load
  4. codeowners_file = Path('CODEOWNERS')
  5. codeowners = CodeOwners(codeowners_file.read_text())
  6. def maintainers(file):
  7. """Yields maintainers for a file.
  8. """
  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