use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class MergedSender method format.
private String format(String type, Table<Account.Id, String, PatchSetApproval> approvals) {
StringBuilder txt = new StringBuilder();
if (approvals.isEmpty()) {
return "";
}
txt.append(type).append(":\n");
for (Account.Id id : approvals.rowKeySet()) {
txt.append(" ");
txt.append(getNameFor(id));
txt.append(": ");
boolean first = true;
for (LabelType lt : labelTypes.getLabelTypes()) {
PatchSetApproval ca = approvals.get(id, lt.getName());
if (ca == null) {
continue;
}
if (first) {
first = false;
} else {
txt.append("; ");
}
LabelValue v = lt.getValue(ca);
if (v != null) {
txt.append(v.getText());
} else {
txt.append(lt.getName());
txt.append('=');
txt.append(LabelValue.formatValue(ca.value()));
}
}
txt.append('\n');
}
txt.append('\n');
return txt.toString();
}
use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class PRED__load_commit_labels_1 method exec.
@Override
public Operation exec(Prolog engine) throws PrologException {
engine.setB0();
Term a1 = arg1.dereference();
Term listHead = Prolog.Nil;
ChangeData cd = StoredValues.CHANGE_DATA.get(engine);
LabelTypes types = cd.getLabelTypes();
for (PatchSetApproval a : cd.currentApprovals()) {
Optional<LabelType> t = types.byLabel(a.labelId());
if (!t.isPresent()) {
continue;
}
StructureTerm labelTerm = new StructureTerm(sym_label, SymbolTerm.intern(t.get().getName()), new IntegerTerm(a.value()));
StructureTerm userTerm = new StructureTerm(sym_user, new IntegerTerm(a.accountId().get()));
listHead = new ListTerm(new StructureTerm(sym_commit_label, labelTerm, userTerm), listHead);
}
if (!a1.unify(listHead, engine.trail)) {
return engine.fail();
}
return cont;
}
use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class EqualsLabelPredicate method match.
@Override
public boolean match(ChangeData object) {
Change c = object.change();
if (c == null) {
//
return false;
}
if (Integer.valueOf(0).equals(count)) {
// is computationally expensive.
return false;
}
Optional<ProjectState> project = projectCache.get(c.getDest().project());
if (!project.isPresent()) {
//
return false;
}
LabelType labelType = type(project.get().getLabelTypes(), label);
if (labelType == null) {
// Label is not defined by this project.
return false;
}
boolean hasVote = false;
int matchingVotes = 0;
StorageConstraint currentStorageConstraint = object.getStorageConstraint();
object.setStorageConstraint(ChangeData.StorageConstraint.INDEX_PRIMARY_NOTEDB_SECONDARY);
for (PatchSetApproval p : object.currentApprovals()) {
if (labelType.matches(p)) {
hasVote = true;
if (match(object, p.value(), p.accountId())) {
matchingVotes += 1;
}
}
}
object.setStorageConstraint(currentStorageConstraint);
if (!hasVote && expVal == 0) {
return true;
}
return count == null ? matchingVotes >= 1 : matchingVotes == count;
}
use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class StickyApprovalsIT method stickyVoteStoredCanBeRemoved.
@Test
public void stickyVoteStoredCanBeRemoved() throws Exception {
// Code-Review will be sticky.
String label = LabelId.CODE_REVIEW;
try (ProjectConfigUpdate u = updateProject(project)) {
u.getConfig().updateLabelType(label, b -> b.setCopyAnyScore(true));
u.save();
}
PushOneCommit.Result r = createChange();
// Add a new vote
ReviewInput input = new ReviewInput().label(LabelId.CODE_REVIEW, 2);
gApi.changes().id(r.getChangeId()).current().review(input);
// Make a new patchset, keeping the Code-Review +2 vote.
amendChange(r.getChangeId());
assertVotes(detailedChange(r.getChangeId()), admin, label, 2, null);
gApi.changes().id(r.getChangeId()).current().review(ReviewInput.noScore());
PatchSetApproval nonCopiedSecondPatchsetRemovedVote = Iterables.getOnlyElement(r.getChange().notes().getApprovalsWithCopied().get(r.getChange().change().currentPatchSetId()));
assertThat(nonCopiedSecondPatchsetRemovedVote.patchSetId().get()).isEqualTo(2);
assertThat(nonCopiedSecondPatchsetRemovedVote.accountId().get()).isEqualTo(admin.id().get());
assertThat(nonCopiedSecondPatchsetRemovedVote.label()).isEqualTo(LabelId.CODE_REVIEW);
// The vote got removed since the latest patch-set only has one vote and it's "0".
assertThat(nonCopiedSecondPatchsetRemovedVote.value()).isEqualTo((short) 0);
assertThat(nonCopiedSecondPatchsetRemovedVote.copied()).isFalse();
}
use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class StickyApprovalsIT method stickyVoteStoredOnUploadWithRealAccountAndTag.
@Test
public void stickyVoteStoredOnUploadWithRealAccountAndTag() throws Exception {
// Give "user" permission to vote on behalf of other users.
projectOperations.project(project).forUpdate().add(allowLabel(TestLabels.codeReview().getName()).impersonation(true).ref("refs/heads/*").group(REGISTERED_USERS).range(-1, 1)).update();
// Code-Review will be sticky.
String label = LabelId.CODE_REVIEW;
try (ProjectConfigUpdate u = updateProject(project)) {
u.getConfig().updateLabelType(label, b -> b.setCopyAnyScore(true));
u.save();
}
PushOneCommit.Result r = createChange();
// Add a new vote as user
requestScopeOperations.setApiUser(user.id());
ReviewInput input = new ReviewInput().label(LabelId.CODE_REVIEW, 1);
input.onBehalfOf = admin.email();
input.tag = "tag";
gApi.changes().id(r.getChangeId()).current().review(input);
// Make a new patchset, keeping the Code-Review +1 vote.
amendChange(r.getChangeId());
List<PatchSetApproval> patchSetApprovals = r.getChange().notes().getApprovalsWithCopied().values().stream().sorted(comparing(a -> a.patchSetId().get())).collect(toImmutableList());
PatchSetApproval nonCopied = patchSetApprovals.get(0);
assertThat(nonCopied.patchSetId().get()).isEqualTo(1);
assertThat(nonCopied.accountId().get()).isEqualTo(admin.id().get());
assertThat(nonCopied.realAccountId().get()).isEqualTo(user.id().get());
assertThat(nonCopied.label()).isEqualTo(LabelId.CODE_REVIEW);
assertThat(nonCopied.value()).isEqualTo((short) 1);
assertThat(nonCopied.tag().get()).isEqualTo("tag");
assertThat(nonCopied.copied()).isFalse();
PatchSetApproval copied = patchSetApprovals.get(1);
assertThat(copied.patchSetId().get()).isEqualTo(2);
assertThat(copied.accountId().get()).isEqualTo(admin.id().get());
assertThat(copied.realAccountId().get()).isEqualTo(user.id().get());
assertThat(copied.label()).isEqualTo(LabelId.CODE_REVIEW);
assertThat(copied.value()).isEqualTo((short) 1);
assertThat(nonCopied.tag().get()).isEqualTo("tag");
assertThat(copied.copied()).isTrue();
}
Aggregations