Browse Source

add the pr comment ourselves and request reviews

list_maintainers
Zach White 2 years ago
parent
commit
610111583b
3 changed files with 37 additions and 15 deletions
  1. +2
    -9
      .github/workflows/maintainers.yaml
  2. +33
    -5
      lib/python/qmk/cli/ping/maintainers.py
  3. +2
    -1
      requirements-dev.txt

+ 2
- 9
.github/workflows/maintainers.yaml View File

@ -23,13 +23,6 @@ jobs:
- name: Install dependencies
run: pip3 install -r requirements-dev.txt
- name: Get our ping message
- name: Ping maintainers and request reviews
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
run: qmk ping-maintainers --pr ${{ github.event.number }} ${{ steps.file_changes.outputs.files }}

+ 33
- 5
lib/python/qmk/cli/ping/maintainers.py View File

@ -7,17 +7,45 @@ from milc import cli
from qmk.maintainers import maintainers
@cli.argument('--pr', type=int, arg_only=True, help="PR to send ping to (optional)")
@cli.argument('--owner', default='qmk', arg_only=True, help="Owner for the repo (Default: qmk)")
@cli.argument('--repo', default='qmk_firmware', arg_only=True, help="Repo to send pings to (Default: qmk_firmware)")
@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.")
@cli.subcommand("Ping the maintainers and request reviews for one or more files.")
def ping_maintainers(cli):
"""List the maintainers for one or more files.
"""Ping the maintainers for one or more files.
"""
github_maintainers = set()
github_teams = set()
for file in cli.args.files:
for maintainer in maintainers(file):
if not maintainer.startswith('@qmk/'):
if '/' in maintainer:
github_teams.add(maintainer)
else:
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))}')
if cli.args.pr:
from ghapi.all import GhApi
ghapi = GhApi(owner=cli.args.owner, repo=cli.args.repo)
pr = ghapi.pulls(cli.args.pr)
if not pr.draft:
for team in pr.requested_teams:
team_name = f'@{cli.args.owner}/{team.slug}'
if team_name in github_teams:
cli.log.info('Found %s in reviews already, skipping', team_name)
github_teams.remove(team_name)
for team in github_teams:
cli.log.info('Requesting review from team %s', team.split('/', 1)[1])
ghapi.pulls.request_reviewers(pull_number=cli.args.pr, team_reviewers=team.split('/', 1)[1])
if github_maintainers:
ghapi.issues.create_comment(cli.args.pr, f'If you were pinged by this comment you have one or more files being changed by this PR: {" ".join(sorted(github_maintainers))}')
else:
print(f'Team Reviews: {" ".join(sorted(github_teams))}')
print(f'Individual Reviews: {" ".join(sorted(github_maintainers))}')

+ 2
- 1
requirements-dev.txt View File

@ -3,7 +3,8 @@
# Python development requirements
codeowners
nose2
flake8
ghapi
nose2
pep8-naming
yapf

Loading…
Cancel
Save