Merge "Log when post is unsuccessful and max retries exceed"
diff --git a/src/main/java/com/googlesource/gerrit/plugins/webhooks/WebhooksConfig.java b/src/main/java/com/googlesource/gerrit/plugins/webhooks/WebhooksConfig.java
index e46b308..c86e727 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/webhooks/WebhooksConfig.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/webhooks/WebhooksConfig.java
@@ -25,44 +25,16 @@
 import static com.googlesource.gerrit.plugins.webhooks.RemoteConfig.SOCKET_TIMEOUT;
 import static com.googlesource.gerrit.plugins.webhooks.RemoteConfig.SSL_VERIFY;
 
-import com.google.common.base.Strings;
 import com.google.gerrit.entities.RefNames;
-import com.google.gerrit.server.git.meta.VersionedMetaData;
+import com.google.gerrit.server.git.meta.VersionedConfigFile;
 import com.google.inject.Inject;
 import com.googlesource.gerrit.plugins.webhooks.rest.UpsertRemote;
-import java.io.IOException;
 import java.util.List;
-import org.eclipse.jgit.errors.ConfigInvalidException;
-import org.eclipse.jgit.lib.CommitBuilder;
-import org.eclipse.jgit.lib.Config;
 
-public class WebhooksConfig extends VersionedMetaData {
-
-  private final String cfgFileName;
-  private Config cfg;
-
+public class WebhooksConfig extends VersionedConfigFile {
   @Inject
   WebhooksConfig(@WebhooksConfigFileName String cfgFileName) {
-    this.cfgFileName = cfgFileName;
-  }
-
-  @Override
-  protected String getRefName() {
-    return RefNames.REFS_CONFIG;
-  }
-
-  @Override
-  protected void onLoad() throws IOException, ConfigInvalidException {
-    cfg = readConfig(cfgFileName);
-  }
-
-  @Override
-  protected boolean onSave(CommitBuilder commit) throws IOException, ConfigInvalidException {
-    if (Strings.isNullOrEmpty(commit.getMessage())) {
-      commit.setMessage("Updated webhooks\n");
-    }
-    saveConfig(cfgFileName, cfg);
-    return true;
+    super(RefNames.REFS_CONFIG, cfgFileName, "Updated webhooks\n");
   }
 
   public void upsertRemote(String name, UpsertRemote.Input in) {
diff --git a/src/test/java/com/googlesource/gerrit/plugins/webhooks/rest/GetRemoteIT.java b/src/test/java/com/googlesource/gerrit/plugins/webhooks/rest/GetRemoteIT.java
index 5b17a56..9d4c9b3 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/webhooks/rest/GetRemoteIT.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/webhooks/rest/GetRemoteIT.java
@@ -28,7 +28,6 @@
 import com.google.gerrit.acceptance.RestResponse;
 import com.google.gerrit.acceptance.TestPlugin;
 import com.google.gson.reflect.TypeToken;
-import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
 import org.eclipse.jgit.transport.RefSpec;
@@ -38,7 +37,7 @@
 public class GetRemoteIT extends LightweightPluginDaemonTest {
 
   @Test
-  public void noWebhooks() throws IOException {
+  public void noWebhooks() throws Exception {
     RestResponse response =
         adminRestSession.get(
             String.format("/config/server/webhooks~projects/%s/remotes/", project.get()));
@@ -135,7 +134,7 @@
     PushOneCommit push =
         pushFactory.create(
             admin.newIdent(), testRepo, "Create webhooks", "webhooks.config", content);
-    push.to(REFS_CONFIG);
+    push.to(REFS_CONFIG).assertOkStatus();
   }
 
   static Map<String, RemoteInfo> asMap(String json) {