Allow configuration of a default value for a label.
This change allows a project admin or owner to define a default value (or score) for a label. The default value is set in the project configurations file with a 'defaultValue' key. The defaultValue must be within the range of valid label values. It is an optional label setting, if not defined the defaultValue for the label will be 0. When a defaultValue is defined, that value will get set in the Reply dialog by default. A defaultValue can be set to a score that is outside of the permissible range for a user. In that case the score that will get set in the Reply box will be the next closes score to the defaultValue. feature: Issue 2041 Change-Id: I12dece29b043e09eaab62cdcf56146a1380041bc
This commit is contained in:
@@ -21,9 +21,11 @@ import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.gerrit.common.data.AccessSection;
|
||||
import com.google.gerrit.common.data.ContributorAgreement;
|
||||
import com.google.gerrit.common.data.GroupReference;
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.common.data.Permission;
|
||||
import com.google.gerrit.common.data.PermissionRule;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
@@ -47,6 +49,7 @@ import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
public class ProjectConfigTest extends LocalDiskRepositoryTestCase {
|
||||
private final GroupReference developers = new GroupReference(
|
||||
@@ -114,6 +117,60 @@ public class ProjectConfigTest extends LocalDiskRepositoryTestCase {
|
||||
assertFalse(push.getExclusiveGroup());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadConfigLabelDefaultValue() throws Exception {
|
||||
RevCommit rev = util.commit(util.tree( //
|
||||
util.file("groups", util.blob(group(developers))), //
|
||||
util.file("project.config", util.blob(""//
|
||||
+ "[label \"CustomLabel\"]\n" //
|
||||
+ " value = -1 Negative\n" //
|
||||
+ " value = 0 No Score\n" //
|
||||
+ " value = 1 Positive\n")) //
|
||||
));
|
||||
|
||||
ProjectConfig cfg = read(rev);
|
||||
Map<String, LabelType> labels = cfg.getLabelSections();
|
||||
Short dv = labels.entrySet().iterator().next().getValue().getDefaultValue();
|
||||
assertEquals(0, (int) dv);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadConfigLabelDefaultValueInRange() throws Exception {
|
||||
RevCommit rev = util.commit(util.tree( //
|
||||
util.file("groups", util.blob(group(developers))), //
|
||||
util.file("project.config", util.blob(""//
|
||||
+ "[label \"CustomLabel\"]\n" //
|
||||
+ " value = -1 Negative\n" //
|
||||
+ " value = 0 No Score\n" //
|
||||
+ " value = 1 Positive\n" //
|
||||
+ " defaultValue = -1\n")) //
|
||||
));
|
||||
|
||||
ProjectConfig cfg = read(rev);
|
||||
Map<String, LabelType> labels = cfg.getLabelSections();
|
||||
Short dv = labels.entrySet().iterator().next().getValue().getDefaultValue();
|
||||
assertEquals(-1, (int) dv);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadConfigLabelDefaultValueNotInRange() throws Exception {
|
||||
RevCommit rev = util.commit(util.tree( //
|
||||
util.file("groups", util.blob(group(developers))), //
|
||||
util.file("project.config", util.blob(""//
|
||||
+ "[label \"CustomLabel\"]\n" //
|
||||
+ " value = -1 Negative\n" //
|
||||
+ " value = 0 No Score\n" //
|
||||
+ " value = 1 Positive\n" //
|
||||
+ " defaultValue = -2\n")) //
|
||||
));
|
||||
|
||||
ProjectConfig cfg = read(rev);
|
||||
assertEquals(1, cfg.getValidationErrors().size());
|
||||
assertEquals("project.config: Invalid defaultValue \"-2\" "
|
||||
+ "for label \"CustomLabel\"",
|
||||
Iterables.getOnlyElement(cfg.getValidationErrors()).getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEditConfig() throws Exception {
|
||||
RevCommit rev = util.commit(util.tree( //
|
||||
|
@@ -129,6 +129,7 @@ public class SchemaCreatorTest {
|
||||
assertNotNull(codeReview);
|
||||
assertEquals("Code-Review", codeReview.getName());
|
||||
assertEquals("CR", codeReview.getAbbreviation());
|
||||
assertEquals(0, codeReview.getDefaultValue());
|
||||
assertEquals("MaxWithBlock", codeReview.getFunctionName());
|
||||
assertTrue(codeReview.isCopyMinScore());
|
||||
assertValueRange(codeReview, 2, 1, 0, -1, -2);
|
||||
|
Reference in New Issue
Block a user