use of com.google.gerrit.extensions.common.LabelInfo in project gerrit by GerritCodeReview.
the class DraftChangeIT method listApprovalsOnDraftChange.
@Test
public void listApprovalsOnDraftChange() throws Exception {
assume().that(isAllowDrafts()).isTrue();
PushOneCommit.Result result = createDraftChange();
result.assertOkStatus();
String changeId = result.getChangeId();
String triplet = project.get() + "~master~" + changeId;
gApi.changes().id(triplet).addReviewer(user.fullName);
ChangeInfo info = get(triplet);
LabelInfo label = info.labels.get("Code-Review");
assertThat(label.all).hasSize(1);
assertThat(label.all.get(0)._accountId).isEqualTo(user.id.get());
assertThat(label.all.get(0).value).isEqualTo(0);
Collection<AccountInfo> ccs = info.reviewers.get(ReviewerState.REVIEWER);
assertThat(ccs).hasSize(1);
assertThat(ccs.iterator().next()._accountId).isEqualTo(user.id.get());
setApiUser(user);
gApi.changes().id(triplet).current().review(ReviewInput.recommend());
setApiUser(admin);
label = get(triplet).labels.get("Code-Review");
assertThat(label.all).hasSize(1);
assertThat(label.all.get(0)._accountId).isEqualTo(user.id.get());
assertThat(label.all.get(0).value).isEqualTo(1);
}
use of com.google.gerrit.extensions.common.LabelInfo in project gerrit by GerritCodeReview.
the class ChangeIT method testRebase.
private void testRebase(Rebase rebase) throws Exception {
// Create two changes both with the same parent
PushOneCommit.Result r = createChange();
testRepo.reset("HEAD~1");
PushOneCommit.Result r2 = createChange();
// Approve and submit the first change
RevisionApi revision = gApi.changes().id(r.getChangeId()).current();
revision.review(ReviewInput.approve());
revision.submit();
// Add an approval whose score should be copied on trivial rebase
gApi.changes().id(r2.getChangeId()).current().review(ReviewInput.recommend());
String changeId = r2.getChangeId();
// Rebase the second change
rebase.call(changeId);
// Second change should have 2 patch sets and an approval
ChangeInfo c2 = gApi.changes().id(changeId).get(CURRENT_REVISION, DETAILED_LABELS);
assertThat(c2.revisions.get(c2.currentRevision)._number).isEqualTo(2);
// ...and the committer and description should be correct
ChangeInfo info = gApi.changes().id(changeId).get(CURRENT_REVISION, CURRENT_COMMIT);
GitPerson committer = info.revisions.get(info.currentRevision).commit.committer;
assertThat(committer.name).isEqualTo(admin.fullName());
assertThat(committer.email).isEqualTo(admin.email());
String description = info.revisions.get(info.currentRevision).description;
assertThat(description).isEqualTo("Rebase");
// ...and the approval was copied
LabelInfo cr = c2.labels.get(LabelId.CODE_REVIEW);
assertThat(cr).isNotNull();
assertThat(cr.all).hasSize(1);
assertThat(cr.all.get(0).value).isEqualTo(1);
// Rebasing the second change again should fail
ResourceConflictException thrown = assertThrows(ResourceConflictException.class, () -> gApi.changes().id(changeId).current().rebase());
assertThat(thrown).hasMessageThat().contains("Change is already up to date");
}
use of com.google.gerrit.extensions.common.LabelInfo in project gerrit by GerritCodeReview.
the class ChangeReviewersIT method removingReviewerRemovesTheirVote.
@Test
public void removingReviewerRemovesTheirVote() throws Exception {
String crLabel = LabelId.CODE_REVIEW;
PushOneCommit.Result r = createChange();
ReviewInput input = ReviewInput.approve().reviewer(admin.email());
ReviewResult addResult = review(r.getChangeId(), r.getCommit().name(), input);
assertThat(addResult.reviewers).isNotNull();
assertThat(addResult.reviewers).hasSize(1);
Map<String, LabelInfo> changeLabels = getChangeLabels(r.getChangeId());
assertThat(changeLabels.get(crLabel).all).hasSize(1);
RestResponse deleteResult = deleteReviewer(r.getChangeId(), admin);
deleteResult.assertNoContent();
changeLabels = getChangeLabels(r.getChangeId());
assertThat(changeLabels.get(crLabel).all).isNull();
// Check that the vote is gone even after the reviewer is added back
addReviewer(r.getChangeId(), admin.email());
changeLabels = getChangeLabels(r.getChangeId());
assertThat(changeLabels.get(crLabel).all).isNull();
}
use of com.google.gerrit.extensions.common.LabelInfo in project gerrit by GerritCodeReview.
the class ChangeIT method votable.
@Test
public void votable() throws Exception {
PushOneCommit.Result r = createChange();
String triplet = project.get() + "~master~" + r.getChangeId();
gApi.changes().id(triplet).addReviewer(user.username());
ChangeInfo c = gApi.changes().id(triplet).get(DETAILED_LABELS);
LabelInfo codeReview = c.labels.get(LabelId.CODE_REVIEW);
assertThat(codeReview.all).hasSize(1);
ApprovalInfo approval = codeReview.all.get(0);
assertThat(approval._accountId).isEqualTo(user.id().get());
assertThat(approval.value).isEqualTo(0);
projectOperations.project(project).forUpdate().add(blockLabel(LabelId.CODE_REVIEW).ref("refs/heads/*").group(REGISTERED_USERS).range(-1, 1)).update();
c = gApi.changes().id(triplet).get(DETAILED_LABELS);
codeReview = c.labels.get(LabelId.CODE_REVIEW);
assertThat(codeReview.all).hasSize(1);
approval = codeReview.all.get(0);
assertThat(approval._accountId).isEqualTo(user.id().get());
assertThat(approval.value).isNull();
}
use of com.google.gerrit.extensions.common.LabelInfo in project gerrit by GerritCodeReview.
the class AbstractPushForReview method pushWithMultipleApprovals.
@Test
public void pushWithMultipleApprovals() throws Exception {
LabelType Q = label("Custom-Label", value(1, "Positive"), value(0, "No score"), value(-1, "Negative"));
String heads = "refs/heads/*";
try (ProjectConfigUpdate u = updateProject(project)) {
u.getConfig().upsertLabelType(Q);
u.save();
}
projectOperations.project(project).forUpdate().add(allowLabel("Custom-Label").ref(heads).group(ANONYMOUS_USERS).range(-1, 1)).update();
RevCommit c = commitBuilder().author(admin.newIdent()).committer(admin.newIdent()).add(PushOneCommit.FILE_NAME, PushOneCommit.FILE_CONTENT).message(PushOneCommit.SUBJECT).create();
pushHead(testRepo, "refs/for/master%l=Code-Review+1,l=Custom-Label-1", false);
ChangeInfo ci = get(GitUtil.getChangeId(testRepo, c).get(), DETAILED_LABELS, DETAILED_ACCOUNTS);
LabelInfo cr = ci.labels.get("Code-Review");
assertThat(cr.all).hasSize(1);
cr = ci.labels.get("Custom-Label");
assertThat(cr.all).hasSize(1);
// Check that the user who pushed the change was added as a reviewer since they added a vote
assertThatUserIsOnlyReviewer(ci, admin);
}
Aggregations