Merge "Use lower case condition keys"
diff --git a/hooks-its/pom.xml b/hooks-its/pom.xml
index 1a472c7..41179f9 100644
--- a/hooks-its/pom.xml
+++ b/hooks-its/pom.xml
@@ -22,7 +22,7 @@
   <parent>
     <groupId>com.googlesource.gerrit.plugins.its</groupId>
     <artifactId>hooks-its-parent</artifactId>
-    <version>2.6-SNAPSHOT</version>
+    <version>2.7-SNAPSHOT</version>
   </parent>
   <artifactId>hooks-its</artifactId>
   <name>Gerrit Code Review - Commit validation and Workflow</name>
diff --git a/hooks-its/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilter.java b/hooks-its/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilter.java
index 10b13d6..b89d1b3 100644
--- a/hooks-its/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilter.java
+++ b/hooks-its/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilter.java
@@ -172,7 +172,7 @@
       } else if (event instanceof RefUpdatedEvent) {
         doFilter((RefUpdatedEvent) event);
       } else {
-        log.info("Event " + event + " not recognised and ignored");
+        log.debug("Event " + event + " not recognised and ignored");
       }
     } catch (Throwable e) {
       log.error("Event " + event + " processing failed", e);
diff --git a/hooks-its/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilterAddComment.java b/hooks-its/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilterAddComment.java
index 5d178a9..c138d18 100644
--- a/hooks-its/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilterAddComment.java
+++ b/hooks-its/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilterAddComment.java
@@ -16,8 +16,11 @@
 
 import java.io.IOException;
 
+import org.eclipse.jgit.lib.Config;
+
 import com.google.common.base.Strings;
 import com.google.gerrit.server.config.AnonymousCowardName;
+import com.google.gerrit.server.config.GerritServerConfig;
 import com.google.gerrit.server.events.AccountAttribute;
 import com.google.gerrit.server.events.ApprovalAttribute;
 import com.google.gerrit.server.events.ChangeAbandonedEvent;
@@ -37,26 +40,48 @@
   @Inject @AnonymousCowardName
   private String anonymousCowardName;
 
+  @Inject
+  @GerritServerConfig
+  private Config gerritConfig;
+
   @Override
   public void doFilter(CommentAddedEvent hook) throws IOException {
+    if (!(gerritConfig.getBoolean(its.name(), null, "commentOnCommentAdded",
+        true))) {
+      return;
+    }
+
     String comment = getComment(hook);
     addComment(hook.change, comment);
   }
 
   @Override
   public void doFilter(ChangeMergedEvent hook) throws IOException {
+    if (!(gerritConfig.getBoolean(its.name(), null, "commentOnChangeMerged",
+        true))) {
+      return;
+    }
+
     String comment = getComment(hook);
     addComment(hook.change, comment);
   }
 
   @Override
   public void doFilter(ChangeAbandonedEvent hook) throws IOException {
+    if (!(gerritConfig.getBoolean(its.name(), null, "commentOnChangeAbandoned",
+        true))) {
+      return;
+    }
     String comment = getComment(hook);
     addComment(hook.change, comment);
   }
 
   @Override
   public void doFilter(ChangeRestoredEvent hook) throws IOException {
+    if (!(gerritConfig.getBoolean(its.name(), null, "commentOnChangeRestored",
+        true))) {
+      return;
+    }
     String comment = getComment(hook);
     addComment(hook.change, comment);
   }
diff --git a/hooks-its/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilterAddRelatedLinkToChangeId.java b/hooks-its/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilterAddRelatedLinkToChangeId.java
index fe83bc2..0d1e5c1 100644
--- a/hooks-its/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilterAddRelatedLinkToChangeId.java
+++ b/hooks-its/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilterAddRelatedLinkToChangeId.java
@@ -17,9 +17,11 @@
 import java.io.IOException;
 import java.net.URL;
 
+import org.eclipse.jgit.lib.Config;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.gerrit.server.config.GerritServerConfig;
 import com.google.gerrit.server.events.PatchSetCreatedEvent;
 import com.google.inject.Inject;
 import com.googlesource.gerrit.plugins.hooks.its.ItsFacade;
@@ -33,8 +35,16 @@
   @Inject
   private ItsFacade its;
 
+  @Inject
+  @GerritServerConfig
+  private Config gerritConfig;
+
   @Override
   public void doFilter(PatchSetCreatedEvent patchsetCreated) throws IOException {
+    if (!(gerritConfig.getBoolean(its.name(), null, "commentOnPatchSetCreated",
+        true))) {
+      return;
+    }
 
     String gitComment =
         getComment(patchsetCreated.change.project,
@@ -43,7 +53,7 @@
 
     for (String issue : issues) {
       its.addRelatedLink(issue, new URL(patchsetCreated.change.url),
-          "Gerrit Patch-Set: " + patchsetCreated.change.id + "/"
+          "Gerrit Patch Set " + patchsetCreated.change.id + "/"
               + patchsetCreated.patchSet.number);
     }
   }
diff --git a/hooks-its/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilterAddRelatedLinkToGitWeb.java b/hooks-its/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilterAddRelatedLinkToGitWeb.java
index 02d40e2..0db89d9 100644
--- a/hooks-its/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilterAddRelatedLinkToGitWeb.java
+++ b/hooks-its/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilterAddRelatedLinkToGitWeb.java
@@ -52,6 +52,10 @@
 
   @Override
   public void doFilter(RefUpdatedEvent hook) throws IOException {
+    if (!(gerritConfig.getBoolean(its.name(), null, "commentOnRefUpdatedGitWeb",
+        true))) {
+      return;
+    }
 
     String gitComment = getComment(hook.refUpdate.project,  hook.refUpdate.newRev);
     log.debug("Git commit " + hook.refUpdate.newRev + ": " + gitComment);
diff --git a/hooks-its/src/main/resources/Documentation/config.md b/hooks-its/src/main/resources/Documentation/config.md
new file mode 100644
index 0000000..9167fe3
--- /dev/null
+++ b/hooks-its/src/main/resources/Documentation/config.md
@@ -0,0 +1,63 @@
+hooks-its
+=========
+
+link:https://gerrit-review.googlesource.com/#/admin/projects/plugins/hooks-its['hooks-its']
+is by itself not a real plugin, but the common parent project for issue tracking
+system (ITS) plugins for gerrit, such as
+link:https://gerrit-review.googlesource.com/#/admin/projects/plugins/hooks-bugzilla['hooks-bugzilla'],
+or
+link:https://gerrit-review.googlesource.com/#/admin/projects/plugins/hooks-jira['hooks-jira'].
+
+
+
+Common configuration
+--------------------
+
+The base functionality for 'hooks-its' based plugins can be configured via the
+plugin's section (e.g.: `bugzilla` for 'hooks-bugzilla') within
+`etc/gerrit.config`. In the following description, we use `itsName` as
+placeholder for the plugin's name.  Be sure to replace it with the plugin's real
+name in the documentation of a 'hooks-its' based plugin (e.g.: Use `bugzilla`
+instead of `itsName` for 'hooks-bugzilla').
+
+[[itsName.commentOnChangeAbandoned]]itsName.commentOnChangeAbandoned::
++
+If true, abandoning a change adds an ITS comment to the change's associated
+issue.
++
+Default is `true`.
+
+
+[[itsName.commentOnChangeMerged]]itsName.commentOnChangeMerged::
++
+If true, merging a change's patch set adds an ITS comment to the change's
+associated issue.
++
+Default is `true`.
+
+[[itsName.commentOnChangeRestored]]itsName.commentOnChangeRestored::
++
+If true, restoring an abandoned change adds an ITS comment to the change's
+associated issue.
++
+Default is `true`.
+
+[[itsName.commentOnCommentAdded]]itsName.commentOnCommentAdded::
++
+If true, adding a comment and/or review to a change in gerrit adds an ITS
+comment to the change's associated issue.
++
+Default is `true`.
+
+[[itsName.commentOnPatchSetCreated]]itsName.commentOnPatchSetCreated::
++
+If true, creating a patch set for a change adds an ITS comment to the change's
+associated issue.
++
+Default is `true`.
+
+[[itsName.commentOnRefUpdatedGitWeb]]itsName.commentOnRefUpdatedGitWeb::
++
+If true, updating a ref adds a GitWeb link to the associated issue.
++
+Default is `true`.
diff --git a/pom.xml b/pom.xml
index eb0d14f..4b67658 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,7 +22,7 @@
   <groupId>com.googlesource.gerrit.plugins.its</groupId>
   <artifactId>hooks-its-parent</artifactId>
   <packaging>pom</packaging>
-  <version>2.6-SNAPSHOT</version>
+  <version>2.7-SNAPSHOT</version>
 
   <name>Gerrit Code Review - Issue tracker support</name>