use of com.google.gerrit.extensions.api.changes.AddReviewerInput in project gerrit by GerritCodeReview.
the class QueryIT method allReviewersOptionJSON.
@Test
public void allReviewersOptionJSON() throws Exception {
String changeId = createChange().getChangeId();
AddReviewerInput in = new AddReviewerInput();
in.reviewer = user.email;
gApi.changes().id(changeId).addReviewer(in);
List<ChangeAttribute> changes = executeSuccessfulQuery(changeId);
assertThat(changes.size()).isEqualTo(1);
assertThat(changes.get(0).allReviewers).isNull();
changes = executeSuccessfulQuery("--all-reviewers " + changeId);
assertThat(changes.size()).isEqualTo(1);
assertThat(changes.get(0).allReviewers).isNotNull();
assertThat(changes.get(0).allReviewers.size()).isEqualTo(1);
}
use of com.google.gerrit.extensions.api.changes.AddReviewerInput in project gerrit by GerritCodeReview.
the class ChangeApiImpl method addReviewer.
@Override
public AddReviewerResult addReviewer(String reviewer) throws RestApiException {
AddReviewerInput in = new AddReviewerInput();
in.reviewer = reviewer;
return addReviewer(in);
}
use of com.google.gerrit.extensions.api.changes.AddReviewerInput in project gerrit by GerritCodeReview.
the class AbstractQueryChangesTest method reviewerAndCcByEmail.
@Test
public void reviewerAndCcByEmail() throws Exception {
assume().that(notesMigration.enabled()).isTrue();
Project.NameKey project = new Project.NameKey("repo");
TestRepository<Repo> repo = createProject(project.get());
ConfigInput conf = new ConfigInput();
conf.enableReviewerByEmail = InheritableBoolean.TRUE;
gApi.projects().name(project.get()).config(conf);
String userByEmail = "un.registered@reviewer.com";
String userByEmailWithName = "John Doe <" + userByEmail + ">";
Change change1 = insert(repo, newChange(repo));
Change change2 = insert(repo, newChange(repo));
insert(repo, newChange(repo));
AddReviewerInput rin = new AddReviewerInput();
rin.reviewer = userByEmailWithName;
rin.state = ReviewerState.REVIEWER;
gApi.changes().id(change1.getId().get()).addReviewer(rin);
rin = new AddReviewerInput();
rin.reviewer = userByEmailWithName;
rin.state = ReviewerState.CC;
gApi.changes().id(change2.getId().get()).addReviewer(rin);
if (getSchemaVersion() >= 41) {
assertQuery("reviewer:\"" + userByEmailWithName + "\"", change1);
assertQuery("cc:\"" + userByEmailWithName + "\"", change2);
// Omitting the name:
assertQuery("reviewer:\"" + userByEmail + "\"", change1);
assertQuery("cc:\"" + userByEmail + "\"", change2);
} else {
assertMissingField(ChangeField.REVIEWER_BY_EMAIL);
assertFailingQuery("reviewer:\"" + userByEmailWithName + "\"", "User " + userByEmailWithName + " not found");
assertFailingQuery("cc:\"" + userByEmailWithName + "\"", "User " + userByEmailWithName + " not found");
// Omitting the name:
assertFailingQuery("reviewer:\"" + userByEmail + "\"", "User " + userByEmail + " not found");
assertFailingQuery("cc:\"" + userByEmail + "\"", "User " + userByEmail + " not found");
}
}
use of com.google.gerrit.extensions.api.changes.AddReviewerInput in project gerrit by GerritCodeReview.
the class ChangeIT method addSelfAsReviewer.
@Test
public void addSelfAsReviewer() throws Exception {
TestTimeUtil.resetWithClockStep(1, SECONDS);
PushOneCommit.Result r = createChange();
ChangeResource rsrc = parseResource(r);
String oldETag = rsrc.getETag();
Timestamp oldTs = rsrc.getChange().getLastUpdatedOn();
AddReviewerInput in = new AddReviewerInput();
in.reviewer = user.email;
setApiUser(user);
gApi.changes().id(r.getChangeId()).addReviewer(in);
// There should be no email notification when adding self
assertThat(sender.getMessages()).isEmpty();
// When NoteDb is enabled adding a reviewer records that user as reviewer
// in NoteDb. When NoteDb is disabled adding a reviewer results in a dummy 0
// approval on the change which is treated as CC when the ChangeInfo is
// created.
ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
Collection<AccountInfo> reviewers = c.reviewers.get(REVIEWER);
assertThat(reviewers).isNotNull();
assertThat(reviewers).hasSize(1);
assertThat(reviewers.iterator().next()._accountId).isEqualTo(user.getId().get());
// Ensure ETag and lastUpdatedOn are updated.
rsrc = parseResource(r);
assertThat(rsrc.getETag()).isNotEqualTo(oldETag);
assertThat(rsrc.getChange().getLastUpdatedOn()).isNotEqualTo(oldTs);
}
use of com.google.gerrit.extensions.api.changes.AddReviewerInput in project gerrit by GerritCodeReview.
the class ChangeIT method addReviewerThatIsInactiveEmailFallback.
@Test
public void addReviewerThatIsInactiveEmailFallback() throws Exception {
assume().that(notesMigration.enabled()).isTrue();
ConfigInput conf = new ConfigInput();
conf.enableReviewerByEmail = InheritableBoolean.TRUE;
gApi.projects().name(project.get()).config(conf);
PushOneCommit.Result result = createChange();
String username = "user@domain.com";
gApi.accounts().create(username).setActive(false);
AddReviewerInput in = new AddReviewerInput();
in.reviewer = username;
in.state = ReviewerState.CC;
AddReviewerResult r = gApi.changes().id(result.getChangeId()).addReviewer(in);
assertThat(r.input).isEqualTo(username);
assertThat(r.error).isNull();
// When adding by email, the reviewers field is also empty because we can't
// render a ReviewerInfo object for a non-account.
assertThat(r.reviewers).isNull();
}
Aggregations