Quellcode durchsuchen

add mechanisms for finding and pinging maintainers

Zach White vor 5 Jahren
Ursprung
Commit
c4a891d425

+ 34 - 0
.github/workflows/maintainers.yaml

@@ -0,0 +1,34 @@
+name: PR Lint Format
+
+on:
+    pull_request:
+
+jobs:
+    lint:
+        runs-on: ubuntu-latest
+
+        container: qmkfm/qmk_cli
+
+        steps:
+            - uses: rlespinasse/github-slug-action@v3.x
+
+            - uses: actions/checkout@v2
+              with:
+                  fetch-depth: 0
+
+            - uses: trilom/file-changes-action@v1.2.4
+              id: file_changes
+              with:
+                  output: " "
+                  fileOutput: " "
+
+            - name: Get our ping message
+              shell: "bash {0}"
+              run: echo "ping_message=$(qmk ping-maintainers $(< ~/files.txt))" > $GITHUB_ENV
+
+            - uses: mshick/add-pr-comment@v1
+              with:
+                  message: ${{ env.ping_message }}
+                  repo-token: ${{ secrets.GITHUB_TOKEN }}
+                  repo-token-user-login: "github-actions[bot]" # The user.login for temporary GitHub tokens
+                  allow-repeats: false # This is the default

+ 2 - 0
lib/python/qmk/cli/__init__.py

@@ -60,10 +60,12 @@ subcommands = [
     'qmk.cli.lint',
     'qmk.cli.list.keyboards',
     'qmk.cli.list.keymaps',
+    'qmk.cli.list.maintainers',
     'qmk.cli.kle2json',
     'qmk.cli.multibuild',
     'qmk.cli.new.keyboard',
     'qmk.cli.new.keymap',
+    'qmk.cli.ping.maintainers',
     'qmk.cli.pyformat',
     'qmk.cli.pytest',
 ]

+ 16 - 0
lib/python/qmk/cli/list/maintainers.py

@@ -0,0 +1,16 @@
+"""List the keymaps for a specific keyboard
+"""
+from pathlib import Path
+
+from milc import cli
+
+from qmk.maintainers import maintainers
+
+
+@cli.argument("files", type=Path, arg_only=True, nargs='*', help="File to check")
+@cli.subcommand("List the maintainers for a file.")
+def list_maintainers(cli):
+    """List the maintainers for a file.
+    """
+    for file in cli.args.files:
+        cli.echo('%s: %s', file, ', '.join(maintainers(file)))

+ 23 - 0
lib/python/qmk/cli/ping/maintainers.py

@@ -0,0 +1,23 @@
+"""Generate a message to ping people responsible for one or more files.
+"""
+from pathlib import Path
+
+from milc import cli
+
+from qmk.maintainers import maintainers
+
+
+@cli.argument("files", type=Path, arg_only=True, nargs='*', help="File to ping maintainers for.")
+@cli.subcommand("Ping the maintainers for one or more files.")
+def ping_maintainers(cli):
+    """List the maintainers for one or more files.
+    """
+    github_maintainers = set()
+
+    for file in cli.args.files:
+        for maintainer in maintainers(file):
+            if maintainer != 'qmk/collaborators':
+                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))}')

+ 22 - 0
lib/python/qmk/maintainers.py

@@ -0,0 +1,22 @@
+from pathlib import Path
+
+from qmk.json_schema import json_load
+
+
+def maintainers(file):
+    """Yields maintainers for a file.
+    """
+    maintainers = 'qmk'
+    file_dir = file if file.is_dir() else file.parent
+
+    cur_path = Path('.')
+
+    for path_part in file_dir.parts:
+        cur_path = cur_path / path_part
+        info_file = cur_path / 'info.json'
+        if info_file.exists():
+            new_info_data = json_load(info_file)
+            maintainers = new_info_data.get('maintainer', maintainers)
+
+    for maintainer in maintainers.replace(',', ' ').split():
+        yield 'qmk/collaborators' if maintainer == 'qmk' else maintainer