Search in sources :

Example 21 with ChangeControl

use of com.google.gerrit.server.project.ChangeControl in project gerrit by GerritCodeReview.

the class AbstractQueryChangesTest method newPatchSet.

protected Change newPatchSet(TestRepository<Repo> repo, Change c) throws Exception {
    // Add a new file so the patch set is not a trivial rebase, to avoid default
    // Code-Review label copying.
    int n = c.currentPatchSetId().get() + 1;
    RevCommit commit = repo.parseBody(repo.commit().message("message").add("file" + n, "contents " + n).create());
    ChangeControl ctl = changeControlFactory.controlFor(db, c, user);
    PatchSetInserter inserter = patchSetFactory.create(ctl, new PatchSet.Id(c.getId(), n), commit).setNotify(NotifyHandling.NONE).setFireRevisionCreated(false).setValidate(false);
    try (BatchUpdate bu = updateFactory.create(db, c.getProject(), user, TimeUtil.nowTs());
        ObjectInserter oi = repo.getRepository().newObjectInserter();
        ObjectReader reader = oi.newReader();
        RevWalk rw = new RevWalk(reader)) {
        bu.setRepository(repo.getRepository(), rw, oi);
        bu.addOp(c.getId(), inserter);
        bu.execute();
    }
    return inserter.getChange();
}
Also used : ObjectInserter(org.eclipse.jgit.lib.ObjectInserter) PatchSetInserter(com.google.gerrit.server.change.PatchSetInserter) ChangeControl(com.google.gerrit.server.project.ChangeControl) ObjectReader(org.eclipse.jgit.lib.ObjectReader) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) ObjectId(org.eclipse.jgit.lib.ObjectId) RevWalk(org.eclipse.jgit.revwalk.RevWalk) BatchUpdate(com.google.gerrit.server.update.BatchUpdate) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 22 with ChangeControl

use of com.google.gerrit.server.project.ChangeControl in project gerrit by GerritCodeReview.

the class ConsistencyCheckerIT method missingRepo.

@Test
public void missingRepo() throws Exception {
    // NoteDb can't have a change without a repo.
    assume().that(notesMigration.enabled()).isFalse();
    ChangeControl ctl = insertChange();
    Project.NameKey name = ctl.getProject().getNameKey();
    ((InMemoryRepositoryManager) repoManager).deleteRepository(name);
    assertProblems(ctl, null, problem("Destination repository not found: " + name));
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) InMemoryRepositoryManager(com.google.gerrit.testutil.InMemoryRepositoryManager) ChangeControl(com.google.gerrit.server.project.ChangeControl) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 23 with ChangeControl

use of com.google.gerrit.server.project.ChangeControl in project gerrit by GerritCodeReview.

the class ConsistencyCheckerIT method currentPatchSetMissing.

@Test
public void currentPatchSetMissing() throws Exception {
    // NoteDb can't create a change without a patch set.
    assume().that(notesMigration.enabled()).isFalse();
    ChangeControl ctl = insertChange();
    db.patchSets().deleteKeys(singleton(ctl.getChange().currentPatchSetId()));
    assertProblems(ctl, null, problem("Current patch set 1 not found"));
}
Also used : ChangeControl(com.google.gerrit.server.project.ChangeControl) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 24 with ChangeControl

use of com.google.gerrit.server.project.ChangeControl in project gerrit by GerritCodeReview.

the class ChangeIncludedIn method apply.

@Override
public IncludedInInfo apply(ChangeResource rsrc) throws RestApiException, OrmException, IOException {
    ChangeControl ctl = rsrc.getControl();
    PatchSet ps = psUtil.current(db.get(), rsrc.getNotes());
    Project.NameKey project = ctl.getProject().getNameKey();
    return includedIn.apply(project, ps.getRevision().get());
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) ChangeControl(com.google.gerrit.server.project.ChangeControl) PatchSet(com.google.gerrit.reviewdb.client.PatchSet)

Example 25 with ChangeControl

