use of com.google.gerrit.extensions.client.ReviewerState.REVIEWER in project gerrit by GerritCodeReview.
the class ChangeIT method pendingReviewers.
@Test
public void pendingReviewers() throws Exception {
ConfigInput conf = new ConfigInput();
conf.enableReviewerByEmail = InheritableBoolean.TRUE;
gApi.projects().name(project.get()).config(conf);
PushOneCommit.Result r = createWorkInProgressChange();
String changeId = r.getChangeId();
assertThat(gApi.changes().id(changeId).get().pendingReviewers).isEmpty();
// Add some pending reviewers.
String email1 = name("user1") + "@example.com";
String email2 = name("user2") + "@example.com";
String email3 = name("user3") + "@example.com";
String email4 = name("user4") + "@example.com";
accountOperations.newAccount().username(name("user1")).preferredEmail(email1).fullname("User1").create();
accountOperations.newAccount().username(name("user2")).preferredEmail(email2).fullname("User2").create();
accountOperations.newAccount().username(name("user3")).preferredEmail(email3).fullname("User3").create();
accountOperations.newAccount().username(name("user4")).preferredEmail(email4).fullname("User4").create();
ReviewInput in = ReviewInput.noScore().reviewer(email1).reviewer(email2).reviewer(email3, CC, false).reviewer(email4, CC, false).reviewer("byemail1@example.com").reviewer("byemail2@example.com").reviewer("byemail3@example.com", CC, false).reviewer("byemail4@example.com", CC, false);
ReviewResult result = gApi.changes().id(changeId).current().review(in);
assertThat(result.reviewers).isNotEmpty();
ChangeInfo info = gApi.changes().id(changeId).get();
Function<Collection<AccountInfo>, Collection<String>> toEmails = ais -> ais.stream().map(ai -> ai.email).collect(toSet());
assertThat(toEmails.apply(info.pendingReviewers.get(REVIEWER))).containsExactly(email1, email2, "byemail1@example.com", "byemail2@example.com");
assertThat(toEmails.apply(info.pendingReviewers.get(CC))).containsExactly(email3, email4, "byemail3@example.com", "byemail4@example.com");
assertThat(info.pendingReviewers.get(REMOVED)).isNull();
// Stage some pending reviewer removals.
gApi.changes().id(changeId).reviewer(email1).remove();
gApi.changes().id(changeId).reviewer(email3).remove();
gApi.changes().id(changeId).reviewer("byemail1@example.com").remove();
gApi.changes().id(changeId).reviewer("byemail3@example.com").remove();
info = gApi.changes().id(changeId).get();
assertThat(toEmails.apply(info.pendingReviewers.get(REVIEWER))).containsExactly(email2, "byemail2@example.com");
assertThat(toEmails.apply(info.pendingReviewers.get(CC))).containsExactly(email4, "byemail4@example.com");
assertThat(toEmails.apply(info.pendingReviewers.get(REMOVED))).containsExactly(email1, email3, "byemail1@example.com", "byemail3@example.com");
// "Undo" a removal.
in = ReviewInput.noScore().reviewer(email1);
gApi.changes().id(changeId).current().review(in);
info = gApi.changes().id(changeId).get();
assertThat(toEmails.apply(info.pendingReviewers.get(REVIEWER))).containsExactly(email1, email2, "byemail2@example.com");
assertThat(toEmails.apply(info.pendingReviewers.get(CC))).containsExactly(email4, "byemail4@example.com");
assertThat(toEmails.apply(info.pendingReviewers.get(REMOVED))).containsExactly(email3, "byemail1@example.com", "byemail3@example.com");
// "Commit" by moving out of WIP.
gApi.changes().id(changeId).setReadyForReview();
info = gApi.changes().id(changeId).get();
assertThat(info.pendingReviewers).isEmpty();
assertThat(toEmails.apply(info.reviewers.get(REVIEWER))).containsExactly(email1, email2, "byemail2@example.com");
assertThat(toEmails.apply(info.reviewers.get(CC))).containsExactly(email4, "byemail4@example.com");
assertThat(info.reviewers.get(REMOVED)).isNull();
}
use of com.google.gerrit.extensions.client.ReviewerState.REVIEWER in project gerrit by GerritCodeReview.
the class ChangeIT method implicitlyAddReviewerOnVotingReview.
@Test
public void implicitlyAddReviewerOnVotingReview() throws Exception {
PushOneCommit.Result r = createChange();
requestScopeOperations.setApiUser(user.id());
gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).review(ReviewInput.recommend().message("LGTM"));
ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
assertThat(c.reviewers.get(REVIEWER).stream().map(ai -> ai._accountId).collect(toList())).containsExactly(user.id().get());
// Further test: remove the vote, then comment again. The user should be
// implicitly re-added to the ReviewerSet, as a CC.
requestScopeOperations.setApiUser(admin.id());
gApi.changes().id(r.getChangeId()).reviewer(user.id().toString()).remove();
c = gApi.changes().id(r.getChangeId()).get();
assertThat(c.reviewers.values()).isEmpty();
requestScopeOperations.setApiUser(user.id());
gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).review(new ReviewInput().message("hi"));
c = gApi.changes().id(r.getChangeId()).get();
assertThat(c.reviewers.get(CC).stream().map(ai -> ai._accountId).collect(toList())).containsExactly(user.id().get());
}
use of com.google.gerrit.extensions.client.ReviewerState.REVIEWER in project gerrit by GerritCodeReview.
the class ChangeIT method reviewAndSetWorkInProgressAndAddReviewerAndVote.
@Test
public void reviewAndSetWorkInProgressAndAddReviewerAndVote() throws Exception {
PushOneCommit.Result r = createChange();
assertThat(r.getChange().change().isWorkInProgress()).isFalse();
ReviewInput in = ReviewInput.approve().reviewer(user.email()).label(LabelId.CODE_REVIEW, 1).setWorkInProgress(true);
gApi.changes().id(r.getChangeId()).current().review(in);
ChangeInfo info = gApi.changes().id(r.getChangeId()).get();
assertThat(info.workInProgress).isTrue();
assertThat(info.reviewers.get(REVIEWER).stream().map(ai -> ai._accountId).collect(toList())).containsExactly(admin.id().get(), user.id().get());
assertThat(info.labels.get(LabelId.CODE_REVIEW).recommended._accountId).isEqualTo(admin.id().get());
}
Aggregations