use of com.google.gerrit.entities.Address in project gerrit by GerritCodeReview.
the class ChangeIT method ignore.
@Test
public void ignore() throws Exception {
String email = "user2@example.com";
String fullname = "User2";
accountOperations.newAccount().username("user2").preferredEmail(email).fullname(fullname).create();
PushOneCommit.Result r = createChange();
ReviewerInput in = new ReviewerInput();
in.reviewer = user.email();
gApi.changes().id(r.getChangeId()).addReviewer(in);
in = new ReviewerInput();
in.reviewer = email;
gApi.changes().id(r.getChangeId()).addReviewer(in);
requestScopeOperations.setApiUser(user.id());
gApi.changes().id(r.getChangeId()).ignore(true);
assertThat(gApi.changes().id(r.getChangeId()).ignored()).isTrue();
// New patch set notification is not sent to users ignoring the change
sender.clear();
requestScopeOperations.setApiUser(admin.id());
amendChange(r.getChangeId());
List<Message> messages = sender.getMessages();
assertThat(messages).hasSize(1);
Address address = Address.create(fullname, email);
assertThat(messages.get(0).rcpt()).containsExactly(address);
// Review notification is not sent to users ignoring the change
sender.clear();
gApi.changes().id(r.getChangeId()).current().review(ReviewInput.approve());
messages = sender.getMessages();
assertThat(messages).hasSize(1);
assertThat(messages.get(0).rcpt()).containsExactly(address);
// Abandoned notification is not sent to users ignoring the change
sender.clear();
gApi.changes().id(r.getChangeId()).abandon();
messages = sender.getMessages();
assertThat(messages).hasSize(1);
assertThat(messages.get(0).rcpt()).containsExactly(address);
requestScopeOperations.setApiUser(user.id());
gApi.changes().id(r.getChangeId()).ignore(false);
assertThat(gApi.changes().id(r.getChangeId()).ignored()).isFalse();
}
use of com.google.gerrit.entities.Address in project gerrit by GerritCodeReview.
the class ModifyReviewersEmail method emailReviewersAsync.
public void emailReviewersAsync(IdentifiedUser user, Change change, Collection<Account.Id> added, Collection<Account.Id> copied, Collection<Account.Id> removed, Collection<Address> addedByEmail, Collection<Address> copiedByEmail, Collection<Address> removedByEmail, NotifyResolver.Result notify) {
// The user knows they added/removed themselves, don't bother emailing them.
Account.Id userId = user.getAccountId();
ImmutableList<Account.Id> immutableToMail = added.stream().filter(id -> !id.equals(userId)).collect(toImmutableList());
ImmutableList<Account.Id> immutableToCopy = copied.stream().filter(id -> !id.equals(userId)).collect(toImmutableList());
ImmutableList<Account.Id> immutableToRemove = removed.stream().filter(id -> !id.equals(userId)).collect(toImmutableList());
if (immutableToMail.isEmpty() && immutableToCopy.isEmpty() && immutableToRemove.isEmpty() && addedByEmail.isEmpty() && copiedByEmail.isEmpty() && removedByEmail.isEmpty()) {
return;
}
// Make immutable copies of collections and hand over only immutable data types to the other
// thread.
Change.Id cId = change.getId();
Project.NameKey projectNameKey = change.getProject();
ImmutableList<Address> immutableAddedByEmail = ImmutableList.copyOf(addedByEmail);
ImmutableList<Address> immutableCopiedByEmail = ImmutableList.copyOf(copiedByEmail);
ImmutableList<Address> immutableRemovedByEmail = ImmutableList.copyOf(removedByEmail);
@SuppressWarnings("unused") Future<?> possiblyIgnoredError = sendEmailsExecutor.submit(() -> {
try {
ModifyReviewerSender emailSender = addReviewerSenderFactory.create(projectNameKey, cId);
emailSender.setNotify(notify);
emailSender.setFrom(userId);
emailSender.addReviewers(immutableToMail);
emailSender.addReviewersByEmail(immutableAddedByEmail);
emailSender.addExtraCC(immutableToCopy);
emailSender.addExtraCCByEmail(immutableCopiedByEmail);
emailSender.addRemovedReviewers(immutableToRemove);
emailSender.addRemovedByEmailReviewers(immutableRemovedByEmail);
emailSender.setMessageId(messageIdGenerator.fromChangeUpdate(change.getProject(), change.currentPatchSetId()));
emailSender.send();
} catch (Exception err) {
logger.atSevere().withCause(err).log("Cannot send email to new reviewers of change %s", change.getId());
}
});
}
use of com.google.gerrit.entities.Address in project gerrit by GerritCodeReview.
the class ReviewerJson method format.
public List<ReviewerInfo> format(Collection<ReviewerResource> rsrcs) throws PermissionBackendException {
List<ReviewerInfo> infos = Lists.newArrayListWithCapacity(rsrcs.size());
AccountLoader loader = accountLoaderFactory.create(true);
ChangeData cd = null;
for (ReviewerResource rsrc : rsrcs) {
if (cd == null || !cd.getId().equals(rsrc.getChangeId())) {
cd = changeDataFactory.create(rsrc.getChangeResource().getNotes());
}
ReviewerInfo info;
if (rsrc.isByEmail()) {
Address address = rsrc.getReviewerByEmail();
info = ReviewerInfo.byEmail(address.name(), address.email());
} else {
Account.Id reviewerAccountId = rsrc.getReviewerUser().getAccountId();
info = format(new ReviewerInfo(reviewerAccountId.get()), reviewerAccountId, cd);
loader.put(info);
}
infos.add(info);
}
loader.fill();
return infos;
}
use of com.google.gerrit.entities.Address in project gerrit by GerritCodeReview.
the class ChangeField method parseReviewerByEmailFieldValues.
public static ReviewerByEmailSet parseReviewerByEmailFieldValues(Change.Id changeId, Iterable<String> values) {
ImmutableTable.Builder<ReviewerStateInternal, Address, Instant> b = ImmutableTable.builder();
for (String v : values) {
int i = v.indexOf(',');
if (i < 0) {
logger.atWarning().log("Invalid value for reviewer by email field from change %s: %s", changeId.get(), v);
continue;
}
int i2 = v.lastIndexOf(',');
if (i2 == i) {
// and the "<reviewer-type>,<email>" value is ignored here.
continue;
}
Optional<ReviewerStateInternal> reviewerState = getReviewerState(v.substring(0, i));
if (!reviewerState.isPresent()) {
logger.atWarning().log("Failed to parse reviewer state of reviewer by email field from change %s: %s", changeId.get(), v);
continue;
}
Address address = Address.tryParse(v.substring(i + 1, i2));
if (address == null) {
logger.atWarning().log("Failed to parse address of reviewer by email field from change %s: %s", changeId.get(), v);
continue;
}
Long l = Longs.tryParse(v.substring(i2 + 1));
if (l == null) {
logger.atWarning().log("Failed to parse timestamp of reviewer by email field from change %s: %s", changeId.get(), v);
continue;
}
Instant timestamp = Instant.ofEpochMilli(l);
b.put(reviewerState.get(), address, timestamp);
}
return ReviewerByEmailSet.fromTable(b.build());
}
use of com.google.gerrit.entities.Address in project gerrit by GerritCodeReview.
the class ProjectConfig method saveNotifySections.
private void saveNotifySections(Config rc, Set<AccountGroup.UUID> keepGroups) {
unsetSection(rc, NOTIFY);
for (NotifyConfig nc : sort(notifySections.values())) {
nc.getGroups().stream().map(GroupReference::getUUID).filter(Objects::nonNull).forEach(keepGroups::add);
List<String> email = nc.getGroups().stream().map(gr -> PermissionRule.create(gr).asString(false)).sorted().collect(toList());
// Separate stream operation so that emails list contains 2 sorted sub-lists.
nc.getAddresses().stream().map(Address::toString).sorted().forEach(email::add);
set(rc, NOTIFY, nc.getName(), KEY_HEADER, nc.getHeader(), NotifyConfig.Header.BCC);
if (email.isEmpty()) {
rc.unset(NOTIFY, nc.getName(), KEY_EMAIL);
} else {
rc.setStringList(NOTIFY, nc.getName(), KEY_EMAIL, email);
}
if (nc.getNotify().equals(Sets.immutableEnumSet(NotifyType.ALL))) {
rc.unset(NOTIFY, nc.getName(), KEY_TYPE);
} else {
List<String> types = new ArrayList<>(4);
for (NotifyType t : NotifyType.values()) {
if (nc.isNotify(t)) {
types.add(t.name().toLowerCase(Locale.US));
}
}
rc.setStringList(NOTIFY, nc.getName(), KEY_TYPE, types);
}
set(rc, NOTIFY, nc.getName(), KEY_FILTER, nc.getFilter());
}
}
Aggregations