From 65fd33ec0e55a0bf883cbb2c9df6a1d340ed5e5e Mon Sep 17 00:00:00 2001 From: Zach White Date: Sat, 18 Sep 2021 22:51:44 -0700 Subject: [PATCH] Add CODEOWNERS support --- CODEOWNERS | 2 ++ lib/python/qmk/cli/ping/maintainers.py | 2 +- lib/python/qmk/maintainers.py | 14 ++++++++++---- requirements-dev.txt | 1 + 4 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 CODEOWNERS diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 00000000000..63a17be22cf --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1,2 @@ +* @qmk/collaborators +/lib/python/* @skullydazed @erovia diff --git a/lib/python/qmk/cli/ping/maintainers.py b/lib/python/qmk/cli/ping/maintainers.py index 77a333b43d5..83bc6b224d7 100644 --- a/lib/python/qmk/cli/ping/maintainers.py +++ b/lib/python/qmk/cli/ping/maintainers.py @@ -17,7 +17,7 @@ def ping_maintainers(cli): for file in cli.args.files: for maintainer in maintainers(file): if maintainer != 'qmk/collaborators': - github_maintainers.add('@' + maintainer) + github_maintainers.add(maintainer) if github_maintainers: print(f'If you were pinged by this comment you have one or more files being changed by this PR: {" ".join(sorted(github_maintainers))}') diff --git a/lib/python/qmk/maintainers.py b/lib/python/qmk/maintainers.py index bfcb789602c..011660166aa 100644 --- a/lib/python/qmk/maintainers.py +++ b/lib/python/qmk/maintainers.py @@ -1,12 +1,17 @@ from pathlib import Path +from codeowners import CodeOwners + from qmk.json_schema import json_load +codeowners_file = Path('CODEOWNERS') +codeowners = CodeOwners(codeowners_file.read_text()) + def maintainers(file): """Yields maintainers for a file. """ - maintainers = 'qmk' + maintainers = [owner[1] for owner in codeowners.of(str(file))] file_dir = file if file.is_dir() else file.parent cur_path = Path('.') @@ -16,7 +21,8 @@ def maintainers(file): info_file = cur_path / 'info.json' if info_file.exists(): new_info_data = json_load(info_file) - maintainers = new_info_data.get('maintainer', maintainers) + maintainers = new_info_data.get('maintainer').replace(',', ' ').split() + maintainers = ['@' + maintainer for maintainer in maintainers] - for maintainer in maintainers.replace(',', ' ').split(): - yield 'qmk/collaborators' if maintainer == 'qmk' else maintainer \ No newline at end of file + for maintainer in maintainers: + yield '@qmk/collaborators' if maintainer == 'qmk' else maintainer \ No newline at end of file diff --git a/requirements-dev.txt b/requirements-dev.txt index 1db3b6d7331..be6082dfedf 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -2,6 +2,7 @@ -r requirements.txt # Python development requirements +codeowners nose2 flake8 pep8-naming