Merge "Send newchange email to reviewers when review is started"

This commit is contained in:
Dave Borowitz
2018-04-09 15:47:05 +00:00
committed by Gerrit Code Review
3 changed files with 44 additions and 7 deletions

View File

@@ -372,7 +372,10 @@ public class PostReview
reviewerResult.gatherResults(); reviewerResult.gatherResults();
} }
emailReviewers(revision.getChange(), reviewerResults, reviewerNotify, accountsToNotify); boolean readyForReview =
(output.ready != null && output.ready) || !revision.getChange().isWorkInProgress();
emailReviewers(
revision.getChange(), reviewerResults, reviewerNotify, accountsToNotify, readyForReview);
} }
return Response.ok(output); return Response.ok(output);
@@ -405,7 +408,8 @@ public class PostReview
Change change, Change change,
List<PostReviewers.Addition> reviewerAdditions, List<PostReviewers.Addition> reviewerAdditions,
@Nullable NotifyHandling notify, @Nullable NotifyHandling notify,
ListMultimap<RecipientType, Account.Id> accountsToNotify) { ListMultimap<RecipientType, Account.Id> accountsToNotify,
boolean readyForReview) {
List<Account.Id> to = new ArrayList<>(); List<Account.Id> to = new ArrayList<>();
List<Account.Id> cc = new ArrayList<>(); List<Account.Id> cc = new ArrayList<>();
List<Address> toByEmail = new ArrayList<>(); List<Address> toByEmail = new ArrayList<>();
@@ -423,7 +427,8 @@ public class PostReview
reviewerAdditions reviewerAdditions
.get(0) .get(0)
.op .op
.emailReviewers(change, to, cc, toByEmail, ccByEmail, notify, accountsToNotify); .emailReviewers(
change, to, cc, toByEmail, ccByEmail, notify, accountsToNotify, readyForReview);
} }
} }

View File

@@ -202,7 +202,8 @@ public class PostReviewersOp implements BatchUpdateOp {
reviewersByEmail, reviewersByEmail,
addedCCsByEmail, addedCCsByEmail,
notify, notify,
accountsToNotify); accountsToNotify,
!rsrc.getChange().isWorkInProgress());
if (!addedReviewers.isEmpty()) { if (!addedReviewers.isEmpty()) {
List<AccountState> reviewers = List<AccountState> reviewers =
addedReviewers addedReviewers
@@ -221,7 +222,8 @@ public class PostReviewersOp implements BatchUpdateOp {
Collection<Address> addedByEmail, Collection<Address> addedByEmail,
Collection<Address> copiedByEmail, Collection<Address> copiedByEmail,
NotifyHandling notify, NotifyHandling notify,
ListMultimap<RecipientType, Account.Id> accountsToNotify) { ListMultimap<RecipientType, Account.Id> accountsToNotify,
boolean readyForReview) {
if (added.isEmpty() && copied.isEmpty() && addedByEmail.isEmpty() && copiedByEmail.isEmpty()) { if (added.isEmpty() && copied.isEmpty() && addedByEmail.isEmpty() && copiedByEmail.isEmpty()) {
return; return;
} }
@@ -250,7 +252,7 @@ public class PostReviewersOp implements BatchUpdateOp {
AddReviewerSender cm = addReviewerSenderFactory.create(change.getProject(), change.getId()); AddReviewerSender cm = addReviewerSenderFactory.create(change.getProject(), change.getId());
// Default to silent operation on WIP changes. // Default to silent operation on WIP changes.
NotifyHandling defaultNotifyHandling = NotifyHandling defaultNotifyHandling =
change.isWorkInProgress() ? NotifyHandling.NONE : NotifyHandling.ALL; readyForReview ? NotifyHandling.ALL : NotifyHandling.NONE;
cm.setNotify(MoreObjects.firstNonNull(notify, defaultNotifyHandling)); cm.setNotify(MoreObjects.firstNonNull(notify, defaultNotifyHandling));
cm.setAccountsToNotify(accountsToNotify); cm.setAccountsToNotify(accountsToNotify);
cm.setFrom(userId); cm.setFrom(userId);

View File

@@ -866,7 +866,8 @@ public class ChangeNotificationsIT extends AbstractNotificationTest {
} }
@Test @Test
public void addReviewerOnWipChangeAndStartReview() throws Exception { public void addReviewerOnWipChangeAndStartReviewInNoteDb() throws Exception {
assume().that(notesMigration.readChanges()).isTrue();
StagedChange sc = stageWipChange(); StagedChange sc = stageWipChange();
ReviewInput in = ReviewInput.noScore().reviewer(other.email).setWorkInProgress(false); ReviewInput in = ReviewInput.noScore().reviewer(other.email).setWorkInProgress(false);
gApi.changes().id(sc.changeId).revision("current").review(in); gApi.changes().id(sc.changeId).revision("current").review(in);
@@ -877,6 +878,35 @@ public class ChangeNotificationsIT extends AbstractNotificationTest {
.bcc(sc.starrer) .bcc(sc.starrer)
.bcc(ALL_COMMENTS) .bcc(ALL_COMMENTS)
.noOneElse(); .noOneElse();
// TODO(logan): Should CCs be included?
assertThat(sender)
.sent("newchange", sc)
.to(other)
.cc(sc.reviewer)
.cc(sc.reviewerByEmail, sc.ccerByEmail)
.noOneElse();
assertThat(sender).notSent();
}
@Test
public void addReviewerOnWipChangeAndStartReviewInReviewDb() throws Exception {
assume().that(notesMigration.readChanges()).isFalse();
StagedChange sc = stageWipChange();
ReviewInput in = ReviewInput.noScore().reviewer(other.email).setWorkInProgress(false);
gApi.changes().id(sc.changeId).revision("current").review(in);
assertThat(sender)
.sent("comment", sc)
.cc(sc.reviewer, sc.ccer, other)
.cc(sc.reviewerByEmail, sc.ccerByEmail)
.bcc(sc.starrer)
.bcc(ALL_COMMENTS)
.noOneElse();
assertThat(sender)
.sent("newchange", sc)
.to(other)
.cc(sc.reviewer, sc.ccer)
.cc(sc.reviewerByEmail, sc.ccerByEmail)
.noOneElse();
assertThat(sender).notSent(); assertThat(sender).notSent();
} }