Send event and execute hooks when topic is changed

When the topic is changed via the web UI or the REST API, send
an event to the event stream and execute a hook.

Bug: Issue 1992
Change-Id: Iba55469d50762478478eb07d9e2d8b0222ee3fd5
This commit is contained in:
David Pursehouse
2013-07-12 14:48:51 +09:00
parent 68ba072e48
commit ba3e28d29d
8 changed files with 96 additions and 2 deletions

View File

@@ -44,6 +44,7 @@ import com.google.gerrit.server.events.MergeFailedEvent;
import com.google.gerrit.server.events.PatchSetCreatedEvent;
import com.google.gerrit.server.events.RefUpdatedEvent;
import com.google.gerrit.server.events.ReviewerAddedEvent;
import com.google.gerrit.server.events.TopicChangedEvent;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.git.WorkQueue;
import com.google.gerrit.server.project.ProjectCache;
@@ -186,6 +187,9 @@ public class ChangeHookRunner implements ChangeHooks, LifecycleListener {
/** Filename of the reviewer added hook. */
private final File reviewerAddedHook;
/** Filename of the topic changed hook. */
private final File topicChangedHook;
/** Filename of the cla signed hook. */
private final File claSignedHook;
@@ -254,6 +258,7 @@ public class ChangeHookRunner implements ChangeHooks, LifecycleListener {
changeRestoredHook = sitePath.resolve(new File(hooksPath, getValue(config, "hooks", "changeRestoredHook", "change-restored")).getPath());
refUpdatedHook = sitePath.resolve(new File(hooksPath, getValue(config, "hooks", "refUpdatedHook", "ref-updated")).getPath());
reviewerAddedHook = sitePath.resolve(new File(hooksPath, getValue(config, "hooks", "reviewerAddedHook", "reviewer-added")).getPath());
topicChangedHook = sitePath.resolve(new File(hooksPath, getValue(config, "hooks", "topicChangedHook", "topic-changed")).getPath());
claSignedHook = sitePath.resolve(new File(hooksPath, getValue(config, "hooks", "claSignedHook", "cla-signed")).getPath());
refUpdateHook = sitePath.resolve(new File(hooksPath, getValue(config, "hooks", "refUpdateHook", "ref-update")).getPath());
syncHookTimeout = config.getInt("hooks", "syncHookTimeout", 30);
@@ -560,6 +565,25 @@ public class ChangeHookRunner implements ChangeHooks, LifecycleListener {
runHook(change.getProject(), reviewerAddedHook, args);
}
public void doTopicChangedHook(final Change change, final Account account,
final String oldTopic, final ReviewDb db)
throws OrmException {
final TopicChangedEvent event = new TopicChangedEvent();
event.change = eventFactory.asChangeAttribute(change);
event.changer = eventFactory.asAccountAttribute(account);
event.oldTopic = oldTopic;
fireEvent(change, event, db);
final List<String> args = new ArrayList<String>();
addArg(args, "--change", event.change.id);
addArg(args, "--changer", getDisplayName(account));
addArg(args, "--old-topic", oldTopic);
addArg(args, "--new-topic", event.change.topic);
runHook(change.getProject(), topicChangedHook, args);
}
public void doClaSignupHook(Account account, ContributorAgreement cla) {
if (account != null) {
final List<String> args = new ArrayList<String>();

View File

@@ -147,6 +147,16 @@ public interface ChangeHooks {
public void doReviewerAddedHook(Change change, Account account,
PatchSet patchSet, ReviewDb db) throws OrmException;
/**
* Fire the Topic Changed Hook
*
* @param change The change itself.
* @param account The gerrit user who changed the topic.
* @param oldTopic The old topic name.
*/
public void doTopicChangedHook(Change change, Account account,
String oldTopic, ReviewDb db) throws OrmException;
public void doClaSignupHook(Account account, ContributorAgreement cla);
/**

View File

@@ -90,6 +90,11 @@ public final class DisabledChangeHooks implements ChangeHooks {
ReviewDb db) {
}
@Override
public void doTopicChangedHook(Change change, Account account, String oldTopic,
ReviewDb db) {
}
@Override
public void removeChangeListener(ChangeListener listener) {
}