use of com.google.gerrit.entities.Address in project gerrit by GerritCodeReview.
the class AbstractDaemonTest method assertNotifyCc.
protected void assertNotifyCc(String expectedEmail, String expectedFullname) {
Address expectedAddress = Address.create(expectedFullname, expectedEmail);
assertNotifyCc(expectedAddress);
}
use of com.google.gerrit.entities.Address in project gerrit by GerritCodeReview.
the class AbstractDaemonTest method assertNotifyTo.
protected void assertNotifyTo(String expectedEmail, String expectedFullname) {
Address expectedAddress = Address.create(expectedFullname, expectedEmail);
assertThat(sender.getMessages()).hasSize(1);
Message m = sender.getMessages().get(0);
assertThat(m.rcpt()).containsExactly(expectedAddress);
assertThat(((EmailHeader.AddressList) m.headers().get("To")).getAddressList()).containsExactly(expectedAddress);
assertThat(m.headers().get("Cc").isEmpty()).isTrue();
}
use of com.google.gerrit.entities.Address in project gerrit by GerritCodeReview.
the class AddReviewersOp method updateChange.
@Override
public boolean updateChange(ChangeContext ctx) throws RestApiException, IOException {
change = ctx.getChange();
if (!accountIds.isEmpty()) {
if (state == CC) {
addedCCs = approvalsUtil.addCcs(ctx.getNotes(), ctx.getUpdate(change.currentPatchSetId()), accountIds, forGroup);
} else {
addedReviewers = approvalsUtil.addReviewers(ctx.getNotes(), ctx.getUpdate(change.currentPatchSetId()), projectCache.get(change.getProject()).orElseThrow(illegalState(change.getProject())).getLabelTypes(change.getDest()), change, accountIds);
}
}
ReviewerStateInternal internalState = ReviewerStateInternal.fromReviewerState(state);
// TODO(dborowitz): This behavior should live in ApprovalsUtil or something, like addCcs does.
ImmutableSet<Address> existing = ctx.getNotes().getReviewersByEmail().byState(internalState);
ImmutableList<Address> addressesToAdd = addresses.stream().filter(a -> !existing.contains(a)).collect(toImmutableList());
if (state == CC) {
addedCCsByEmail = addressesToAdd;
} else {
addedReviewersByEmail = addressesToAdd;
}
for (Address a : addressesToAdd) {
ctx.getUpdate(change.currentPatchSetId()).putReviewerByEmail(a, internalState);
}
if (addedCCs.isEmpty() && addedReviewers.isEmpty() && addressesToAdd.isEmpty()) {
return false;
}
checkAdded();
if (patchSet == null) {
patchSet = requireNonNull(psUtil.current(ctx.getNotes()));
}
return true;
}
use of com.google.gerrit.entities.Address in project gerrit by GerritCodeReview.
the class ChangeNotesTest method putReviewerByEmailAndChangeToCc.
@Test
public void putReviewerByEmailAndChangeToCc() throws Exception {
Address adr = Address.create("Foo Bar", "foo.bar@gerritcodereview.com");
Change c = newChange();
ChangeUpdate update = newUpdate(c, changeOwner);
update.putReviewerByEmail(adr, ReviewerStateInternal.REVIEWER);
update.commit();
update = newUpdate(c, changeOwner);
update.putReviewerByEmail(adr, ReviewerStateInternal.CC);
update.commit();
ChangeNotes notes = newNotes(c);
assertThat(notes.getReviewersByEmail().byState(ReviewerStateInternal.REVIEWER)).isEmpty();
assertThat(notes.getReviewersByEmail().byState(ReviewerStateInternal.CC)).containsExactly(adr);
assertThat(notes.getReviewersByEmail().all()).containsExactly(adr);
}
use of com.google.gerrit.entities.Address in project gerrit by GerritCodeReview.
the class ChangeNotesTest method putReviewerByEmail.
@Test
public void putReviewerByEmail() throws Exception {
Address adr = Address.create("Foo Bar", "foo.bar@gerritcodereview.com");
Change c = newChange();
ChangeUpdate update = newUpdate(c, changeOwner);
update.putReviewerByEmail(adr, ReviewerStateInternal.REVIEWER);
update.commit();
ChangeNotes notes = newNotes(c);
assertThat(notes.getReviewersByEmail().all()).containsExactly(adr);
}
Aggregations