Merge "Add plugin name to event properties"
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/util/PropertyExtractor.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/util/PropertyExtractor.java
index 53e22c0..20bbc1f 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/util/PropertyExtractor.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/util/PropertyExtractor.java
@@ -15,6 +15,7 @@
package com.googlesource.gerrit.plugins.hooks.util;
import com.google.common.collect.Sets;
+import com.google.gerrit.extensions.annotations.PluginName;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.server.data.ApprovalAttribute;
@@ -42,14 +43,17 @@
private IssueExtractor issueExtractor;
private Property.Factory propertyFactory;
private PropertyAttributeExtractor propertyAttributeExtractor;
+ private final String pluginName;
@Inject
PropertyExtractor(IssueExtractor issueExtractor,
Property.Factory propertyFactory,
- PropertyAttributeExtractor propertyAttributeExtractor) {
+ PropertyAttributeExtractor propertyAttributeExtractor,
+ @PluginName String pluginName) {
this.issueExtractor = issueExtractor;
this.propertyFactory = propertyFactory;
this.propertyAttributeExtractor = propertyAttributeExtractor;
+ this.pluginName = pluginName;
}
/**
@@ -226,6 +230,8 @@
Set<Property> properties = Sets.newHashSet();
Property property = propertyFactory.create("issue", issue);
properties.add(property);
+ property = propertyFactory.create("its-name", pluginName);
+ properties.add(property);
for (String occurrence: associations.get(issue)) {
property = propertyFactory.create("association", occurrence);
properties.add(property);
diff --git a/src/main/resources/Documentation/config-rulebase-common.md b/src/main/resources/Documentation/config-rulebase-common.md
index 60e1185..ab25dd3 100644
--- a/src/main/resources/Documentation/config-rulebase-common.md
+++ b/src/main/resources/Documentation/config-rulebase-common.md
@@ -130,6 +130,28 @@
: How the issue of property `issue` got associated to this event.
See [Property: `association`][property-association].
+`its-name`
+: Name of this plugin (i.e.: `@PLUGIN@`). This property can be used to
+ make a rule in the rulebase match only for certain ITS plugins, if more
+ than one is installed.
+
+ For example
+
+ ```
+ [rule "someRuleForBugzillaOnly"]
+ its-name = its-bugzilla
+ approval-Code-Review = -2
+ action = add-comment Heya Bugzilla users, the change had a -2 Code-Review approval.
+ [rule "someRuleForJiraOnly"]
+ its-name = its-jira
+ approval-Code-Review = -2
+ action = add-comment Dear JIRA users, the change had a -2 Code-Review approval.
+ ```
+
+ would report the “Heya Bugzilla...” text only through its-bugzilla for
+ changes that had a -2 Code-Review and have an association through
+ its-bugzilla. And for changes that had a -2 Code-Review and have an
+ association through its-jira, its-jira would report “Dear Jira users, ...”.
The further properties are listed in the event's
corresponding subsection below:
diff --git a/src/test/java/com/googlesource/gerrit/plugins/hooks/util/PropertyExtractorTest.java b/src/test/java/com/googlesource/gerrit/plugins/hooks/util/PropertyExtractorTest.java
index f61e9f1..f1d7d42 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/hooks/util/PropertyExtractorTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/hooks/util/PropertyExtractorTest.java
@@ -17,6 +17,7 @@
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
+import com.google.gerrit.extensions.annotations.PluginName;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.server.config.FactoryModule;
@@ -377,6 +378,10 @@
PropertyExtractor propertyExtractor = injector.getInstance(
PropertyExtractor.class);
+ Property propertyItsName = createMock(Property.class);
+ expect(propertyFactory.create("its-name", "ItsTestName"))
+ .andReturn(propertyItsName).anyTimes();
+
Property propertyEvent = createMock(Property.class);
expect(propertyFactory.create("event", "com.google.gerrit.server.events." +
className)).andReturn(propertyEvent);
@@ -423,6 +428,7 @@
Set<Set<Property>> expected = Sets.newHashSet();
Set<Property> properties = Sets.newHashSet();
+ properties.add(propertyItsName);
properties.add(propertyEvent);
properties.add(propertyEventType);
properties.add(propertyAssociationAnywhere);
@@ -432,6 +438,7 @@
expected.add(properties);
properties = Sets.newHashSet();
+ properties.add(propertyItsName);
properties.add(propertyEvent);
properties.add(propertyEventType);
properties.add(propertyAssociationAnywhere);
@@ -451,6 +458,9 @@
private class TestModule extends FactoryModule {
@Override
protected void configure() {
+ bind(String.class).annotatedWith(PluginName.class)
+ .toInstance("ItsTestName");
+
issueExtractor = createMock(IssueExtractor.class);
bind(IssueExtractor.class).toInstance(issueExtractor);