use of com.google.gerrit.entities.LabelType in project gerrit by GerritCodeReview.
the class SubmitRequirementIT method submitRequirement_returnsEmpty_forAbandonedChangeWithPreviouslyStoredSRs.
@Test
public void submitRequirement_returnsEmpty_forAbandonedChangeWithPreviouslyStoredSRs() throws Exception {
for (SubmitType submitType : SubmitType.values()) {
Project.NameKey project = createProjectForPush(submitType);
TestRepository<InMemoryRepository> repo = cloneProject(project);
configSubmitRequirement(project, SubmitRequirement.builder().setName("Code-Review").setSubmittabilityExpression(SubmitRequirementExpression.maxCodeReview()).setAllowOverrideInChildProjects(false).build());
PushOneCommit.Result r = createChange(repo, "master", "Add a file", "foo", "content", "topic");
String changeId = r.getChangeId();
// Abandon change. Submit requirements get stored in the revision note of patch-set 1.
gApi.changes().id(changeId).abandon();
ChangeInfo change = gApi.changes().id(changeId).get();
assertThat(change.submitRequirements).hasSize(1);
assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.UNSATISFIED, /* isLegacy= */
false);
// Clear SRs for the project and update code-review label to be non-blocking.
clearSubmitRequirements(project);
LabelType cr = TestLabels.codeReview().toBuilder().setFunction(LabelFunction.NO_BLOCK).build();
try (ProjectConfigUpdate u = updateProject(project)) {
u.getConfig().upsertLabelType(cr);
u.save();
}
// Restore the change. No SRs apply.
gApi.changes().id(changeId).restore();
change = gApi.changes().id(changeId).get();
assertThat(change.submitRequirements).isEmpty();
// Abandon the change. Still, no SRs apply.
gApi.changes().id(changeId).abandon();
change = gApi.changes().id(changeId).get();
assertThat(change.submitRequirements).isEmpty();
}
}
use of com.google.gerrit.entities.LabelType in project gerrit by GerritCodeReview.
the class SubmitRequirementIT method submitRequirements_submittedTogetherWithoutLegacySubmitRequirements.
@Test
public void submitRequirements_submittedTogetherWithoutLegacySubmitRequirements() throws Exception {
// Add a code review submit requirement and mark the 'Code-Review' label function to be
// non-blocking.
configSubmitRequirement(allProjects, SubmitRequirement.builder().setName("Code-Review").setSubmittabilityExpression(SubmitRequirementExpression.maxCodeReview()).setAllowOverrideInChildProjects(true).build());
LabelType cr = TestLabels.codeReview().toBuilder().setFunction(LabelFunction.NO_BLOCK).build();
try (ProjectConfigUpdate u = updateProject(project)) {
u.getConfig().upsertLabelType(cr);
u.save();
}
// Create two changes in a chain.
createChange();
PushOneCommit.Result r2 = createChange();
// Make sure the CR requirement is unsatisfied.
String changeId = r2.getChangeId();
ChangeInfo change = gApi.changes().id(changeId).get();
assertThat(change.submitRequirements).hasSize(1);
assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.UNSATISFIED, /* isLegacy= */
false);
List<ChangeInfo> changeInfos = gApi.changes().id(changeId).submittedTogether();
assertThat(changeInfos).hasSize(2);
assertThat(changeInfos.stream().map(c -> c.submittable).distinct().collect(MoreCollectors.onlyElement())).isFalse();
}
use of com.google.gerrit.entities.LabelType in project gerrit by GerritCodeReview.
the class ProjectConfigTest method readConfigLabelScores.
@Test
public void readConfigLabelScores() throws Exception {
RevCommit rev = tr.commit().add("groups", group(developers)).add("project.config", "[label \"CustomLabel\"]\n" + LABEL_SCORES_CONFIG).create();
ProjectConfig cfg = read(rev);
Map<String, LabelType> labels = cfg.getLabelSections();
LabelType type = labels.entrySet().iterator().next().getValue();
assertThat(type.isCopyAnyScore()).isNotEqualTo(LabelType.DEF_COPY_ANY_SCORE);
assertThat(type.isCopyMinScore()).isNotEqualTo(LabelType.DEF_COPY_MIN_SCORE);
assertThat(type.isCopyMaxScore()).isNotEqualTo(LabelType.DEF_COPY_MAX_SCORE);
assertThat(type.isCopyAllScoresIfListOfFilesDidNotChange()).isNotEqualTo(LabelType.DEF_COPY_ALL_SCORES_IF_LIST_OF_FILES_DID_NOT_CHANGE);
assertThat(type.isCopyAllScoresOnMergeFirstParentUpdate()).isNotEqualTo(LabelType.DEF_COPY_ALL_SCORES_ON_MERGE_FIRST_PARENT_UPDATE);
assertThat(type.isCopyAllScoresOnTrivialRebase()).isNotEqualTo(LabelType.DEF_COPY_ALL_SCORES_ON_TRIVIAL_REBASE);
assertThat(type.isCopyAllScoresIfNoCodeChange()).isNotEqualTo(LabelType.DEF_COPY_ALL_SCORES_IF_NO_CODE_CHANGE);
assertThat(type.isCopyAllScoresIfNoChange()).isNotEqualTo(LabelType.DEF_COPY_ALL_SCORES_IF_NO_CHANGE);
}
use of com.google.gerrit.entities.LabelType in project gerrit by GerritCodeReview.
the class SubmitRequirementsAdapterTest method setup.
@Before
public void setup() {
LabelType codeReview = LabelType.builder("Code-Review", ImmutableList.of(LabelValue.create((short) 1, "Looks good to me"), LabelValue.create((short) 0, "No score"), LabelValue.create((short) -1, "I would prefer this is not merged as is"))).setFunction(LabelFunction.MAX_WITH_BLOCK).build();
LabelType verified = LabelType.builder("Verified", ImmutableList.of(LabelValue.create((short) 1, "Looks good to me"), LabelValue.create((short) 0, "No score"), LabelValue.create((short) -1, "I would prefer this is not merged as is"))).setFunction(LabelFunction.MAX_NO_BLOCK).build();
LabelType codeStyle = LabelType.builder("Code-Style", ImmutableList.of(LabelValue.create((short) 1, "Looks good to me"), LabelValue.create((short) 0, "No score"), LabelValue.create((short) -1, "I would prefer this is not merged as is"))).setFunction(LabelFunction.ANY_WITH_BLOCK).build();
LabelType ignoreSelfApprovalLabel = LabelType.builder("ISA-Label", ImmutableList.of(LabelValue.create((short) 1, "Looks good to me"), LabelValue.create((short) 0, "No score"), LabelValue.create((short) -1, "I would prefer this is not merged as is"))).setFunction(LabelFunction.MAX_WITH_BLOCK).setIgnoreSelfApproval(true).build();
labelTypes = Arrays.asList(codeReview, verified, codeStyle, ignoreSelfApprovalLabel);
}
use of com.google.gerrit.entities.LabelType in project gerrit by GerritCodeReview.
the class LabelsJson method permittedLabels.
/**
* Returns A map of all label names and the values that the provided user has permission to vote
* on.
*
* @param filterApprovalsBy a Gerrit user ID.
* @param cd {@link ChangeData} corresponding to a specific gerrit change.
* @return A Map where the key contain a label name, and the value is a list of the permissible
* vote values that the user can vote on.
*/
Map<String, Collection<String>> permittedLabels(Account.Id filterApprovalsBy, ChangeData cd) throws PermissionBackendException {
SetMultimap<String, String> permitted = LinkedHashMultimap.create();
boolean isMerged = cd.change().isMerged();
Map<String, Short> currentUserVotes = currentLabels(filterApprovalsBy, cd);
for (LabelType labelType : cd.getLabelTypes().getLabelTypes()) {
if (isMerged && !labelType.isAllowPostSubmit()) {
continue;
}
Set<LabelPermission.WithValue> can = permissionBackend.absentUser(filterApprovalsBy).change(cd).test(labelType);
for (LabelValue v : labelType.getValues()) {
boolean ok = can.contains(new LabelPermission.WithValue(labelType, v));
if (isMerged) {
// Votes cannot be decreased if the change is merged. Only accept the label value if it's
// greater or equal than the user's latest vote.
short prev = currentUserVotes.getOrDefault(labelType.getName(), (short) 0);
ok &= v.getValue() >= prev;
}
if (ok) {
permitted.put(labelType.getName(), v.formatValue());
}
}
}
clearOnlyZerosEntries(permitted);
return permitted.asMap();
}
Aggregations