Merge branch 'stable-3.2' into stable-3.3
* stable-3.2:
Fix test due to change in Gerrit core
Index change when combined state changes
ChecksSubmitRule.Module: Demote base class to AbstractModule
Change-Id: I67a1bccc4f5d81261320afc1b3d9b31fce49a8f3
diff --git a/java/com/google/gerrit/plugins/checks/ChecksUpdate.java b/java/com/google/gerrit/plugins/checks/ChecksUpdate.java
index b017b68..336a961 100644
--- a/java/com/google/gerrit/plugins/checks/ChecksUpdate.java
+++ b/java/com/google/gerrit/plugins/checks/ChecksUpdate.java
@@ -17,12 +17,16 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.flogger.FluentLogger;
import com.google.gerrit.common.Nullable;
+import com.google.gerrit.entities.Change;
import com.google.gerrit.entities.PatchSet;
+import com.google.gerrit.entities.Project;
import com.google.gerrit.exceptions.DuplicateKeyException;
+import com.google.gerrit.extensions.api.changes.Changes;
import com.google.gerrit.extensions.api.changes.NotifyHandling;
import com.google.gerrit.extensions.api.changes.NotifyInfo;
import com.google.gerrit.extensions.api.changes.RecipientType;
import com.google.gerrit.extensions.restapi.BadRequestException;
+import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.plugins.checks.Checks.GetCheckOptions;
import com.google.gerrit.plugins.checks.api.CombinedCheckState;
import com.google.gerrit.plugins.checks.email.CombinedCheckStateUpdatedSender;
@@ -66,6 +70,7 @@
private final Checkers checkers;
private final NotifyResolver notifyResolver;
private final MessageIdGenerator messageIdGenerator;
+ private final Changes changes;
private final Optional<IdentifiedUser> currentUser;
@AssistedInject
@@ -79,6 +84,7 @@
Checkers checkers,
NotifyResolver notifyResolver,
MessageIdGenerator messageIdGenerator,
+ Changes changes,
@Assisted IdentifiedUser currentUser) {
this.checksStorageUpdate = checksStorageUpdate;
this.combinedCheckStateCache = combinedCheckStateCache;
@@ -89,6 +95,7 @@
this.checkers = checkers;
this.notifyResolver = notifyResolver;
this.messageIdGenerator = messageIdGenerator;
+ this.changes = changes;
this.currentUser = Optional.of(currentUser);
}
@@ -102,7 +109,8 @@
Checks checks,
Checkers checkers,
NotifyResolver notifyResolver,
- MessageIdGenerator messageIdGenerator) {
+ MessageIdGenerator messageIdGenerator,
+ Changes changes) {
this.checksStorageUpdate = checksStorageUpdate;
this.combinedCheckStateCache = combinedCheckStateCache;
this.combinedCheckStateUpdatedSenderFactory = combinedCheckStateUpdatedSenderFactory;
@@ -112,6 +120,7 @@
this.checkers = checkers;
this.notifyResolver = notifyResolver;
this.messageIdGenerator = messageIdGenerator;
+ this.changes = changes;
this.currentUser = Optional.empty();
}
@@ -128,6 +137,8 @@
CombinedCheckState newCombinedCheckState =
combinedCheckStateCache.get(key.repository(), key.patchSet());
+ maybeIndexChange(
+ oldCombinedCheckState, newCombinedCheckState, key.repository(), key.patchSet().changeId());
maybeSendEmail(
notifyHandling, notifyDetails, check, oldCombinedCheckState, newCombinedCheckState);
@@ -147,12 +158,28 @@
CombinedCheckState newCombinedCheckState =
combinedCheckStateCache.get(key.repository(), key.patchSet());
+ maybeIndexChange(
+ oldCombinedCheckState, newCombinedCheckState, key.repository(), key.patchSet().changeId());
maybeSendEmail(
notifyHandling, notifyDetails, check, oldCombinedCheckState, newCombinedCheckState);
return check;
}
+ private void maybeIndexChange(
+ CombinedCheckState oldState,
+ CombinedCheckState newState,
+ Project.NameKey project,
+ Change.Id changeId) {
+ if (oldState != newState) {
+ try {
+ changes.id(project.get(), changeId.get()).index();
+ } catch (RestApiException e) {
+ logger.atSevere().withCause(e).log("Cannot index change: %s after check update.", changeId);
+ }
+ }
+ }
+
private void maybeSendEmail(
@Nullable NotifyHandling notifyHandling,
@Nullable Map<RecipientType, NotifyInfo> notifyDetails,
diff --git a/java/com/google/gerrit/plugins/checks/rules/ChecksSubmitRule.java b/java/com/google/gerrit/plugins/checks/rules/ChecksSubmitRule.java
index 0de4b79..4f7ab1c 100644
--- a/java/com/google/gerrit/plugins/checks/rules/ChecksSubmitRule.java
+++ b/java/com/google/gerrit/plugins/checks/rules/ChecksSubmitRule.java
@@ -23,10 +23,10 @@
import com.google.gerrit.entities.SubmitRecord.Status;
import com.google.gerrit.entities.SubmitRequirement;
import com.google.gerrit.extensions.annotations.Exports;
-import com.google.gerrit.extensions.config.FactoryModule;
import com.google.gerrit.plugins.checks.Checks;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gerrit.server.rules.SubmitRule;
+import com.google.inject.AbstractModule;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.io.IOException;
@@ -42,7 +42,7 @@
.setType("checks_pass")
.build();
- public static class Module extends FactoryModule {
+ public static class Module extends AbstractModule {
@Override
public void configure() {
bind(SubmitRule.class)
diff --git a/javatests/com/google/gerrit/plugins/checks/acceptance/api/CreateCheckIT.java b/javatests/com/google/gerrit/plugins/checks/acceptance/api/CreateCheckIT.java
index 8848278..b1e0273 100644
--- a/javatests/com/google/gerrit/plugins/checks/acceptance/api/CreateCheckIT.java
+++ b/javatests/com/google/gerrit/plugins/checks/acceptance/api/CreateCheckIT.java
@@ -349,16 +349,20 @@
@Test
public void createCheckOnChangeEditRejected() throws Exception {
- int changeId = patchSetId.changeId().get();
- gApi.changes().id(changeId).edit().modifyCommitMessage("new message");
- assertThat(gApi.changes().id(changeId).edit().get()).isPresent();
+ int numChangeId = patchSetId.changeId().get();
+ String changeId = gApi.changes().id(numChangeId).get().changeId;
+ gApi.changes()
+ .id(numChangeId)
+ .edit()
+ .modifyCommitMessage("Change edit\n\nChange-Id: " + changeId);
+ assertThat(gApi.changes().id(numChangeId).edit().get()).isPresent();
CheckerUuid checkerUuid = checkerOperations.newChecker().repository(project).create();
CheckInput input = new CheckInput();
input.checkerUuid = checkerUuid.get();
input.state = CheckState.RUNNING;
RestResponse response =
- adminRestSession.post("/changes/" + changeId + "/revisions/edit/checks~checks", input);
+ adminRestSession.post("/changes/" + numChangeId + "/revisions/edit/checks~checks", input);
response.assertConflict();
assertThat(response.getEntityContent()).isEqualTo("checks are not supported on a change edit");
diff --git a/javatests/com/google/gerrit/plugins/checks/acceptance/api/GetCheckIT.java b/javatests/com/google/gerrit/plugins/checks/acceptance/api/GetCheckIT.java
index 97fa1a6..ee3c261 100644
--- a/javatests/com/google/gerrit/plugins/checks/acceptance/api/GetCheckIT.java
+++ b/javatests/com/google/gerrit/plugins/checks/acceptance/api/GetCheckIT.java
@@ -554,8 +554,9 @@
@Test
public void getCheckOnChangeEditRejected() throws Exception {
- int changeId = patchSetId.changeId().get();
- gApi.changes().id(changeId).edit().modifyCommitMessage("new message");
+ int numChangeId = patchSetId.changeId().get();
+ String changeId = gApi.changes().id(numChangeId).get().changeId;
+ gApi.changes().id(changeId).edit().modifyCommitMessage("Change edit\n\nChange-Id: " + changeId);
Optional<EditInfo> editInfo = gApi.changes().id(changeId).edit().get();
assertThat(editInfo).isPresent();
diff --git a/javatests/com/google/gerrit/plugins/checks/acceptance/api/ListChecksIT.java b/javatests/com/google/gerrit/plugins/checks/acceptance/api/ListChecksIT.java
index 1be5870..d21488f 100644
--- a/javatests/com/google/gerrit/plugins/checks/acceptance/api/ListChecksIT.java
+++ b/javatests/com/google/gerrit/plugins/checks/acceptance/api/ListChecksIT.java
@@ -349,7 +349,7 @@
@Test
public void listAllOnChangeEditRejected() throws Exception {
- gApi.changes().id(changeId).edit().modifyCommitMessage("new message");
+ gApi.changes().id(changeId).edit().modifyCommitMessage("Change edit\n\nChange-Id: " + changeId);
Optional<EditInfo> editInfo = gApi.changes().id(changeId).edit().get();
assertThat(editInfo).isPresent();