Adapt automerger to expect minimal event payload

Gerrit will start sending events with minimal payload only on
googlesource.com. This commit makes it so that automerger will only use
identifiers from events and load the rest of the data on demand.

Change-Id: I196fa098c9d1216a908b943c45e99068a2961010
diff --git a/src/main/java/com/googlesource/gerrit/plugins/automerger/DownstreamCreator.java b/src/main/java/com/googlesource/gerrit/plugins/automerger/DownstreamCreator.java
index 84ae7c3..661f3bb 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/automerger/DownstreamCreator.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/automerger/DownstreamCreator.java
@@ -100,10 +100,15 @@
   public void onChangeAbandoned(ChangeAbandonedListener.Event event) {
     try (ManualRequestContext ctx = oneOffRequestContext.openAs(config.getContextUserId())) {
       ChangeInfo change = event.getChange();
-      String revision = event.getRevision().commit.commit;
+      String revision =
+          gApi.changes()
+              .id(change._number)
+              .revision(event.getRevision()._number)
+              .commit(false)
+              .commit;
       log.debug("Detected revision {} abandoned on {}.", revision, change.project);
       abandonDownstream(change, revision);
-    } catch (ConfigInvalidException | StorageException e) {
+    } catch (ConfigInvalidException | StorageException | RestApiException e) {
       log.error("Automerger plugin failed onChangeAbandoned for {}", event.getChange().id, e);
     }
   }
@@ -191,7 +196,7 @@
         return;
       }
       ChangeInfo change = event.getChange();
-      String revision = change.currentRevision;
+      String revision = gApi.changes().id(event.getChange()._number).current().commit(false).commit;
       Set<String> downstreamBranches;
       downstreamBranches = config.getDownstreamBranches(change.branch, change.project);
 
@@ -558,7 +563,8 @@
   private void automergeChanges(ChangeInfo change, RevisionInfo revisionInfo)
       throws RestApiException, IOException, ConfigInvalidException, InvalidQueryParameterException,
           StorageException {
-    String currentRevision = revisionInfo.commit.commit;
+    String currentRevision =
+        gApi.changes().id(change._number).revision(revisionInfo._number).commit(false).commit;
     log.debug(
         "Handling patchsetevent with change id {} and revision {}", change.id, currentRevision);
 
diff --git a/src/test/java/com/googlesource/gerrit/plugins/automerger/DownstreamCreatorIT.java b/src/test/java/com/googlesource/gerrit/plugins/automerger/DownstreamCreatorIT.java
index a59bff8..c472128 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/automerger/DownstreamCreatorIT.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/automerger/DownstreamCreatorIT.java
@@ -56,6 +56,7 @@
 import com.google.gerrit.extensions.restapi.BinaryResult;
 import com.google.gerrit.extensions.restapi.RestApiException;
 import com.google.gerrit.server.group.SystemGroupBackend;
+import com.google.gerrit.testing.ConfigSuite;
 import com.google.inject.Inject;
 import com.googlesource.gerrit.plugins.automerger.helpers.ConfigOption;
 import java.io.InputStream;
@@ -76,6 +77,18 @@
   @Inject private GroupOperations groupOperations;
   @Inject private ProjectOperations projectOperations;
 
+  @ConfigSuite.Default
+  public static Config minimalEventPayload() {
+    Config cfg = new Config();
+    // Expect only identifiers in internal Gerrit events
+    cfg.setStringList(
+        "event",
+        "payload",
+        "listChangeOptions",
+        ImmutableList.of("SKIP_MERGEABLE", "SKIP_DIFFSTAT"));
+    return cfg;
+  }
+
   @Test
   public void testExpectedFlow() throws Exception {
     Project.NameKey manifestNameKey = defaultSetup();