Prevent infinite loop on messages emitted by the plugin
Change-Id: I27315e3765284cdf1fc0192d624392823f9a7c50
diff --git a/src/main/java/com/criteo/gerrit/plugins/automerge/AutomaticMerger.java b/src/main/java/com/criteo/gerrit/plugins/automerge/AutomaticMerger.java
index 8a3147f..15d3bce 100644
--- a/src/main/java/com/criteo/gerrit/plugins/automerge/AutomaticMerger.java
+++ b/src/main/java/com/criteo/gerrit/plugins/automerge/AutomaticMerger.java
@@ -26,7 +26,6 @@
import com.google.gerrit.server.change.PostReview;
import com.google.gerrit.server.change.Submit;
import com.google.gerrit.server.data.AccountAttribute;
-import com.google.gerrit.server.data.ApprovalAttribute;
import com.google.gerrit.server.data.ChangeAttribute;
import com.google.gerrit.server.events.CommentAddedEvent;
import com.google.gerrit.server.events.Event;
@@ -201,14 +200,8 @@
if (!config.getBotEmail().equals(account.email)) {
return true;
}
- ApprovalAttribute[] approvals = comment.approvals.get();
- if (approvals != null) {
- for (ApprovalAttribute approval : approvals) {
- // See ReviewUpdate#setMinusOne
- if (!("Code-Review".equals(approval.type) && "-1".equals(approval.value))) {
- return true;
- }
- }
+ if (!comment.comment.contains(ReviewUpdater.commentsPrefix)) {
+ return true;
}
return false;
}
diff --git a/src/main/java/com/criteo/gerrit/plugins/automerge/ReviewUpdater.java b/src/main/java/com/criteo/gerrit/plugins/automerge/ReviewUpdater.java
index 9ee5e0e..af2e7a6 100644
--- a/src/main/java/com/criteo/gerrit/plugins/automerge/ReviewUpdater.java
+++ b/src/main/java/com/criteo/gerrit/plugins/automerge/ReviewUpdater.java
@@ -26,6 +26,13 @@
public class ReviewUpdater {
private final static Logger log = LoggerFactory.getLogger(AutomaticMerger.class);
+ /**
+ * Prefix used in front of messages pushed to Gerrit by this plugin. This prefix is used to
+ * discriminate the messages emitted by the plugin from the other messages and avoid infinite
+ * loops.
+ */
+ public static final String commentsPrefix = "[Autosubmitter] ";
+
@Inject
ChangeData.Factory changeDataFactory;
@@ -52,7 +59,7 @@
}
private ReviewInput createComment(final String commentTemplate) {
- return new ReviewInput().message(getCommentFromFile(commentTemplate));
+ return new ReviewInput().message(commentsPrefix + getCommentFromFile(commentTemplate));
}
private String getCommentFromFile(final String filename) {