use of com.google.gerrit.entities.SubmitRecord in project gerrit by GerritCodeReview.
the class SubmitRequirementsAdapterTest method defaultSubmitRule_withLabelStatusNeed_labelHasIgnoreSelfApproval.
@Test
public void defaultSubmitRule_withLabelStatusNeed_labelHasIgnoreSelfApproval() throws Exception {
SubmitRecord submitRecord = createSubmitRecord(DefaultSubmitRule.RULE_NAME, Status.NOT_READY, Arrays.asList(createLabel("ISA-Label", Label.Status.NEED)));
List<SubmitRequirementResult> requirements = SubmitRequirementsAdapter.createResult(submitRecord, labelTypes, psCommitId, /* isForced= */
false);
assertThat(requirements).hasSize(1);
assertResult(requirements.get(0), /* reqName= */
"ISA-Label", /* submitExpression= */
"label:ISA-Label=MAX,user=non_uploader -label:ISA-Label=MIN", SubmitRequirementResult.Status.UNSATISFIED, SubmitRequirementExpressionResult.Status.FAIL);
}
use of com.google.gerrit.entities.SubmitRecord in project gerrit by GerritCodeReview.
the class SubmitRequirementsAdapterTest method defaultSubmitRule_withLabelStatusOk_labelHasIgnoreSelfApproval.
@Test
public void defaultSubmitRule_withLabelStatusOk_labelHasIgnoreSelfApproval() throws Exception {
SubmitRecord submitRecord = createSubmitRecord(DefaultSubmitRule.RULE_NAME, Status.OK, Arrays.asList(createLabel("ISA-Label", Label.Status.OK)));
List<SubmitRequirementResult> requirements = SubmitRequirementsAdapter.createResult(submitRecord, labelTypes, psCommitId, /* isForced= */
false);
assertThat(requirements).hasSize(1);
assertResult(requirements.get(0), /* reqName= */
"ISA-Label", /* submitExpression= */
"label:ISA-Label=MAX,user=non_uploader -label:ISA-Label=MIN", SubmitRequirementResult.Status.SATISFIED, SubmitRequirementExpressionResult.Status.PASS);
}
use of com.google.gerrit.entities.SubmitRecord in project gerrit by GerritCodeReview.
the class LabelsJson method initLabels.
private Map<String, LabelWithStatus> initLabels(AccountLoader accountLoader, ChangeData cd, LabelTypes labelTypes, boolean standard) {
Map<String, LabelWithStatus> labels = new TreeMap<>(labelTypes.nameComparator());
for (SubmitRecord rec : submitRecords(cd)) {
if (rec.labels == null) {
continue;
}
for (SubmitRecord.Label r : rec.labels) {
LabelWithStatus p = labels.get(r.label);
if (p == null || p.status().compareTo(r.status) < 0) {
LabelInfo n = new LabelInfo();
if (standard) {
switch(r.status) {
case OK:
n.approved = accountLoader.get(r.appliedBy);
break;
case REJECT:
n.rejected = accountLoader.get(r.appliedBy);
n.blocking = true;
break;
case IMPOSSIBLE:
case MAY:
case NEED:
default:
break;
}
}
n.optional = r.status == SubmitRecord.Label.Status.MAY ? true : null;
labels.put(r.label, LabelWithStatus.create(n, r.status));
}
}
}
setLabelsDescription(labels, labelTypes);
return labels;
}
use of com.google.gerrit.entities.SubmitRecord in project gerrit by GerritCodeReview.
the class ReviewerJson method format.
public ReviewerInfo format(ReviewerInfo out, Account.Id reviewerAccountId, ChangeData cd, Iterable<PatchSetApproval> approvals) throws PermissionBackendException {
LabelTypes labelTypes = cd.getLabelTypes();
out.approvals = new TreeMap<>(labelTypes.nameComparator());
for (PatchSetApproval ca : approvals) {
Optional<LabelType> at = labelTypes.byLabel(ca.labelId());
at.ifPresent(lt -> out.approvals.put(lt.getName(), formatValue(ca.value())));
}
// Add dummy approvals for all permitted labels for the user even if they
// do not exist in the DB.
PatchSet ps = cd.currentPatchSet();
if (ps != null) {
PermissionBackend.ForChange perm = permissionBackend.absentUser(reviewerAccountId).change(cd);
for (SubmitRecord rec : cd.submitRecords(SubmitRuleOptions.defaults())) {
if (rec.labels == null) {
continue;
}
for (SubmitRecord.Label label : rec.labels) {
String name = label.label;
Optional<LabelType> type = labelTypes.byLabel(name);
if (out.approvals.containsKey(name) || !type.isPresent()) {
continue;
}
if (perm.test(new LabelPermission(type.get()))) {
out.approvals.put(name, formatValue((short) 0));
}
}
}
}
if (out.approvals.isEmpty()) {
out.approvals = null;
}
return out;
}
use of com.google.gerrit.entities.SubmitRecord in project gerrit by GerritCodeReview.
the class ChangeField method formatSubmitRecordValues.
@VisibleForTesting
static List<String> formatSubmitRecordValues(List<SubmitRecord> records, Account.Id changeOwner) {
List<String> result = new ArrayList<>();
for (SubmitRecord rec : records) {
result.add(rec.status.name());
if (rec.labels == null) {
continue;
}
for (SubmitRecord.Label label : rec.labels) {
String sl = label.status.toString() + ',' + label.label.toLowerCase();
result.add(sl);
String slc = sl + ',';
if (label.appliedBy != null) {
result.add(slc + label.appliedBy.get());
if (label.appliedBy.equals(changeOwner)) {
result.add(slc + ChangeQueryBuilder.OWNER_ACCOUNT_ID.get());
}
}
}
}
return result;
}
Aggregations