mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
Add --review and --cc flags to repo upload, so you can
assign reviewers when you upload changes.
This commit is contained in:
parent
8c6eef4713
commit
2896a79120
@ -1 +1 @@
|
|||||||
__version__ = 'v1.0-99-g9cd3ea2f'
|
__version__ = 'v1.0-112-gbcd4db5a'
|
||||||
|
@ -35,23 +35,27 @@ _UPLOADBUNDLERESPONSE_CODETYPE = descriptor.EnumDescriptor(
|
|||||||
options=None,
|
options=None,
|
||||||
type=None),
|
type=None),
|
||||||
descriptor.EnumValueDescriptor(
|
descriptor.EnumValueDescriptor(
|
||||||
name='UNKNOWN_PROJECT', index=5, number=2,
|
name='UNKNOWN_EMAIL', index=5, number=11,
|
||||||
options=None,
|
options=None,
|
||||||
type=None),
|
type=None),
|
||||||
descriptor.EnumValueDescriptor(
|
descriptor.EnumValueDescriptor(
|
||||||
name='UNKNOWN_BRANCH', index=6, number=3,
|
name='UNKNOWN_PROJECT', index=6, number=2,
|
||||||
options=None,
|
options=None,
|
||||||
type=None),
|
type=None),
|
||||||
descriptor.EnumValueDescriptor(
|
descriptor.EnumValueDescriptor(
|
||||||
name='UNKNOWN_BUNDLE', index=7, number=5,
|
name='UNKNOWN_BRANCH', index=7, number=3,
|
||||||
options=None,
|
options=None,
|
||||||
type=None),
|
type=None),
|
||||||
descriptor.EnumValueDescriptor(
|
descriptor.EnumValueDescriptor(
|
||||||
name='NOT_BUNDLE_OWNER', index=8, number=6,
|
name='UNKNOWN_BUNDLE', index=8, number=5,
|
||||||
options=None,
|
options=None,
|
||||||
type=None),
|
type=None),
|
||||||
descriptor.EnumValueDescriptor(
|
descriptor.EnumValueDescriptor(
|
||||||
name='BUNDLE_CLOSED', index=9, number=8,
|
name='NOT_BUNDLE_OWNER', index=9, number=6,
|
||||||
|
options=None,
|
||||||
|
type=None),
|
||||||
|
descriptor.EnumValueDescriptor(
|
||||||
|
name='BUNDLE_CLOSED', index=10, number=8,
|
||||||
options=None,
|
options=None,
|
||||||
type=None),
|
type=None),
|
||||||
],
|
],
|
||||||
@ -136,6 +140,20 @@ _UPLOADBUNDLEREQUEST = descriptor.Descriptor(
|
|||||||
message_type=None, enum_type=None, containing_type=None,
|
message_type=None, enum_type=None, containing_type=None,
|
||||||
is_extension=False, extension_scope=None,
|
is_extension=False, extension_scope=None,
|
||||||
options=None),
|
options=None),
|
||||||
|
descriptor.FieldDescriptor(
|
||||||
|
name='reviewers', full_name='codereview.UploadBundleRequest.reviewers', index=6,
|
||||||
|
number=3, type=9, cpp_type=9, label=3,
|
||||||
|
default_value=[],
|
||||||
|
message_type=None, enum_type=None, containing_type=None,
|
||||||
|
is_extension=False, extension_scope=None,
|
||||||
|
options=None),
|
||||||
|
descriptor.FieldDescriptor(
|
||||||
|
name='cc', full_name='codereview.UploadBundleRequest.cc', index=7,
|
||||||
|
number=4, type=9, cpp_type=9, label=3,
|
||||||
|
default_value=[],
|
||||||
|
message_type=None, enum_type=None, containing_type=None,
|
||||||
|
is_extension=False, extension_scope=None,
|
||||||
|
options=None),
|
||||||
],
|
],
|
||||||
extensions=[
|
extensions=[
|
||||||
],
|
],
|
||||||
@ -165,6 +183,20 @@ _UPLOADBUNDLERESPONSE = descriptor.Descriptor(
|
|||||||
message_type=None, enum_type=None, containing_type=None,
|
message_type=None, enum_type=None, containing_type=None,
|
||||||
is_extension=False, extension_scope=None,
|
is_extension=False, extension_scope=None,
|
||||||
options=None),
|
options=None),
|
||||||
|
descriptor.FieldDescriptor(
|
||||||
|
name='invalid_reviewers', full_name='codereview.UploadBundleResponse.invalid_reviewers', index=2,
|
||||||
|
number=12, type=9, cpp_type=9, label=3,
|
||||||
|
default_value=[],
|
||||||
|
message_type=None, enum_type=None, containing_type=None,
|
||||||
|
is_extension=False, extension_scope=None,
|
||||||
|
options=None),
|
||||||
|
descriptor.FieldDescriptor(
|
||||||
|
name='invalid_cc', full_name='codereview.UploadBundleResponse.invalid_cc', index=3,
|
||||||
|
number=13, type=9, cpp_type=9, label=3,
|
||||||
|
default_value=[],
|
||||||
|
message_type=None, enum_type=None, containing_type=None,
|
||||||
|
is_extension=False, extension_scope=None,
|
||||||
|
options=None),
|
||||||
],
|
],
|
||||||
extensions=[
|
extensions=[
|
||||||
],
|
],
|
||||||
|
@ -75,6 +75,7 @@ def UploadBundle(project,
|
|||||||
dest_branch,
|
dest_branch,
|
||||||
src_branch,
|
src_branch,
|
||||||
bases,
|
bases,
|
||||||
|
people,
|
||||||
replace_changes = None,
|
replace_changes = None,
|
||||||
save_cookies=True):
|
save_cookies=True):
|
||||||
|
|
||||||
@ -112,6 +113,10 @@ def UploadBundle(project,
|
|||||||
req = UploadBundleRequest()
|
req = UploadBundleRequest()
|
||||||
req.dest_project = str(dest_project)
|
req.dest_project = str(dest_project)
|
||||||
req.dest_branch = str(dest_branch)
|
req.dest_branch = str(dest_branch)
|
||||||
|
for e in people[0]:
|
||||||
|
req.reviewers.append(e)
|
||||||
|
for e in people[1]:
|
||||||
|
req.cc.append(e)
|
||||||
for c in revlist:
|
for c in revlist:
|
||||||
req.contained_object.append(c)
|
req.contained_object.append(c)
|
||||||
if replace_changes:
|
if replace_changes:
|
||||||
@ -158,6 +163,10 @@ def UploadBundle(project,
|
|||||||
reason = 'invalid change id'
|
reason = 'invalid change id'
|
||||||
elif rsp.status_code == UploadBundleResponse.CHANGE_CLOSED:
|
elif rsp.status_code == UploadBundleResponse.CHANGE_CLOSED:
|
||||||
reason = 'one or more changes are closed'
|
reason = 'one or more changes are closed'
|
||||||
|
elif rsp.status_code == UploadBundleResponse.UNKNOWN_EMAIL:
|
||||||
|
emails = [x for x in rsp.invalid_reviewers] + [
|
||||||
|
x for x in rsp.invalid_cc]
|
||||||
|
reason = 'invalid email addresses: %s' % ", ".join(emails)
|
||||||
else:
|
else:
|
||||||
reason = 'unknown error ' + str(rsp.status_code)
|
reason = 'unknown error ' + str(rsp.status_code)
|
||||||
raise UploadError(reason)
|
raise UploadError(reason)
|
||||||
|
@ -142,9 +142,10 @@ class ReviewableBranch(object):
|
|||||||
R_HEADS + self.name,
|
R_HEADS + self.name,
|
||||||
'--')
|
'--')
|
||||||
|
|
||||||
def UploadForReview(self):
|
def UploadForReview(self, people):
|
||||||
self.project.UploadForReview(self.name,
|
self.project.UploadForReview(self.name,
|
||||||
self.replace_changes)
|
self.replace_changes,
|
||||||
|
people)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def tip_url(self):
|
def tip_url(self):
|
||||||
@ -456,7 +457,7 @@ class Project(object):
|
|||||||
return rb
|
return rb
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def UploadForReview(self, branch=None, replace_changes=None):
|
def UploadForReview(self, branch=None, replace_changes=None, people=([],[])):
|
||||||
"""Uploads the named branch for code review.
|
"""Uploads the named branch for code review.
|
||||||
"""
|
"""
|
||||||
if branch is None:
|
if branch is None:
|
||||||
@ -495,6 +496,7 @@ class Project(object):
|
|||||||
dest_branch = dest_branch,
|
dest_branch = dest_branch,
|
||||||
src_branch = R_HEADS + branch.name,
|
src_branch = R_HEADS + branch.name,
|
||||||
bases = base_list,
|
bases = base_list,
|
||||||
|
people = people,
|
||||||
replace_changes = replace_changes)
|
replace_changes = replace_changes)
|
||||||
except proto_client.ClientLoginError:
|
except proto_client.ClientLoginError:
|
||||||
raise UploadError('Login failure')
|
raise UploadError('Login failure')
|
||||||
|
@ -25,11 +25,17 @@ def _die(fmt, *args):
|
|||||||
print >>sys.stderr, 'error: %s' % msg
|
print >>sys.stderr, 'error: %s' % msg
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
def _SplitEmails(values):
|
||||||
|
result = []
|
||||||
|
for str in values:
|
||||||
|
result.extend([s.strip() for s in str.split(',')])
|
||||||
|
return result
|
||||||
|
|
||||||
class Upload(InteractiveCommand):
|
class Upload(InteractiveCommand):
|
||||||
common = True
|
common = True
|
||||||
helpSummary = "Upload changes for code review"
|
helpSummary = "Upload changes for code review"
|
||||||
helpUsage="""
|
helpUsage="""
|
||||||
%prog {[<project>]... | --replace <project>}
|
%prog [--re --cc] {[<project>]... | --replace <project>}
|
||||||
"""
|
"""
|
||||||
helpDescription = """
|
helpDescription = """
|
||||||
The '%prog' command is used to send changes to the Gerrit code
|
The '%prog' command is used to send changes to the Gerrit code
|
||||||
@ -44,14 +50,25 @@ at the command line. Projects can be specified either by name, or
|
|||||||
by a relative or absolute path to the project's local directory. If
|
by a relative or absolute path to the project's local directory. If
|
||||||
no projects are specified, '%prog' will search for uploadable
|
no projects are specified, '%prog' will search for uploadable
|
||||||
changes in all projects listed in the manifest.
|
changes in all projects listed in the manifest.
|
||||||
|
|
||||||
|
If the --reviewers or --cc options are passed, those emails are
|
||||||
|
added to the respective list of users, and emails are sent to any
|
||||||
|
new users. Users passed to --reviewers must be already registered
|
||||||
|
with the code review system, or the upload will fail.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def _Options(self, p):
|
def _Options(self, p):
|
||||||
p.add_option('--replace',
|
p.add_option('--replace',
|
||||||
dest='replace', action='store_true',
|
dest='replace', action='store_true',
|
||||||
help='Upload replacement patchesets from this branch')
|
help='Upload replacement patchesets from this branch')
|
||||||
|
p.add_option('--re', '--reviewers',
|
||||||
|
type='string', action='append', dest='reviewers',
|
||||||
|
help='Request reviews from these people.')
|
||||||
|
p.add_option('--cc',
|
||||||
|
type='string', action='append', dest='cc',
|
||||||
|
help='Also send email to these email addresses.')
|
||||||
|
|
||||||
def _SingleBranch(self, branch):
|
def _SingleBranch(self, branch, people):
|
||||||
project = branch.project
|
project = branch.project
|
||||||
name = branch.name
|
name = branch.name
|
||||||
date = branch.date
|
date = branch.date
|
||||||
@ -69,11 +86,11 @@ changes in all projects listed in the manifest.
|
|||||||
sys.stdout.write('(y/n)? ')
|
sys.stdout.write('(y/n)? ')
|
||||||
answer = sys.stdin.readline().strip()
|
answer = sys.stdin.readline().strip()
|
||||||
if answer in ('y', 'Y', 'yes', '1', 'true', 't'):
|
if answer in ('y', 'Y', 'yes', '1', 'true', 't'):
|
||||||
self._UploadAndReport([branch])
|
self._UploadAndReport([branch], people)
|
||||||
else:
|
else:
|
||||||
_die("upload aborted by user")
|
_die("upload aborted by user")
|
||||||
|
|
||||||
def _MultipleBranches(self, pending):
|
def _MultipleBranches(self, pending, people):
|
||||||
projects = {}
|
projects = {}
|
||||||
branches = {}
|
branches = {}
|
||||||
|
|
||||||
@ -132,7 +149,7 @@ changes in all projects listed in the manifest.
|
|||||||
todo.append(branch)
|
todo.append(branch)
|
||||||
if not todo:
|
if not todo:
|
||||||
_die("nothing uncommented for upload")
|
_die("nothing uncommented for upload")
|
||||||
self._UploadAndReport(todo)
|
self._UploadAndReport(todo, people)
|
||||||
|
|
||||||
def _ReplaceBranch(self, project):
|
def _ReplaceBranch(self, project):
|
||||||
branch = project.CurrentBranch
|
branch = project.CurrentBranch
|
||||||
@ -176,13 +193,13 @@ changes in all projects listed in the manifest.
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
branch.replace_changes = to_replace
|
branch.replace_changes = to_replace
|
||||||
self._UploadAndReport([branch])
|
self._UploadAndReport([branch], people)
|
||||||
|
|
||||||
def _UploadAndReport(self, todo):
|
def _UploadAndReport(self, todo, people):
|
||||||
have_errors = False
|
have_errors = False
|
||||||
for branch in todo:
|
for branch in todo:
|
||||||
try:
|
try:
|
||||||
branch.UploadForReview()
|
branch.UploadForReview(people)
|
||||||
branch.uploaded = True
|
branch.uploaded = True
|
||||||
except UploadError, e:
|
except UploadError, e:
|
||||||
branch.error = e
|
branch.error = e
|
||||||
@ -216,6 +233,14 @@ changes in all projects listed in the manifest.
|
|||||||
def Execute(self, opt, args):
|
def Execute(self, opt, args):
|
||||||
project_list = self.GetProjects(args)
|
project_list = self.GetProjects(args)
|
||||||
pending = []
|
pending = []
|
||||||
|
reviewers = []
|
||||||
|
cc = []
|
||||||
|
|
||||||
|
if opt.reviewers:
|
||||||
|
reviewers = _SplitEmails(opt.reviewers)
|
||||||
|
if opt.cc:
|
||||||
|
cc = _SplitEmails(opt.cc)
|
||||||
|
people = (reviewers,cc)
|
||||||
|
|
||||||
if opt.replace:
|
if opt.replace:
|
||||||
if len(project_list) != 1:
|
if len(project_list) != 1:
|
||||||
@ -233,6 +258,6 @@ changes in all projects listed in the manifest.
|
|||||||
if not pending:
|
if not pending:
|
||||||
print >>sys.stdout, "no branches ready for upload"
|
print >>sys.stdout, "no branches ready for upload"
|
||||||
elif len(pending) == 1 and len(pending[0][1]) == 1:
|
elif len(pending) == 1 and len(pending[0][1]) == 1:
|
||||||
self._SingleBranch(pending[0][1][0])
|
self._SingleBranch(pending[0][1][0], people)
|
||||||
else:
|
else:
|
||||||
self._MultipleBranches(pending)
|
self._MultipleBranches(pending, people)
|
||||||
|
Loading…
Reference in New Issue
Block a user