Merge "Add config to remove emails for new patchsets"

This commit is contained in:
Gal Paikin
2020-08-26 15:25:58 +00:00
committed by Gerrit Code Review
5 changed files with 62 additions and 5 deletions

View File

@@ -1400,6 +1400,14 @@ supported. Zero or negative values allow robot comments of unlimited size.
+
The default limit is 1MiB.
[[change.sendNewPatchsetEmails]]change.sendNewPatchsetEmails::
+
When false, emails will not be sent to owners, reviewers, and cc for
creating a new patchset unless they are project watchers or have starred
the change.
+
Default is true.
[[change.showAssigneeInChangesTable]]change.showAssigneeInChangesTable::
+
Show assignee field in changes table. If set to false, assignees will

View File

@@ -1387,6 +1387,7 @@ public abstract class AbstractDaemonTest {
pwi.filter = filter;
pwi.notifyAbandonedChanges = true;
pwi.notifyNewChanges = true;
pwi.notifyNewPatchSets = true;
pwi.notifyAllComments = true;
});
}

View File

@@ -37,6 +37,7 @@ public class EmailSettings {
public final String password;
public final Encryption encryption;
public final long fetchInterval; // in milliseconds
public final boolean sendNewPatchsetEmails;
@Inject
EmailSettings(@GerritServerConfig Config cfg) {
@@ -58,5 +59,6 @@ public class EmailSettings {
"fetchInterval",
TimeUnit.MILLISECONDS.convert(60, TimeUnit.SECONDS),
TimeUnit.MILLISECONDS);
sendNewPatchsetEmails = cfg.getBoolean("change", null, "sendNewPatchsetEmails", true);
}
}

View File

@@ -61,12 +61,14 @@ public class ReplacePatchSetSender extends ReplyToChangeSender {
//
reviewers.remove(fromId);
}
if (notify.handling() == NotifyHandling.ALL
|| notify.handling() == NotifyHandling.OWNER_REVIEWERS) {
add(RecipientType.TO, reviewers);
add(RecipientType.CC, extraCC);
if (args.settings.sendNewPatchsetEmails) {
if (notify.handling() == NotifyHandling.ALL
|| notify.handling() == NotifyHandling.OWNER_REVIEWERS) {
add(RecipientType.TO, reviewers);
add(RecipientType.CC, extraCC);
}
rcptToAuthors(RecipientType.CC);
}
rcptToAuthors(RecipientType.CC);
bccStarredBy();
includeWatchers(NotifyType.NEW_PATCHSETS, !change.isWorkInProgress() && !change.isPrivate());
removeUsersThatIgnoredTheChange();

View File

@@ -96,6 +96,7 @@ import com.google.gerrit.extensions.webui.PatchSetWebLink;
import com.google.gerrit.server.change.RevisionResource;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gerrit.server.restapi.change.GetRevisionActions;
import com.google.gerrit.testing.FakeEmailSender;
import com.google.inject.Inject;
import java.io.ByteArrayOutputStream;
import java.sql.Timestamp;
@@ -1899,6 +1900,49 @@ public class RevisionIT extends AbstractDaemonTest {
assertThat(result.getChange().reviewers().all()).isEmpty();
}
@Test
public void notificationsOnPushNewPatchset() throws Exception {
PushOneCommit.Result r = createChange();
change(r).addReviewer(user.email());
sender.clear();
// check that reviewer is notified.
amendChange(r.getChangeId());
List<FakeEmailSender.Message> messages = sender.getMessages();
FakeEmailSender.Message m = Iterables.getOnlyElement(messages);
assertThat(m.rcpt()).containsExactly(user.getNameEmail());
assertThat(m.body()).contains("I'd like you to reexamine a change.");
}
@Test
@GerritConfig(name = "change.sendNewPatchsetEmails", value = "false")
public void notificationsOnPushNewPatchsetNotSentWithSendNewPatchsetEmailsAsFalse()
throws Exception {
PushOneCommit.Result r = createChange();
change(r).addReviewer(user.email());
sender.clear();
// check that reviewer is not notified
amendChange(r.getChangeId());
assertThat(sender.getMessages()).isEmpty();
}
@Test
@GerritConfig(name = "change.sendNewPatchsetEmails", value = "false")
public void notificationsOnPushNewPatchsetAlwaysSentToProjectWatchers() throws Exception {
PushOneCommit.Result r = createChange();
requestScopeOperations.setApiUser(user.id());
watch(project.get());
sender.clear();
// check that watcher is notified
amendChange(r.getChangeId());
List<FakeEmailSender.Message> messages = sender.getMessages();
FakeEmailSender.Message m = Iterables.getOnlyElement(messages);
assertThat(m.rcpt()).containsExactly(user.getNameEmail());
assertThat(m.body()).contains(admin.fullName() + " has uploaded a new patch set (#2).");
}
private static void assertCherryPickResult(
ChangeInfo changeInfo, CherryPickInput input, String srcChangeId) throws Exception {
assertThat(changeInfo.changeId).isEqualTo(srcChangeId);