use of com.google.gerrit.server.project.ChangeControl in project gerrit by GerritCodeReview.

the class ChangeInserter method postUpdate.

@Override
public void postUpdate(Context ctx) throws OrmException {
    if (sendMail && (notify != NotifyHandling.NONE || !accountsToNotify.isEmpty())) {
        Runnable sender = new Runnable() {

            @Override
            public void run() {
                try {
                    CreateChangeSender cm = createChangeSenderFactory.create(change.getProject(), change.getId());
                    cm.setFrom(change.getOwner());
                    cm.setPatchSet(patchSet, patchSetInfo);
                    cm.setNotify(notify);
                    cm.setAccountsToNotify(accountsToNotify);
                    cm.addReviewers(reviewers);
                    cm.addExtraCC(extraCC);
                    cm.send();
                } catch (Exception e) {
                    log.error("Cannot send email for new change " + change.getId(), e);
                }
            }

            @Override
            public String toString() {
                return "send-email newchange";
            }
        };
        if (requestScopePropagator != null) {
            @SuppressWarnings("unused") Future<?> possiblyIgnoredError = sendEmailExecutor.submit(requestScopePropagator.wrap(sender));
        } else {
            sender.run();
        }
    }
    /* For labels that are not set in this operation, show the "current" value
     * of 0, and no oldValue as the value was not modified by this operation.
     * For labels that are set in this operation, the value was modified, so
     * show a transition from an oldValue of 0 to the new value.
     */
    if (fireRevisionCreated) {
        revisionCreated.fire(change, patchSet, ctx.getAccount(), ctx.getWhen(), notify);
        if (approvals != null && !approvals.isEmpty()) {
            ChangeControl changeControl = changeControlFactory.controlFor(ctx.getDb(), change, ctx.getUser());
            List<LabelType> labels = changeControl.getLabelTypes().getLabelTypes();
            Map<String, Short> allApprovals = new HashMap<>();
            Map<String, Short> oldApprovals = new HashMap<>();
            for (LabelType lt : labels) {
                allApprovals.put(lt.getName(), (short) 0);
                oldApprovals.put(lt.getName(), null);
            }
            for (Map.Entry<String, Short> entry : approvals.entrySet()) {
                if (entry.getValue() != 0) {
                    allApprovals.put(entry.getKey(), entry.getValue());
                    oldApprovals.put(entry.getKey(), (short) 0);
                }
            }
            commentAdded.fire(change, patchSet, ctx.getAccount(), null, allApprovals, oldApprovals, ctx.getWhen());
        }
    }
}
Also used : HashMap(java.util.HashMap) CreateChangeSender(com.google.gerrit.server.mail.send.CreateChangeSender) OrmException(com.google.gwtorm.server.OrmException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) CommitValidationException(com.google.gerrit.server.git.validators.CommitValidationException) NoSuchProjectException(com.google.gerrit.server.project.NoSuchProjectException) IOException(java.io.IOException) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) ChangeControl(com.google.gerrit.server.project.ChangeControl) LabelType(com.google.gerrit.common.data.LabelType) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ChangeControl (com.google.gerrit.server.project.ChangeControl)34 Change (com.google.gerrit.reviewdb.client.Change)11 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)9 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)7 AuthException (com.google.gerrit.extensions.restapi.AuthException)6 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)6 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)5 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)5 Project (com.google.gerrit.reviewdb.client.Project)5 ChangeData (com.google.gerrit.server.query.change.ChangeData)5 HashMap (java.util.HashMap)5 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)4 ObjectId (org.eclipse.jgit.lib.ObjectId)4 ObjectInserter (org.eclipse.jgit.lib.ObjectInserter)4 ObjectReader (org.eclipse.jgit.lib.ObjectReader)4 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)3 LabelType (com.google.gerrit.common.data.LabelType)3 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)3 UnprocessableEntityException (com.google.gerrit.extensions.restapi.UnprocessableEntityException)3 Branch (com.google.gerrit.reviewdb.client.Branch)3