Porting to Gerrit 2.12 and master
Gerrit 2.12 and master have a few differences in the SitePaths and
UpdateException when submitting a change.
This patch allows to make this plugin work with the new versions
of Gerrit.
Change-Id: If29f8ee45175aad62409dd1db4d62c57689d6984
diff --git a/src/main/java/com/criteo/gerrit/plugins/automerge/AutomaticMerger.java b/src/main/java/com/criteo/gerrit/plugins/automerge/AutomaticMerger.java
index b27e7cf..3aa6b26 100644
--- a/src/main/java/com/criteo/gerrit/plugins/automerge/AutomaticMerger.java
+++ b/src/main/java/com/criteo/gerrit/plugins/automerge/AutomaticMerger.java
@@ -33,6 +33,7 @@
import com.google.gerrit.server.events.PatchSetCreatedEvent;
import com.google.gerrit.server.events.TopicChangedEvent;
import com.google.gerrit.server.git.MergeUtil;
+import com.google.gerrit.server.git.UpdateException;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gwtorm.server.OrmException;
@@ -124,7 +125,7 @@
log.info(String.format("Change %d is submittable. Will try to merge all related changes.", reviewNumber));
attemptToMerge(change);
}
- } catch (final RestApiException | NoSuchChangeException | OrmException | IOException e) {
+ } catch (final RestApiException | NoSuchChangeException | OrmException | UpdateException | IOException e) {
log.error("An exception occured while trying to atomic merge a change.", e);
throw new RuntimeException(e);
}
@@ -152,7 +153,7 @@
return false;
}
- private void attemptToMerge(ChangeAttribute change) throws RestApiException, OrmException, NoSuchChangeException, IOException {
+ private void attemptToMerge(ChangeAttribute change) throws RestApiException, OrmException, NoSuchChangeException, IOException, UpdateException {
final List<ChangeInfo> related = Lists.newArrayList();
if (atomicityHelper.isAtomicReview(change)) {
related.addAll(api.changes().query("status: open AND topic: " + change.topic)
@@ -197,7 +198,7 @@
log.info(String.format("Detected atomic review on change %d.", reviewNumber));
reviewUpdater.commentOnReview(reviewNumber, AutomergeConfig.ATOMIC_REVIEW_DETECTED_FILE);
}
- } catch (RestApiException | IOException | NoSuchChangeException | OrmException e) {
+ } catch (RestApiException | IOException | NoSuchChangeException | OrmException | UpdateException e) {
throw new RuntimeException(e);
}
}
diff --git a/src/main/java/com/criteo/gerrit/plugins/automerge/AutomergeConfig.java b/src/main/java/com/criteo/gerrit/plugins/automerge/AutomergeConfig.java
index 135c8df..40d0811 100644
--- a/src/main/java/com/criteo/gerrit/plugins/automerge/AutomergeConfig.java
+++ b/src/main/java/com/criteo/gerrit/plugins/automerge/AutomergeConfig.java
@@ -45,7 +45,7 @@
topicPrefix = defaultTopicPrefix;
}
- templatesPath = paths.etc_dir;
+ templatesPath = paths.etc_dir.toFile();
}
public final String getBotEmail() {
diff --git a/src/main/java/com/criteo/gerrit/plugins/automerge/ReviewUpdater.java b/src/main/java/com/criteo/gerrit/plugins/automerge/ReviewUpdater.java
index 32c05fe..b2bd5be 100644
--- a/src/main/java/com/criteo/gerrit/plugins/automerge/ReviewUpdater.java
+++ b/src/main/java/com/criteo/gerrit/plugins/automerge/ReviewUpdater.java
@@ -10,6 +10,7 @@
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.change.PostReview;
import com.google.gerrit.server.change.RevisionResource;
+import com.google.gerrit.server.git.UpdateException;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gwtorm.server.OrmException;
@@ -40,12 +41,12 @@
@Inject
private AtomicityHelper atomicityHelper;
- public void commentOnReview(final int number, final String commentTemplate) throws RestApiException, OrmException, IOException, NoSuchChangeException {
+ public void commentOnReview(final int number, final String commentTemplate) throws RestApiException, OrmException, IOException, NoSuchChangeException, UpdateException {
final ReviewInput comment = createComment(commentTemplate);
applyComment(number, comment);
}
- public void setMinusOne(final int number, final String commentTemplate) throws RestApiException, OrmException, IOException, NoSuchChangeException {
+ public void setMinusOne(final int number, final String commentTemplate) throws RestApiException, OrmException, IOException, NoSuchChangeException, UpdateException {
final ReviewInput message = createComment(commentTemplate).label("Code-Review", -1);
applyComment(number, message);
}
@@ -65,7 +66,7 @@
}
}
- private void applyComment(final int number, ReviewInput comment) throws RestApiException, OrmException, IOException, NoSuchChangeException {
+ private void applyComment(final int number, ReviewInput comment) throws RestApiException, OrmException, IOException, NoSuchChangeException, UpdateException {
final RevisionResource r = atomicityHelper.getRevisionResource(number);
reviewer.get().apply(r, comment);
}
diff --git a/src/test/java/com/criteo/gerrit/plugins/automerge/AutomergeConfigTest.java b/src/test/java/com/criteo/gerrit/plugins/automerge/AutomergeConfigTest.java
index 3ff50ee..49535db 100644
--- a/src/test/java/com/criteo/gerrit/plugins/automerge/AutomergeConfigTest.java
+++ b/src/test/java/com/criteo/gerrit/plugins/automerge/AutomergeConfigTest.java
@@ -8,16 +8,17 @@
import org.eclipse.jgit.lib.Config;
import org.junit.Test;
-import java.io.File;
import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.nio.file.Paths;
public class AutomergeConfigTest {
@Test
- public void testGetDefaultConfig() {
+ public void testGetDefaultConfig() throws IOException {
final Config conf = new Config();
try {
- final SitePaths paths = new SitePaths(new File("."));
+ final SitePaths paths = new SitePaths(Paths.get("."));
final AutomergeConfig amconf = new AutomergeConfig(conf, paths);
@@ -29,10 +30,10 @@
}
@Test
- public void testGetValues() {
+ public void testGetValues() throws IOException {
final Config conf = new Config();
try {
- final SitePaths paths = new SitePaths(new File("."));
+ final SitePaths paths = new SitePaths(Paths.get("."));
conf.setString(AutomergeConfig.AUTOMERGE_SECTION, null, AutomergeConfig.BOT_EMAIL_KEY, "Foo@bar.com");
conf.setString(AutomergeConfig.AUTOMERGE_SECTION, null, AutomergeConfig.TOPIC_PREFIX_KEY, "fake_topic_prefix");