StarredChangesUtil: Handle unexpected format of reviewed/unreviewed labels
Labels for the Mark Reviewed/Unreviewed functionality have the format 'reviewed/<patch-set-number>' and 'unreviewed/<patch-set-number>'. However users can also set labels that start with 'reviewed/' or 'unreviewed/' but don't have a valid patch set number following. Don't fail for such labels when checking if mutually exclusive labels are set, but just allow them. Change-Id: I8dce0686c06f4b494e2aa650d1297582356b22ec Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
parent
ed0b6dadf8
commit
46902736d4
@ -407,18 +407,8 @@ public class StarredChangesUtil {
|
||||
throw new MutuallyExclusiveLabelsException(DEFAULT_LABEL, IGNORE_LABEL);
|
||||
}
|
||||
|
||||
Set<Integer> reviewedPatchSets =
|
||||
labels
|
||||
.stream()
|
||||
.filter(l -> l.startsWith(REVIEWED_LABEL))
|
||||
.map(l -> Integer.valueOf(l.substring(REVIEWED_LABEL.length() + 1)))
|
||||
.collect(toSet());
|
||||
Set<Integer> unreviewedPatchSets =
|
||||
labels
|
||||
.stream()
|
||||
.filter(l -> l.startsWith(UNREVIEWED_LABEL))
|
||||
.map(l -> Integer.valueOf(l.substring(UNREVIEWED_LABEL.length() + 1)))
|
||||
.collect(toSet());
|
||||
Set<Integer> reviewedPatchSets = getStarredPatchSets(labels, REVIEWED_LABEL);
|
||||
Set<Integer> unreviewedPatchSets = getStarredPatchSets(labels, UNREVIEWED_LABEL);
|
||||
Optional<Integer> ps =
|
||||
Sets.intersection(reviewedPatchSets, unreviewedPatchSets).stream().findFirst();
|
||||
if (ps.isPresent()) {
|
||||
@ -427,6 +417,15 @@ public class StarredChangesUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static Set<Integer> getStarredPatchSets(Set<String> labels, String label) {
|
||||
return labels
|
||||
.stream()
|
||||
.filter(l -> l.startsWith(label))
|
||||
.filter(l -> Ints.tryParse(l.substring(label.length() + 1)) != null)
|
||||
.map(l -> Integer.valueOf(l.substring(label.length() + 1)))
|
||||
.collect(toSet());
|
||||
}
|
||||
|
||||
private static void validateLabels(Collection<String> labels) throws InvalidLabelsException {
|
||||
if (labels == null) {
|
||||
return;
|
||||
|
@ -15,7 +15,6 @@
|
||||
package com.google.gerrit.server.schema;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
import static java.util.stream.Collectors.toSet;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import com.google.gerrit.reviewdb.client.RefNames;
|
||||
@ -64,15 +63,18 @@ public class Schema_161 extends SchemaVersion {
|
||||
for (Ref ref : git.getRefDatabase().getRefs(RefNames.REFS_STARRED_CHANGES).values()) {
|
||||
StarRef starRef = StarredChangesUtil.readLabels(git, ref.getName());
|
||||
|
||||
Set<Integer> mutedPatchSets = getStarredPatchSets(starRef, MUTE_LABEL);
|
||||
Set<Integer> mutedPatchSets =
|
||||
StarredChangesUtil.getStarredPatchSets(starRef.labels(), MUTE_LABEL);
|
||||
if (mutedPatchSets.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Set<Integer> reviewedPatchSets =
|
||||
getStarredPatchSets(starRef, StarredChangesUtil.REVIEWED_LABEL);
|
||||
StarredChangesUtil.getStarredPatchSets(
|
||||
starRef.labels(), StarredChangesUtil.REVIEWED_LABEL);
|
||||
Set<Integer> unreviewedPatchSets =
|
||||
getStarredPatchSets(starRef, StarredChangesUtil.UNREVIEWED_LABEL);
|
||||
StarredChangesUtil.getStarredPatchSets(
|
||||
starRef.labels(), StarredChangesUtil.UNREVIEWED_LABEL);
|
||||
|
||||
List<String> newLabels =
|
||||
starRef
|
||||
@ -109,14 +111,4 @@ public class Schema_161 extends SchemaVersion {
|
||||
throw new OrmException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private Set<Integer> getStarredPatchSets(StarRef starRef, String label) {
|
||||
return starRef
|
||||
.labels()
|
||||
.stream()
|
||||
.filter(l -> l.startsWith(label))
|
||||
.filter(l -> Ints.tryParse(l.substring(label.length() + 1)) != null)
|
||||
.map(l -> Integer.valueOf(l.substring(label.length() + 1)))
|
||||
.collect(toSet());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user