blob: a9c2cc0a29bddb4bcf5431da9c264f9993494cb7 [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 final static 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;
}
}