def setUp(self): super(TestPublish, self).setUp() self.user = User('*****@*****.**') self.login('*****@*****.**') self.issue = models.Issue(subject='test') self.issue.local_base = False self.issue.put() self.ps = models.PatchSet(parent=self.issue, issue=self.issue) self.ps.data = load_file('ps1.diff') self.ps.save() self.patches = engine.ParsePatchSet(self.ps) db.put(self.patches)
def test_both_patch(self): issue = models.Issue(subject="test with changes") issue.local_base = False issue.put() ps = models.PatchSet(parent=issue.key, issue_key=issue.key) ps.data = self.makePatch(5, 7) ps.put() patches = engine.ParsePatchSet(ps) ndb.put_multi(patches) added, removed = views._get_modified_counts(issue) self.assertEqual(5, added) self.assertEqual(7, removed)
def test_remove_patch(self): issue = models.Issue(subject="test with 1 line removed") issue.local_base = False issue.put() ps = models.PatchSet(parent=issue, issue=issue) ps.data = self.makePatch(0, 1) ps.save() patches = engine.ParsePatchSet(ps) db.put(patches) added, removed = views._get_modified_counts(issue) self.assertEqual(0, added) self.assertEqual(1, removed)
def process_codereview_from_fogbugz(request): """Create/update codereview issue given the fogbugz case. :param request: HTTP request. """ # get information from the fogbugz case case_number, case_title, original_branch, feature_branch, _, target_branch = get_fogbugz_case_info( request, request.REQUEST['case']) # get codereview issue issue = get_issue(request, case_number, case_title) source_export_path = target_export_path = None try: # get the diff (source_url, target_url, complete_diff, vcs, target_export_path, source_revision, source_export_path) = generate_diff(original_branch, feature_branch) # validate the diff for validator in settings.CODEREVIEW_VALIDATORS: validator(complete_diff) complete_diff = unicode(complete_diff, 'utf-8', 'replace') issue.latest_patch_rev = source_revision issue.base = source_url issue.put() log("Creating patch set instance") patchset = models.PatchSet( issue=issue, data=complete_diff, parent=issue, revision=source_revision) patchset.put() log("Created patch set instance!") log("Parsing patch set") patches = ParsePatchSet(patchset) log("Parsed patch set") if not patches: return HttpResponseServerError('Looks like there is no difference between provided branches.') db.put(patches) fill_original_files(patches, target_export_path, source_export_path) return HttpResponseRedirect('/%s/show' % issue.id) finally: for path in target_export_path, source_export_path: if path and not settings.DEBUG: shutil.rmtree(path, ignore_errors=True) issue.processing = False issue.save()
def trans(): change = models.Change.get_by_id(req.change_id) if not change: return None change.subject = subject change.description = u(req.commit.message) change.n_patchsets += 1 id = change.n_patchsets change.put() patchset = models.PatchSet(change=change, owner=user, parent=change, revision=rev, id=id) patchset.put() return patchset
def create_issue(self, date, reviewers=None, cc=None): """Creates an issue by self.author with self.reviewer1 as a reviewer.""" date = datetime.datetime.strptime('2011-03-' + date, '%Y-%m-%d %H:%M') issue = models.Issue( subject='test', owner=self.author.user, reviewers=[r.email for r in reviewers or [self.reviewer1]], cc=[db.Email('*****@*****.**')] + [c.email for c in cc or []], created=date, modified=date) issue.put() # Verify that our auto_now hack works. self.assertEqual(issue.key.get().created, date) self.assertEqual(issue.key.get().modified, date) ps = models.PatchSet( parent=issue.key, issue_key=issue.key, created=date, modified=date) ps.data = utils.load_file('ps1.diff') ps.put() patches = engine.ParsePatchSet(ps) ndb.put_multi(patches) return issue
def trans(): change = models.Change(subject=subject, description=u(req.commit.message), owner=user, dest_project=branch.project, dest_branch=branch, n_patchsets=1) if cc: change.cc = cc change.put() if reviewers: (added_review_status, deleted_review_status, new_review_status) = \ library.update_reviewers(change, [], reviewers) for rs in added_review_status: rs.put() patchset = models.PatchSet(change=change, owner=user, parent=change, revision=rev, id=1) patchset.put() return (change, patchset)
project=original_issue.project, base=original_issue.base, target_ref=original_issue.target_ref, repo_guid=original_issue.repo_guid, reviewers=reviewers, cc=original_issue.cc, private=original_issue.private, n_comments=0, commit=False, # Do not check the commit box yet. key=issue_key) pending_commits.append(issue) # Create the new revert patchset to use as the key in the new patches. ps_id, _ = models.PatchSet.allocate_ids(1, parent=issue.key) ps_key = ndb.Key(models.PatchSet, ps_id, parent=issue.key) patchset = models.PatchSet(issue_key=issue.key, url=None, key=ps_key) patchset_data = [] # Will be populated with the diff texts of all patches. pending_commits.append(patchset) # Loop through all the original patches and create inversions. for original_patch in original_patches: try: patch = original_patch.make_inverted(patchset) except exceptions.FetchError, e: return HttpTextResponse( 'Revert failed: ' + e.message + '\nThis sometimes happens when a ' 'file\'s contents are not uploaded because it is too large.' + ERROR_MSG_POSTPEND, status=500)
def patchset(issue, patchset_revision): """Test patchset.""" patchset = models.PatchSet(issue=issue, revision=patchset_revision) patchset.put() return patchset