@@ -0,0 +1,3122 @@
+package com.criteo.gerrit.plugins.automerge;%0A%0Aimport com.google.gerrit.extensions.api.changes.ReviewInput;%0Aimport com.google.gerrit.extensions.restapi.AuthException;%0Aimport com.google.gerrit.extensions.restapi.BadRequestException;%0Aimport com.google.gerrit.extensions.restapi.UnprocessableEntityException;%0Aimport com.google.gerrit.reviewdb.client.Account;%0Aimport com.google.gerrit.reviewdb.client.Change;%0Aimport com.google.gerrit.reviewdb.server.ReviewDb;%0Aimport com.google.gerrit.server.IdentifiedUser;%0Aimport com.google.gerrit.server.account.AccountByEmailCache;%0Aimport com.google.gerrit.server.change.ChangesCollection;%0Aimport com.google.gerrit.server.change.PostReview;%0Aimport com.google.gerrit.server.change.RevisionResource;%0Aimport com.google.gerrit.server.project.ChangeControl;%0Aimport com.google.gerrit.server.project.NoSuchChangeException;%0Aimport com.google.gerrit.server.query.change.ChangeData;%0Aimport com.google.gwtorm.server.OrmException;%0Aimport com.google.inject.Inject;%0Aimport com.google.inject.Provider;%0A%0Aimport java.io.IOException;%0Aimport java.util.Set;%0A%0Apublic class ReviewUpdater %7B%0A  @Inject%0A  private AccountByEmailCache byEmailCache;%0A%0A  @Inject%0A  ChangeData.Factory changeDataFactory;%0A%0A  @Inject%0A  private ChangeControl.GenericFactory changeFactory;%0A%0A  @Inject%0A  private ChangesCollection collection;%0A%0A  final AutomergeConfig config;%0A  @Inject%0A  Provider%3CReviewDb%3E db;%0A%0A  @Inject%0A  private IdentifiedUser.GenericFactory factory;%0A%0A  @Inject%0A  Provider%3CPostReview%3E reviewer;%0A%0A  public ReviewUpdater(final AutomergeConfig config) %7B%0A    this.config = config;%0A  %7D%0A%0A  public void commentOnReview(final int number, final String comment) throws NoSuchChangeException, OrmException,%0A      AuthException, BadRequestException, UnprocessableEntityException, IOException %7B%0A    final ReviewInput message = new ReviewInput();%0A    message.message = comment;%0A    final Set%3CAccount.Id%3E ids = byEmailCache.get(config.getBotEmail());%0A    final IdentifiedUser bot = factory.create(ids.iterator().next());%0A    final ChangeControl ctl = changeFactory.controlFor(new Change.Id(number), bot);%0A    final ChangeData changeData = changeDataFactory.create(db.get(), new Change.Id(number));%0A%0A    final RevisionResource r = new RevisionResource(collection.parse(ctl), changeData.currentPatchSet());%0A    reviewer.get().apply(r, message);%0A  %7D%0A%0A  public void setMinusTwo(final int number, final String comment) throws NoSuchChangeException, OrmException,%0A      AuthException, BadRequestException, UnprocessableEntityException, IOException %7B%0A    final ReviewInput message = new ReviewInput();%0A    message.message = comment;%0A    message.label(%22Code-Review%22, -2);%0A    final Set%3CAccount.Id%3E ids = byEmailCache.get(config.getBotEmail());%0A    final IdentifiedUser qabot = factory.create(ids.iterator().next());%0A    final ChangeControl ctl = changeFactory.controlFor(new Change.Id(number), qabot);%0A    final ChangeData changeData = changeDataFactory.create(db.get(), new Change.Id(number));%0A%0A    final RevisionResource r = new RevisionResource(collection.parse(ctl), changeData.currentPatchSet());%0A    reviewer.get().apply(r, message);%0A  %7D%0A%0A%7D%0A

Add a utility class to update a review