Send email notification when commit message is edited
When a user edits the commit message through the Gerrit web UI,
send a notification email.
Change-Id: I6f2d840f362d82af25960fb4f1891eee040de9a6
diff --git a/Documentation/config-mail.txt b/Documentation/config-mail.txt
index fc7060d..8de8e59 100644
--- a/Documentation/config-mail.txt
+++ b/Documentation/config-mail.txt
@@ -58,6 +58,13 @@
text that will be appended to emails related to a user submitting comments on
changes. See `ChangeSubject.vm`, `Comment.vm` and `ChangeFooter.vm`.
+CommitMessageEdited.vm
+~~~~~~~~~~~~~~~~~~~~~~
+
+The `CommitMessageEdited.vm` template will determine the contents of the email
+related to a user editing the commit message through the Gerrit UI. It is a
+`ChangeEmail`: see `ChangeSubject.vm` and `ChangeFooter.vm`.
+
Merged.vm
~~~~~~~~~
diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/EditCommitMessageHandler.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/EditCommitMessageHandler.java
index c2baa6e..c3e5d4f 100644
--- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/EditCommitMessageHandler.java
+++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/EditCommitMessageHandler.java
@@ -26,6 +26,7 @@
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.extensions.events.GitReferenceUpdated;
import com.google.gerrit.server.git.GitRepositoryManager;
+import com.google.gerrit.server.mail.CommitMessageEditedSender;
import com.google.gerrit.server.mail.EmailException;
import com.google.gerrit.server.patch.PatchSetInfoFactory;
import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException;
@@ -53,6 +54,8 @@
private final ReviewDb db;
private final IdentifiedUser currentUser;
private final ChangeDetailFactory.Factory changeDetailFactory;
+ private final CommitMessageEditedSender.Factory commitMessageEditedSenderFactory;
+
private final GitReferenceUpdated replication;
private final PatchSet.Id patchSetId;
@@ -70,6 +73,7 @@
EditCommitMessageHandler(final ChangeControl.Factory changeControlFactory,
final ReviewDb db, final IdentifiedUser currentUser,
final ChangeDetailFactory.Factory changeDetailFactory,
+ final CommitMessageEditedSender.Factory commitMessageEditedSenderFactory,
@Assisted final PatchSet.Id patchSetId,
@Assisted @Nullable final String message, final ChangeHooks hooks,
final GitRepositoryManager gitManager,
@@ -80,6 +84,7 @@
this.db = db;
this.currentUser = currentUser;
this.changeDetailFactory = changeDetailFactory;
+ this.commitMessageEditedSenderFactory = commitMessageEditedSenderFactory;
this.patchSetId = patchSetId;
this.message = message;
@@ -105,7 +110,8 @@
}
ChangeUtil.editCommitMessage(patchSetId, currentUser, message, db,
- hooks, gitManager, patchSetInfoFactory, replication, myIdent);
+ commitMessageEditedSenderFactory, hooks, gitManager, patchSetInfoFactory,
+ replication, myIdent);
return changeDetailFactory.create(changeId).call();
}
diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/SitePathInitializer.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/SitePathInitializer.java
index ca3bf84..bf0af7f 100644
--- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/SitePathInitializer.java
+++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/SitePathInitializer.java
@@ -90,6 +90,7 @@
extractMailExample("ChangeSubject.vm");
extractMailExample("Comment.vm");
extractMailExample("CommentFooter.vm");
+ extractMailExample("CommitMessageEdited.vm");
extractMailExample("Merged.vm");
extractMailExample("MergeFail.vm");
extractMailExample("NewChange.vm");
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/ChangeUtil.java b/gerrit-server/src/main/java/com/google/gerrit/server/ChangeUtil.java
index 4658edf..fda2907 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/ChangeUtil.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/ChangeUtil.java
@@ -29,6 +29,7 @@
import com.google.gerrit.server.extensions.events.GitReferenceUpdated;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.git.MergeOp;
+import com.google.gerrit.server.mail.CommitMessageEditedSender;
import com.google.gerrit.server.mail.EmailException;
import com.google.gerrit.server.mail.RevertedSender;
import com.google.gerrit.server.patch.PatchSetInfoFactory;
@@ -305,6 +306,7 @@
public static Change.Id editCommitMessage(final PatchSet.Id patchSetId,
final IdentifiedUser user, final String message, final ReviewDb db,
+ final CommitMessageEditedSender.Factory commitMessageEditedSenderFactory,
final ChangeHooks hooks, GitRepositoryManager gitManager,
final PatchSetInfoFactory patchSetInfoFactory,
final GitReferenceUpdated replication, PersonIdent myIdent)
@@ -426,6 +428,11 @@
cmsg.setMessage(msg);
db.changeMessages().insert(Collections.singleton(cmsg));
db.commit();
+
+ final CommitMessageEditedSender cm = commitMessageEditedSenderFactory.create(change);
+ cm.setFrom(user.getAccountId());
+ cm.setChangeMessage(cmsg);
+ cm.send();
} finally {
db.rollback();
}
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/config/GerritRequestModule.java b/gerrit-server/src/main/java/com/google/gerrit/server/config/GerritRequestModule.java
index f30259d..2a2bdcf 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/config/GerritRequestModule.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/config/GerritRequestModule.java
@@ -36,6 +36,7 @@
import com.google.gerrit.server.git.NotesBranchUtil;
import com.google.gerrit.server.git.SubmoduleOp;
import com.google.gerrit.server.mail.AddReviewerSender;
+import com.google.gerrit.server.mail.CommitMessageEditedSender;
import com.google.gerrit.server.mail.CreateChangeSender;
import com.google.gerrit.server.mail.MergeFailSender;
import com.google.gerrit.server.mail.MergedSender;
@@ -76,6 +77,7 @@
//
factory(AddReviewer.Factory.class);
factory(AddReviewerSender.Factory.class);
+ factory(CommitMessageEditedSender.Factory.class);
factory(CreateChangeSender.Factory.class);
factory(DeleteDraftPatchSet.Factory.class);
factory(PublishDraft.Factory.class);
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/mail/CommitMessageEditedSender.java b/gerrit-server/src/main/java/com/google/gerrit/server/mail/CommitMessageEditedSender.java
new file mode 100644
index 0000000..de3cb65
--- /dev/null
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/mail/CommitMessageEditedSender.java
@@ -0,0 +1,39 @@
+// Copyright (C) 2012 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.gerrit.server.mail;
+
+import com.google.gerrit.reviewdb.client.Change;
+import com.google.gerrit.server.config.AnonymousCowardName;
+import com.google.gerrit.server.ssh.SshInfo;
+import com.google.inject.Inject;
+import com.google.inject.assistedinject.Assisted;
+
+public class CommitMessageEditedSender extends ReplacePatchSetSender {
+ public static interface Factory {
+ CommitMessageEditedSender create(Change change);
+ }
+
+ @Inject
+ public CommitMessageEditedSender(EmailArguments ea,
+ @AnonymousCowardName String anonymousCowardName, SshInfo si,
+ @Assisted Change c) {
+ super(ea, anonymousCowardName, si, c);
+ }
+
+ @Override
+ protected void formatChange() throws EmailException {
+ appendText(velocifyFile("CommitMessageEdited.vm"));
+ }
+}
diff --git a/gerrit-server/src/main/resources/com/google/gerrit/server/mail/CommitMessageEdited.vm b/gerrit-server/src/main/resources/com/google/gerrit/server/mail/CommitMessageEdited.vm
new file mode 100644
index 0000000..f583101
--- /dev/null
+++ b/gerrit-server/src/main/resources/com/google/gerrit/server/mail/CommitMessageEdited.vm
@@ -0,0 +1,54 @@
+## Copyright (C) 2012 The Android Open Source Project
+##
+## Licensed under the Apache License, Version 2.0 (the "License");
+## you may not use this file except in compliance with the License.
+## You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+##
+##
+## Template Type:
+## -------------
+## This is a velocity mail template, see: http://velocity.apache.org and the
+## gerrit-docs:config-mail.txt for more info on modifying gerrit mail templates.
+##
+## Template File Names and extensions:
+## ----------------------------------
+## Gerrit will use templates ending in ".vm" but will ignore templates ending
+## in ".vm.example". If a .vm template does not exist, the default internal
+## gerrit template which is the same as the .vm.example will be used. If you
+## want to override the default template, copy the .vm.example file to a .vm
+## file and edit it appropriately.
+##
+## This Template:
+## --------------
+## The CommitMessageUpdated.vm template will determine the contents of the email
+## related to a user editing the commit message for a change through the Gerrit UI.
+## It is a ChangeEmail: see ChangeSubject.vm and ChangeFooter.vm.
+##
+#if($email.reviewerNames)
+Hello $email.joinStrings($email.reviewerNames, ', '),
+
+I'd like you to reexamine a change.#if($email.changeUrl) Please visit
+
+ $email.changeUrl
+
+to look at the new patch set with edited commit message (#$patchSet.patchSetId).
+#end
+#else
+$fromName has created a new patch set by editing the commit message in Gerrit (#$patchSet.patchSetId).
+#end
+
+Change subject: $change.subject
+......................................................................
+
+$email.changeDetail
+#if($email.sshHost)
+ git pull ssh://$email.sshHost/$projectName $patchSet.refName
+#end