add the pr comment ourselves and request reviews
This commit is contained in:
parent
1db04e4622
commit
610111583b
3 changed files with 37 additions and 15 deletions
|
@ -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))}')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue