Commit 0518357b authored by Matthias Putz's avatar Matthias Putz

fixes #3 adds upload without review

parent 374ae250
...@@ -6,6 +6,7 @@ Bugs: ...@@ -6,6 +6,7 @@ Bugs:
Features: Features:
* upload via https * upload via https
* upload without reviewing
# Notes on compability # Notes on compability
......
...@@ -159,11 +159,12 @@ class ReviewableBranch(object): ...@@ -159,11 +159,12 @@ class ReviewableBranch(object):
R_HEADS + self.name, R_HEADS + self.name,
'--') '--')
def UploadForReview(self, people, auto_topic=False, draft=False): def Upload(self, people, auto_topic=False, draft=False, no_review=False):
self.project.UploadForReview(self.name, self.project.Upload(self.name,
people, people,
auto_topic=auto_topic, auto_topic=auto_topic,
draft=draft) draft=draft,
no_review=no_review)
def GetPublishedRefs(self): def GetPublishedRefs(self):
refs = {} refs = {}
...@@ -909,10 +910,11 @@ class Project(object): ...@@ -909,10 +910,11 @@ class Project(object):
return rb return rb
return None return None
def UploadForReview(self, branch=None, def Upload(self, branch=None,
people=([], []), people=([], []),
auto_topic=False, auto_topic=False,
draft=False): draft=False,
no_review=False):
"""Uploads the named branch for code review. """Uploads the named branch for code review.
""" """
if branch is None: if branch is None:
...@@ -952,12 +954,14 @@ class Project(object): ...@@ -952,12 +954,14 @@ class Project(object):
if dest_branch.startswith(R_HEADS): if dest_branch.startswith(R_HEADS):
dest_branch = dest_branch[len(R_HEADS):] dest_branch = dest_branch[len(R_HEADS):]
if not no_review:
upload_type = 'for' upload_type = 'for'
if draft: if draft:
upload_type = 'drafts' upload_type = 'drafts'
ref_spec = '%s:refs/%s/%s' % (R_HEADS + branch.name, upload_type, dest_branch)
else:
ref_spec = '%s:%s' % (R_HEADS + branch.name, dest_branch)
ref_spec = '%s:refs/%s/%s' % (R_HEADS + branch.name, upload_type,
dest_branch)
if auto_topic: if auto_topic:
ref_spec = ref_spec + '/' + branch.name ref_spec = ref_spec + '/' + branch.name
cmd.append(ref_spec) cmd.append(ref_spec)
......
...@@ -145,6 +145,9 @@ Gerrit Code Review: http://code.google.com/p/gerrit/ ...@@ -145,6 +145,9 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
p.add_option('-d', '--draft', p.add_option('-d', '--draft',
action='store_true', dest='draft', default=False, action='store_true', dest='draft', default=False,
help='If specified, upload as a draft.') help='If specified, upload as a draft.')
p.add_option('-n', '--no-review',
action='store_true', dest='no_review', default=False,
help='Uploads without reviewing.')
# Options relating to upload hook. Note that verify and no-verify are NOT # Options relating to upload hook. Note that verify and no-verify are NOT
# opposites of each other, which is why they store to different locations. # opposites of each other, which is why they store to different locations.
...@@ -169,7 +172,7 @@ Gerrit Code Review: http://code.google.com/p/gerrit/ ...@@ -169,7 +172,7 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
dest='allow_all_hooks', action='store_true', dest='allow_all_hooks', action='store_true',
help='Run the upload hook without prompting.') help='Run the upload hook without prompting.')
def _SingleBranch(self, opt, branch, people): def _SingleBranch(self, opt, branch, people, no_review):
project = branch.project project = branch.project
name = branch.name name = branch.name
remote = project.GetBranch(name).remote remote = project.GetBranch(name).remote
...@@ -203,11 +206,11 @@ Gerrit Code Review: http://code.google.com/p/gerrit/ ...@@ -203,11 +206,11 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
answer = _ConfirmManyUploads() answer = _ConfirmManyUploads()
if answer: if answer:
self._UploadAndReport(opt, [branch], people) self._UploadAndReport(opt, [branch], people, no_review)
else: else:
_die("upload aborted by user") _die("upload aborted by user")
def _MultipleBranches(self, opt, pending, people): def _MultipleBranches(self, opt, pending, people, no_review):
projects = {} projects = {}
branches = {} branches = {}
...@@ -284,7 +287,7 @@ Gerrit Code Review: http://code.google.com/p/gerrit/ ...@@ -284,7 +287,7 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
if not _ConfirmManyUploads(multiple_branches=True): if not _ConfirmManyUploads(multiple_branches=True):
_die("upload aborted by user") _die("upload aborted by user")
self._UploadAndReport(opt, todo, people) self._UploadAndReport(opt, todo, people, no_review)
def _AppendAutoCcList(self, branch, people): def _AppendAutoCcList(self, branch, people):
""" """
...@@ -311,7 +314,7 @@ Gerrit Code Review: http://code.google.com/p/gerrit/ ...@@ -311,7 +314,7 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
except (AttributeError, IndexError): except (AttributeError, IndexError):
return "" return ""
def _UploadAndReport(self, opt, todo, original_people): def _UploadAndReport(self, opt, todo, original_people, no_review):
have_errors = False have_errors = False
for branch in todo: for branch in todo:
try: try:
...@@ -340,7 +343,7 @@ Gerrit Code Review: http://code.google.com/p/gerrit/ ...@@ -340,7 +343,7 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
key = 'review.%s.uploadtopic' % branch.project.remote.review key = 'review.%s.uploadtopic' % branch.project.remote.review
opt.auto_topic = branch.project.config.GetBoolean(key) opt.auto_topic = branch.project.config.GetBoolean(key)
branch.UploadForReview(people, auto_topic=opt.auto_topic, draft=opt.draft) branch.Upload(people, auto_topic=opt.auto_topic, draft=opt.draft, no_review=no_review)
branch.uploaded = True branch.uploaded = True
except UploadError as e: except UploadError as e:
branch.error = e branch.error = e
...@@ -409,9 +412,13 @@ Gerrit Code Review: http://code.google.com/p/gerrit/ ...@@ -409,9 +412,13 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
cc = _SplitEmails(opt.cc) cc = _SplitEmails(opt.cc)
people = (reviewers, cc) people = (reviewers, cc)
no_review = opt.no_review
if no_review:
print("WARNING: uploading without reviewing")
if not pending: if not pending:
print("no branches ready for upload", file=sys.stderr) print("no branches ready for upload", file=sys.stderr)
elif len(pending) == 1 and len(pending[0][1]) == 1: elif len(pending) == 1 and len(pending[0][1]) == 1:
self._SingleBranch(opt, pending[0][1][0], people) self._SingleBranch(opt, pending[0][1][0], people, no_review)
else: else:
self._MultipleBranches(opt, pending, people) self._MultipleBranches(opt, pending, people, no_review)
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