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
This commit is contained in:
@@ -58,6 +58,13 @@ The `CommentFooter.vm` template will determine the contents of the footer
|
||||
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
|
||||
~~~~~~~~~
|
||||
|
||||
|
@@ -26,6 +26,7 @@ import com.google.gerrit.server.GerritPersonIdent;
|
||||
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 @@ class EditCommitMessageHandler extends Handler<ChangeDetail> {
|
||||
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 @@ class EditCommitMessageHandler extends Handler<ChangeDetail> {
|
||||
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 @@ class EditCommitMessageHandler extends Handler<ChangeDetail> {
|
||||
this.db = db;
|
||||
this.currentUser = currentUser;
|
||||
this.changeDetailFactory = changeDetailFactory;
|
||||
this.commitMessageEditedSenderFactory = commitMessageEditedSenderFactory;
|
||||
|
||||
this.patchSetId = patchSetId;
|
||||
this.message = message;
|
||||
@@ -105,7 +110,8 @@ class EditCommitMessageHandler extends Handler<ChangeDetail> {
|
||||
}
|
||||
|
||||
ChangeUtil.editCommitMessage(patchSetId, currentUser, message, db,
|
||||
hooks, gitManager, patchSetInfoFactory, replication, myIdent);
|
||||
commitMessageEditedSenderFactory, hooks, gitManager, patchSetInfoFactory,
|
||||
replication, myIdent);
|
||||
|
||||
return changeDetailFactory.create(changeId).call();
|
||||
}
|
||||
|
@@ -90,6 +90,7 @@ public class SitePathInitializer {
|
||||
extractMailExample("ChangeSubject.vm");
|
||||
extractMailExample("Comment.vm");
|
||||
extractMailExample("CommentFooter.vm");
|
||||
extractMailExample("CommitMessageEdited.vm");
|
||||
extractMailExample("Merged.vm");
|
||||
extractMailExample("MergeFail.vm");
|
||||
extractMailExample("NewChange.vm");
|
||||
|
@@ -29,6 +29,7 @@ import com.google.gerrit.server.config.TrackingFooters;
|
||||
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 class ChangeUtil {
|
||||
|
||||
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 @@ public class ChangeUtil {
|
||||
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();
|
||||
}
|
||||
|
@@ -36,6 +36,7 @@ import com.google.gerrit.server.git.MetaDataUpdate;
|
||||
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 @@ public class GerritRequestModule extends FactoryModule {
|
||||
//
|
||||
factory(AddReviewer.Factory.class);
|
||||
factory(AddReviewerSender.Factory.class);
|
||||
factory(CommitMessageEditedSender.Factory.class);
|
||||
factory(CreateChangeSender.Factory.class);
|
||||
factory(DeleteDraftPatchSet.Factory.class);
|
||||
factory(PublishDraft.Factory.class);
|
||||
|
@@ -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"));
|
||||
}
|
||||
}
|
@@ -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
|
Reference in New Issue
Block a user