use of com.google.gerrit.extensions.api.changes.ReviewerResult in project gerrit by GerritCodeReview.
the class ChangeIT method addReviewerThatIsInactiveById.
@Test
public void addReviewerThatIsInactiveById() throws Exception {
PushOneCommit.Result result = createChange();
String username = name("new-user");
Account.Id id = accountOperations.newAccount().username(username).inactive().create();
ReviewerInput in = new ReviewerInput();
in.reviewer = Integer.toString(id.get());
ReviewerResult r = gApi.changes().id(result.getChangeId()).addReviewer(in);
assertThat(r.input).isEqualTo(in.reviewer);
assertThat(r.error).isNull();
assertThat(r.reviewers).hasSize(1);
ReviewerInfo reviewer = r.reviewers.get(0);
assertThat(reviewer._accountId).isEqualTo(id.get());
assertThat(reviewer.username).isEqualTo(username);
}
use of com.google.gerrit.extensions.api.changes.ReviewerResult in project gerrit by GerritCodeReview.
the class ChangeIT method addReviewerThatCannotSeeChange.
@Test
public void addReviewerThatCannotSeeChange() throws Exception {
// create hidden project that is only visible to administrators
Project.NameKey p = projectOperations.newProject().create();
projectOperations.project(p).forUpdate().add(allow(Permission.READ).ref("refs/*").group(adminGroupUuid())).add(block(Permission.READ).ref("refs/*").group(REGISTERED_USERS)).update();
// create change
TestRepository<InMemoryRepository> repo = cloneProject(p, admin);
PushOneCommit push = pushFactory.create(admin.newIdent(), repo);
PushOneCommit.Result result = push.to("refs/for/master");
result.assertOkStatus();
// check the user cannot see the change
requestScopeOperations.setApiUser(user.id());
assertThrows(ResourceNotFoundException.class, () -> gApi.changes().id(result.getChangeId()).get());
// try to add user as reviewer
requestScopeOperations.setApiUser(admin.id());
ReviewerInput in = new ReviewerInput();
in.reviewer = user.email();
ReviewerResult r = gApi.changes().id(result.getChangeId()).addReviewer(in);
assertThat(r.input).isEqualTo(user.email());
assertThat(r.error).contains("does not have permission to see this change");
assertThat(r.reviewers).isNull();
}
use of com.google.gerrit.extensions.api.changes.ReviewerResult in project gerrit by GerritCodeReview.
the class ChangeReviewersIT method addExistingCcShortCircuits.
@Test
public void addExistingCcShortCircuits() throws Exception {
PushOneCommit.Result r = createChange();
ReviewerInput input = new ReviewerInput();
input.reviewer = user.email();
input.state = ReviewerState.CC;
ReviewerResult result = gApi.changes().id(r.getChangeId()).addReviewer(input);
assertThat(result.ccs).hasSize(1);
AccountInfo info = result.ccs.get(0);
assertThat(info._accountId).isEqualTo(user.id().get());
assertThat(gApi.changes().id(r.getChangeId()).addReviewer(input).ccs).isEmpty();
}
use of com.google.gerrit.extensions.api.changes.ReviewerResult in project gerrit by GerritCodeReview.
the class ChangeReviewersIT method reviewAndAddGroupReviewers.
@Test
public void reviewAndAddGroupReviewers() throws Exception {
int largeGroupSize = ReviewerModifier.DEFAULT_MAX_REVIEWERS + 1;
int mediumGroupSize = ReviewerModifier.DEFAULT_MAX_REVIEWERS_WITHOUT_CHECK + 1;
List<TestAccount> users = createAccounts(largeGroupSize, "reviewAndAddGroupReviewers");
List<String> usernames = new ArrayList<>(largeGroupSize);
for (TestAccount u : users) {
usernames.add(u.username());
}
String largeGroup = groupOperations.newGroup().name("largeGroup").create().get();
String mediumGroup = groupOperations.newGroup().name("mediumGroup").create().get();
gApi.groups().id(largeGroup).addMembers(usernames.toArray(new String[largeGroupSize]));
gApi.groups().id(mediumGroup).addMembers(usernames.subList(0, mediumGroupSize).toArray(new String[mediumGroupSize]));
TestAccount observer = accountCreator.user2();
PushOneCommit.Result r = createChange();
// Attempt to add overly large group as reviewers.
ReviewInput input = ReviewInput.approve().reviewer(user.email()).reviewer(observer.email(), CC, false).reviewer(largeGroup);
ReviewResult result = review(r.getChangeId(), r.getCommit().name(), input, SC_BAD_REQUEST);
assertThat(result.labels).isNull();
assertThat(result.reviewers).isNotNull();
assertThat(result.reviewers).hasSize(3);
ReviewerResult reviewerResult = result.reviewers.get(largeGroup);
assertThat(reviewerResult).isNotNull();
assertThat(reviewerResult.confirm).isNull();
assertThat(reviewerResult.error).isNotNull();
assertThat(reviewerResult.error).contains("has too many members to add them all as reviewers");
// No labels should have changed, and no reviewers/CCs should have been added.
ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
assertThat(c.messages).hasSize(1);
assertThat(c.reviewers.get(REVIEWER)).isNull();
assertThat(c.reviewers.get(CC)).isNull();
// Attempt to add group large enough to require confirmation, without
// confirmation, as reviewers.
input = ReviewInput.approve().reviewer(user.email()).reviewer(observer.email(), CC, false).reviewer(mediumGroup);
result = review(r.getChangeId(), r.getCommit().name(), input, SC_BAD_REQUEST);
assertThat(result.labels).isNull();
assertThat(result.reviewers).isNotNull();
assertThat(result.reviewers).hasSize(3);
reviewerResult = result.reviewers.get(mediumGroup);
assertThat(reviewerResult).isNotNull();
assertThat(reviewerResult.confirm).isTrue();
assertThat(reviewerResult.error).contains("has " + mediumGroupSize + " members. Do you want to add them all as reviewers?");
// No labels should have changed, and no reviewers/CCs should have been added.
c = gApi.changes().id(r.getChangeId()).get();
assertThat(c.messages).hasSize(1);
assertThat(c.reviewers.get(REVIEWER)).isNull();
assertThat(c.reviewers.get(CC)).isNull();
// Retrying with confirmation should successfully approve and add reviewers/CCs.
input = ReviewInput.approve().reviewer(user.email()).reviewer(mediumGroup, CC, true);
result = review(r.getChangeId(), r.getCommit().name(), input);
assertThat(result.labels).isNotNull();
assertThat(result.reviewers).isNotNull();
assertThat(result.reviewers).hasSize(2);
c = gApi.changes().id(r.getChangeId()).get();
assertThat(c.messages).hasSize(2);
assertReviewers(c, REVIEWER, admin, user);
assertReviewers(c, CC, users.subList(0, mediumGroupSize));
}
use of com.google.gerrit.extensions.api.changes.ReviewerResult in project gerrit by GerritCodeReview.
the class ChangeReviewersIT method addExistingReviewerShortCircuits.
@Test
public void addExistingReviewerShortCircuits() throws Exception {
PushOneCommit.Result r = createChange();
ReviewerInput input = new ReviewerInput();
input.reviewer = user.email();
input.state = ReviewerState.REVIEWER;
ReviewerResult result = gApi.changes().id(r.getChangeId()).addReviewer(input);
assertThat(result.reviewers).hasSize(1);
ReviewerInfo info = result.reviewers.get(0);
assertThat(info._accountId).isEqualTo(user.id().get());
assertThat(gApi.changes().id(r.getChangeId()).addReviewer(input).reviewers).isEmpty();
}
Aggregations