Send event to stream and execute hook when reviewer is added
When a new reviewer is added on a change, the `reviewer-added` hook is executed, and the `reviewer-added` event is sent to the event stream. This will allow users like automated review bots to monitor the event stream and take action only when they are explicitly added as reviewer on a change. Bug: Issue 1200 Change-Id: I26339360d9e1a5eabb8b6938309d5b411d6cd420
This commit is contained in:
committed by
Gustaf Lundh
parent
320467f829
commit
2336bd8bac
@@ -41,6 +41,7 @@ import com.google.gerrit.server.events.DraftPublishedEvent;
|
||||
import com.google.gerrit.server.events.EventFactory;
|
||||
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.git.GitRepositoryManager;
|
||||
import com.google.gerrit.server.git.WorkQueue;
|
||||
import com.google.gerrit.server.project.ProjectCache;
|
||||
@@ -117,6 +118,9 @@ public class ChangeHookRunner implements ChangeHooks {
|
||||
/** Filename of the ref updated hook. */
|
||||
private final File refUpdatedHook;
|
||||
|
||||
/** Filename of the reviewer added hook. */
|
||||
private final File reviewerAddedHook;
|
||||
|
||||
/** Filename of the cla signed hook. */
|
||||
private final File claSignedHook;
|
||||
|
||||
@@ -173,6 +177,7 @@ public class ChangeHookRunner implements ChangeHooks {
|
||||
changeAbandonedHook = sitePath.resolve(new File(hooksPath, getValue(config, "hooks", "changeAbandonedHook", "change-abandoned")).getPath());
|
||||
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());
|
||||
claSignedHook = sitePath.resolve(new File(hooksPath, getValue(config, "hooks", "claSignedHook", "cla-signed")).getPath());
|
||||
}
|
||||
|
||||
@@ -391,6 +396,25 @@ public class ChangeHookRunner implements ChangeHooks {
|
||||
runHook(refName.getParentKey(), refUpdatedHook, args);
|
||||
}
|
||||
|
||||
public void doReviewerAddedHook(final Change change, final Account account,
|
||||
final PatchSet patchSet, final ReviewDb db) throws OrmException {
|
||||
final ReviewerAddedEvent event = new ReviewerAddedEvent();
|
||||
|
||||
event.change = eventFactory.asChangeAttribute(change);
|
||||
event.patchSet = eventFactory.asPatchSetAttribute(patchSet);
|
||||
event.reviewer = eventFactory.asAccountAttribute(account);
|
||||
fireEvent(change, event, db);
|
||||
|
||||
final List<String> args = new ArrayList<String>();
|
||||
addArg(args, "--change", event.change.id);
|
||||
addArg(args, "--change-url", event.change.url);
|
||||
addArg(args, "--project", event.change.project);
|
||||
addArg(args, "--branch", event.change.branch);
|
||||
addArg(args, "--reviewer", getDisplayName(account));
|
||||
|
||||
runHook(change.getProject(), reviewerAddedHook, args);
|
||||
}
|
||||
|
||||
public void doClaSignupHook(Account account, ContributorAgreement cla) {
|
||||
if (account != null) {
|
||||
final List<String> args = new ArrayList<String>();
|
||||
|
||||
@@ -50,7 +50,7 @@ public interface ChangeHooks {
|
||||
* Fire the Draft Published Hook.
|
||||
*
|
||||
* @param change The change itself.
|
||||
* @param patchSet The Patchset that was created.
|
||||
* @param patchSet The Patchset that was published.
|
||||
* @throws OrmException
|
||||
*/
|
||||
public void doDraftPublishedHook(Change change, PatchSet patchSet,
|
||||
@@ -125,5 +125,15 @@ public interface ChangeHooks {
|
||||
public void doRefUpdatedHook(Branch.NameKey refName, ObjectId oldId,
|
||||
ObjectId newId, Account account);
|
||||
|
||||
/**
|
||||
* Fire the Reviewer Added Hook
|
||||
*
|
||||
* @param change The change itself.
|
||||
* @param patchSet The patchset that the reviewer was added on.
|
||||
* @param account The gerrit user who was added as reviewer.
|
||||
*/
|
||||
public void doReviewerAddedHook(Change change, Account account,
|
||||
PatchSet patchSet, ReviewDb db) throws OrmException;
|
||||
|
||||
public void doClaSignupHook(Account account, ContributorAgreement cla);
|
||||
}
|
||||
|
||||
@@ -80,6 +80,11 @@ public final class DisabledChangeHooks implements ChangeHooks {
|
||||
Account account) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doReviewerAddedHook(Change change, Account account, PatchSet patchSet,
|
||||
ReviewDb db) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeChangeListener(ChangeListener listener) {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user