package com.criteo.gerrit.plugins.automerge;

import com.google.gerrit.server.config.GerritServerConfig;

import org.eclipse.jgit.lib.Config;

public class AutomergeConfig {

  public final static String AUTOMERGE_SECTION = "automerge";
  public final static String BOT_EMAIL_KEY = "botEmail";
  private final static String defaultBotEmail = "qabot@criteo.com";
  private final static String defaultTopicPrefix = "crossrepo/";
  public final static String TOPIC_PREFIX_KEY = "topicPrefix";

  public static final String getDefaultBotEmail() {
    return defaultBotEmail;

  }

  public static final String getDefaultTopicPrefix() {
    return defaultTopicPrefix;
  }

  private final Config config;


  public AutomergeConfig(@GerritServerConfig final Config config) {
    this.config = config;
  }

  public final String getBotEmail() {
    final String botEmail = config.getString(AUTOMERGE_SECTION, null, BOT_EMAIL_KEY);
    if (botEmail == null) {
      return defaultBotEmail;
    }
    return botEmail;
  }

  public final String getTopicPrefix() {
    final String topicPrefix = config.getString(AUTOMERGE_SECTION, null, TOPIC_PREFIX_KEY);
    if (topicPrefix == null) {
      return defaultTopicPrefix;
    }
    return topicPrefix;
  }
}

@@ -102,77 +102,432 @@
 ig;%0A
-%0Aimport org.eclipse.jgit.lib.Config;%0A%0Apublic class AutomergeConfig %7B%0A
+import com.google.gerrit.server.config.SitePaths;%0Aimport com.google.inject.Inject;%0A%0Aimport org.apache.commons.io.FileUtils;%0Aimport org.eclipse.jgit.lib.Config;%0A%0Aimport java.io.File;%0Aimport java.io.IOException;%0A%0A%0Apublic class AutomergeConfig %7B%0A%0A  public final static String ATOMIC_REVIEW_DETECTED_FILE = %22atomic_review_detected.txt%22;%0A  public final static String ATOMIC_REVIEWS_SAME_REPO_FILE = %22atomic_review_same_repo.txt%22;
 %0A  p
@@ -642,16 +642,89 @@
 Email%22;%0A
+  public final static String CANT_MERGE_COMMENT_FILE = %22cantmerge.txt%22;%0A%0A
   privat
@@ -1121,16 +1121,58 @@
 onfig;%0A%0A
+  @Inject%0A  private SitePaths sitePaths;%0A%0A
 %0A  publi
@@ -1473,24 +1473,561 @@
 Email;%0A  %7D%0A%0A
+  /**%0A   * Return a comment from a file located in the gerrit etc_dir%0A   *%0A   * @param filename%0A   * @return a string containing a comment.%0A   * @throws IOException%0A   */%0A  public final String getCommentFromFile(final String filename) %7B%0A    final File commentFile = new File(sitePaths.etc_dir, filename);%0A    try %7B%0A      return FileUtils.readFileToString(commentFile);%0A    %7D catch (final IOException exc) %7B%0A      return String.format(%22Cannot find %25s file in gerrit etc dir. Please check your gerrit configuration%22, filename);%0A    %7D%0A  %7D%0A%0A
   public fin
@@ -2245,10 +2245,11 @@
 ix;%0A  %7D%0A
+%0A
 %7D%0A

Add a way to retrieve a comment from a file.