blob: 4cacdd6a6d772b0b05fcb923642ce5c0c77e79ff [file] [log] [blame]
package com.criteo.gerrit.plugins.automerge;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
import java.io.File;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** A comment pushed by the plugin to a Gerrit patchset. */
public class PluginComment {
private static final Logger log = LoggerFactory.getLogger(PluginComment.class);
private final File templatePath;
private final String defaultMessage;
PluginComment(File templatePath, String defaultMessage) {
this.templatePath = templatePath;
this.defaultMessage = defaultMessage;
}
/**
* Returns the comment message, possibly with interpolation placeholders.
*
* @return a string
*/
String getContent() {
if (templatePath.exists()) {
try {
return Files.toString(templatePath, Charsets.UTF_8);
} catch (final IOException exc) {
log.error("Not able to read " + templatePath, exc);
}
}
return defaultMessage;
}
}