Fix adding votes
The injected value for labelTypes was empty, so no votes (only
Submitted-by, Submitted-at, ...) were added to the reviewnotes. We now
initialize labelTypes from the project state, and thereby correctly
add votes again.
Change-Id: I078d591469b1a4a40d59ebc5693c52873f4eb842
diff --git a/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/CreateReviewNotes.java b/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/CreateReviewNotes.java
index 42374ac..63d9186 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/CreateReviewNotes.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/CreateReviewNotes.java
@@ -15,6 +15,7 @@
package com.googlesource.gerrit.plugins.reviewnotes;
import java.io.IOException;
+import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;
@@ -51,6 +52,8 @@
import com.google.gerrit.server.git.LabelNormalizer;
import com.google.gerrit.server.git.NotesBranchUtil;
import com.google.gerrit.server.project.NoSuchChangeException;
+import com.google.gerrit.server.project.ProjectCache;
+import com.google.gerrit.server.project.ProjectState;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
@@ -86,7 +89,7 @@
CreateReviewNotes(@GerritPersonIdent final PersonIdent gerritIdent,
final AccountCache accountCache,
final @AnonymousCowardName String anonymousCowardName,
- final LabelTypes labelTypes,
+ final ProjectCache projectCache,
final LabelNormalizer labelNormalizer,
final NotesBranchUtil.Factory notesBranchUtilFactory,
final @Nullable @CanonicalWebUrl String canonicalWebUrl,
@@ -96,7 +99,14 @@
this.gerritServerIdent = gerritIdent;
this.accountCache = accountCache;
this.anonymousCowardName = anonymousCowardName;
- this.labelTypes = labelTypes;
+ ProjectState projectState = projectCache.get(project);
+ if (projectState == null) {
+ log.error("Could not obtain available labels for project "
+ + project.get() + ". Expect missing labels in its review notes.");
+ this.labelTypes = new LabelTypes(Collections.<LabelType> emptyList());
+ } else {
+ this.labelTypes = projectState.getLabelTypes();
+ }
this.labelNormalizer = labelNormalizer;
this.notesBranchUtilFactory = notesBranchUtilFactory;
this.canonicalWebUrl = canonicalWebUrl;