Set current project name for EventListener events.
Currently, the current project name is not properly set when receiving
RefEvent events which prevents determining project level settings.
For example, IssueAction events are not triggered during PatchSetEvents
because the current project defines what the commentlink should be,
which is required to link the commit to a specific issue.
Bug: Issue 9388
Change-Id: Ibe2c7bf641bd4c76fe4afadec4eec5744a27f160
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/base/workflow/ActionController.java b/src/main/java/com/googlesource/gerrit/plugins/its/base/workflow/ActionController.java
index 4af8f1b..879cae8 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/its/base/workflow/ActionController.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/base/workflow/ActionController.java
@@ -57,6 +57,7 @@
public void onEvent(Event event) {
if (event instanceof RefEvent) {
RefEvent refEvent = (RefEvent) event;
+ ItsConfig.setCurrentProjectName(refEvent.getProjectNameKey());
if (itsConfig.isEnabled(refEvent)) {
handleEvent(refEvent);
}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/its/base/workflow/ActionControllerTest.java b/src/test/java/com/googlesource/gerrit/plugins/its/base/workflow/ActionControllerTest.java
index bd32089..b7a0aad 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/its/base/workflow/ActionControllerTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/its/base/workflow/ActionControllerTest.java
@@ -20,6 +20,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.gerrit.extensions.config.FactoryModule;
+import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.events.ChangeEvent;
import com.google.gerrit.server.events.RefEvent;
import com.google.inject.Guice;
@@ -34,6 +35,7 @@
import java.util.Set;
public class ActionControllerTest extends LoggingMockingTestCase {
+ private static Project.NameKey testProjectName = new Project.NameKey("test-project");
private Injector injector;
private PropertyExtractor propertyExtractor;
@@ -50,6 +52,7 @@
expect(propertyExtractor.extractFrom(event))
.andReturn(new RefEventProperties(Collections.emptyMap(), propertySets))
.anyTimes();
+ expect(event.getProjectNameKey()).andReturn(testProjectName).once();
replayMocks();
@@ -68,6 +71,7 @@
expect(propertyExtractor.extractFrom(event))
.andReturn(new RefEventProperties(properties, propertySets))
.anyTimes();
+ expect(event.getProjectNameKey()).andReturn(testProjectName).once();
// When no issues are found in the commit message, the list of actions is empty
// as there are no matchs with an empty map of properties.
@@ -97,6 +101,7 @@
expect(propertyExtractor.extractFrom(event))
.andReturn(new RefEventProperties(projectProperties, propertySets))
.anyTimes();
+ expect(event.getProjectNameKey()).andReturn(testProjectName).once();
ActionRequest issueActionRequest1 = createMock(ActionRequest.class);
Collection<ActionRequest> issueActionRequests = ImmutableList.of(issueActionRequest1);
@@ -127,6 +132,7 @@
expect(propertyExtractor.extractFrom(event))
.andReturn(new RefEventProperties(Collections.emptyMap(), propertySets))
.anyTimes();
+ expect(event.getProjectNameKey()).andReturn(testProjectName).once();
ActionRequest actionRequest1 = createMock(ActionRequest.class);
Collection<ActionRequest> actionRequests1 = ImmutableList.of(actionRequest1);