Commit bf98088f authored by Dirk Pranke's avatar Dirk Pranke Committed by Commit Bot

Add a --batch mode to `git-cl owners`.

This allows a script to generate a sufficient list of owners (and 
reviewers) for a given CL. Unlike the owners presubmit check and 
the normal, interactive mode of `git-cl owners`, we do not print 
the comments associated with an owner for each file, since 
presumably a script doesn't care about them (and the comments
aren't in a particularly machine-parsable form, anyway).

This could be used by the WPT import scripts, and presumably
by roll scripts and other such things.

I didn't add a test for this because there appears to be no good
mechanism for testing top-level CMD functions in git_cl that 
didn't end up just repeating the code mock-for-mock :(.

R: phajdan.jr@chromium.org
Change-Id: I3a9e6d117d6f4bafe938b07b028f119835c3e575
Reviewed-on: https://chromium-review.googlesource.com/648653Reviewed-by: 's avatarPaweł Hajdan Jr. <phajdan.jr@chromium.org>
Commit-Queue: Dirk Pranke <dpranke@chromium.org>
parent 372e0fdb
......@@ -5752,11 +5752,15 @@ def CMDdiff(parser, args):
def CMDowners(parser, args):
"""Interactively finds potential owners for reviewing."""
"""Finds potential owners for reviewing."""
parser.add_option(
'--no-color',
action='store_true',
help='Use this option to disable color output')
parser.add_option(
'--batch',
action='store_true',
help='Do not run interactively, just suggest some')
auth.add_auth_options(parser)
options, args = parser.parse_args(args)
auth_config = auth.extract_auth_config_from_options(options)
......@@ -5774,9 +5778,15 @@ def CMDowners(parser, args):
base_branch = cl.GetCommonAncestorWithUpstream()
change = cl.GetChange(base_branch, None)
affected_files = [f.LocalPath() for f in change.AffectedFiles()]
if options.batch:
db = owners.Database(change.RepositoryRoot(), file, os.path)
print('\n'.join(db.reviewers_for(affected_files, author)))
return 0
return owners_finder.OwnersFinder(
[f.LocalPath() for f in
cl.GetChange(base_branch, None).AffectedFiles()],
affected_files,
change.RepositoryRoot(),
author, fopen=file, os_path=os.path,
disable_color=options.no_color,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment