def UploadBundle(self, rpc_controller, req, done): """ Receives an uploaded Git style bundle and queues it for processing. """ rsp = UploadBundleResponse() # can't get here if there isn't a current user current_user = users.get_current_user() if not Account.get_account_for_user(current_user).cla_verified: rsp.status_code = UploadBundleResponse.UNAUTHORIZED_USER done(rsp) return # Validate that we have an Account for everyone in reviewers invalid_reviewers = [] reviewers = Account.get_accounts_for_emails([x for x in req.reviewers]) for i in range(0, len(reviewers)): if not reviewers[i]: invalid_reviewers.append(req.reviewers[i]) # Validate all of the email addresses invalid_cc = [] for e in req.cc: if not forms.fields.email_re.search(e): invalid_cc.append(e) # Return failure if any of that was bad if invalid_reviewers or invalid_cc: rsp.status_code = UploadBundleResponse.UNKNOWN_EMAIL for e in invalid_reviewers: rsp.invalid_reviewers.append(e) for e in invalid_cc: rsp.invalid_cc.append(e) done(rsp) return reviewers = [x.user for x in reviewers] cc = [db.Email(x) for x in req.cc] if not req.dest_project: rsp.status_code = UploadBundleResponse.UNKNOWN_PROJECT done(rsp) return proj = req.dest_project if proj.endswith(".git"): proj = proj[0 : len(proj) - 4] proj = Project.get_project_for_name(proj) if not proj: rsp.status_code = UploadBundleResponse.UNKNOWN_PROJECT done(rsp) return if not req.dest_branch: rsp.status_code = UploadBundleResponse.UNKNOWN_BRANCH done(rsp) brch = Branch.get_branch_for_name(proj, req.dest_branch) if not brch: rsp.status_code = UploadBundleResponse.UNKNOWN_BRANCH done(rsp) return replaces = list() ids_to_check = list() for p in req.replace: id = int(p.change_id) ids_to_check.append(id) replaces.append('%d %s' % (id, p.object_id)) if ids_to_check: for id, c in zip(ids_to_check, Change.get_by_id(ids_to_check)): if not c: rsp.status_code = UploadBundleResponse.UNKNOWN_CHANGE done(rsp) return if c.closed: rsp.status_code = UploadBundleResponse.CHANGE_CLOSED done(rsp) return rb = git_models.ReceivedBundle( dest_project = proj, dest_branch = brch, owner = current_user, state = git_models.ReceivedBundle.STATE_UPLOADING, reviewers = reviewers, cc = cc, contained_objects = list(req.contained_object), replaces = replaces) rb.put() rsp.bundle_id = str(rb.key().id()) self._store_segment(req, rsp, rb, 1) done(rsp)