Add current patchset to json when a review is public/ready
Current patch set is not a part of wip-state-changed and private-state-changed events. Previously when drafts were published a draft-published event was fired, and it included the current patchset information in the json for the event. Private-state-changed and wip-state-changed events do not contain that data. This change adds current patch set data for those events. Bug: Issue 8202 Change-Id: I9eda90de6b793e0080f4a79f60ea1bdd25d9d589
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
package com.google.gerrit.extensions.events;
|
||||
|
||||
public interface PrivateStateChangedListener {
|
||||
interface Event extends ChangeEvent {}
|
||||
interface Event extends RevisionEvent {}
|
||||
|
||||
void onPrivateStateChanged(Event event);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
package com.google.gerrit.extensions.events;
|
||||
|
||||
public interface WorkInProgressStateChangedListener {
|
||||
interface Event extends ChangeEvent {}
|
||||
interface Event extends RevisionEvent {}
|
||||
|
||||
void onWorkInProgressStateChanged(Event event);
|
||||
}
|
||||
|
||||
@@ -18,8 +18,11 @@ import com.google.common.base.Strings;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.ChangeMessage;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.server.ChangeMessagesUtil;
|
||||
import com.google.gerrit.server.PatchSetUtil;
|
||||
import com.google.gerrit.server.extensions.events.PrivateStateChanged;
|
||||
import com.google.gerrit.server.notedb.ChangeNotes;
|
||||
import com.google.gerrit.server.notedb.ChangeUpdate;
|
||||
import com.google.gerrit.server.update.BatchUpdateOp;
|
||||
import com.google.gerrit.server.update.ChangeContext;
|
||||
@@ -44,19 +47,23 @@ public class SetPrivateOp implements BatchUpdateOp {
|
||||
}
|
||||
|
||||
private final ChangeMessagesUtil cmUtil;
|
||||
private final PatchSetUtil psUtil;
|
||||
private final boolean isPrivate;
|
||||
private final Input input;
|
||||
private final PrivateStateChanged privateStateChanged;
|
||||
|
||||
private Change change;
|
||||
private PatchSet ps;
|
||||
|
||||
@Inject
|
||||
SetPrivateOp(
|
||||
PrivateStateChanged privateStateChanged,
|
||||
PatchSetUtil psUtil,
|
||||
@Assisted ChangeMessagesUtil cmUtil,
|
||||
@Assisted boolean isPrivate,
|
||||
@Assisted Input input) {
|
||||
this.cmUtil = cmUtil;
|
||||
this.psUtil = psUtil;
|
||||
this.isPrivate = isPrivate;
|
||||
this.input = input;
|
||||
this.privateStateChanged = privateStateChanged;
|
||||
@@ -65,6 +72,8 @@ public class SetPrivateOp implements BatchUpdateOp {
|
||||
@Override
|
||||
public boolean updateChange(ChangeContext ctx) throws ResourceConflictException, OrmException {
|
||||
change = ctx.getChange();
|
||||
ChangeNotes notes = ctx.getNotes();
|
||||
ps = psUtil.get(ctx.getDb(), notes, change.currentPatchSetId());
|
||||
ChangeUpdate update = ctx.getUpdate(change.currentPatchSetId());
|
||||
change.setPrivate(isPrivate);
|
||||
change.setLastUpdatedOn(ctx.getWhen());
|
||||
@@ -75,7 +84,7 @@ public class SetPrivateOp implements BatchUpdateOp {
|
||||
|
||||
@Override
|
||||
public void postUpdate(Context ctx) {
|
||||
privateStateChanged.fire(change, ctx.getAccount(), ctx.getWhen());
|
||||
privateStateChanged.fire(change, ps, ctx.getAccount(), ctx.getWhen());
|
||||
}
|
||||
|
||||
private void addMessage(ChangeContext ctx, ChangeUpdate update) throws OrmException {
|
||||
|
||||
@@ -125,7 +125,7 @@ public class WorkInProgressOp implements BatchUpdateOp {
|
||||
|
||||
@Override
|
||||
public void postUpdate(Context ctx) {
|
||||
stateChanged.fire(change, ctx.getAccount(), ctx.getWhen());
|
||||
stateChanged.fire(change, ps, ctx.getAccount(), ctx.getWhen());
|
||||
if (workInProgress || notify.ordinal() < NotifyHandling.OWNER_REVIEWERS.ordinal()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import com.google.common.base.Supplier;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.server.data.AccountAttribute;
|
||||
|
||||
public class PrivateStateChangedEvent extends ChangeEvent {
|
||||
public class PrivateStateChangedEvent extends PatchSetEvent {
|
||||
static final String TYPE = "private-state-changed";
|
||||
public Supplier<AccountAttribute> changer;
|
||||
|
||||
|
||||
@@ -473,11 +473,14 @@ public class StreamEventsApiListener
|
||||
@Override
|
||||
public void onWorkInProgressStateChanged(WorkInProgressStateChangedListener.Event ev) {
|
||||
try {
|
||||
Change change = getChange(ev.getChange());
|
||||
ChangeNotes notes = getNotes(ev.getChange());
|
||||
Change change = notes.getChange();
|
||||
PatchSet patchSet = getPatchSet(notes, ev.getRevision());
|
||||
WorkInProgressStateChangedEvent event = new WorkInProgressStateChangedEvent(change);
|
||||
|
||||
event.change = changeAttributeSupplier(change);
|
||||
event.changer = accountAttributeSupplier(ev.getWho());
|
||||
event.patchSet = patchSetAttributeSupplier(change, patchSet);
|
||||
|
||||
dispatcher.get().postEvent(change, event);
|
||||
} catch (OrmException | PermissionBackendException e) {
|
||||
@@ -488,11 +491,14 @@ public class StreamEventsApiListener
|
||||
@Override
|
||||
public void onPrivateStateChanged(PrivateStateChangedListener.Event ev) {
|
||||
try {
|
||||
Change change = getChange(ev.getChange());
|
||||
ChangeNotes notes = getNotes(ev.getChange());
|
||||
Change change = notes.getChange();
|
||||
PatchSet patchSet = getPatchSet(notes, ev.getRevision());
|
||||
PrivateStateChangedEvent event = new PrivateStateChangedEvent(change);
|
||||
|
||||
event.change = changeAttributeSupplier(change);
|
||||
event.changer = accountAttributeSupplier(ev.getWho());
|
||||
event.patchSet = patchSetAttributeSupplier(change, patchSet);
|
||||
|
||||
dispatcher.get().postEvent(change, event);
|
||||
} catch (OrmException | PermissionBackendException e) {
|
||||
|
||||
@@ -18,7 +18,7 @@ import com.google.common.base.Supplier;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.server.data.AccountAttribute;
|
||||
|
||||
public class WorkInProgressStateChangedEvent extends ChangeEvent {
|
||||
public class WorkInProgressStateChangedEvent extends PatchSetEvent {
|
||||
static final String TYPE = "wip-state-changed";
|
||||
public Supplier<AccountAttribute> changer;
|
||||
|
||||
|
||||
@@ -17,13 +17,19 @@ package com.google.gerrit.server.extensions.events;
|
||||
import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
||||
import com.google.gerrit.extensions.common.AccountInfo;
|
||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.common.RevisionInfo;
|
||||
import com.google.gerrit.extensions.events.PrivateStateChangedListener;
|
||||
import com.google.gerrit.extensions.registration.DynamicSet;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.server.GpgException;
|
||||
import com.google.gerrit.server.patch.PatchListNotAvailableException;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import java.sql.Timestamp;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -41,13 +47,18 @@ public class PrivateStateChanged {
|
||||
this.util = util;
|
||||
}
|
||||
|
||||
public void fire(Change change, Account account, Timestamp when) {
|
||||
public void fire(Change change, PatchSet patchSet, Account account, Timestamp when) {
|
||||
|
||||
if (!listeners.iterator().hasNext()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Event event = new Event(util.changeInfo(change), util.accountInfo(account), when);
|
||||
Event event =
|
||||
new Event(
|
||||
util.changeInfo(change),
|
||||
util.revisionInfo(change.getProject(), patchSet),
|
||||
util.accountInfo(account),
|
||||
when);
|
||||
for (PrivateStateChangedListener l : listeners) {
|
||||
try {
|
||||
l.onPrivateStateChanged(event);
|
||||
@@ -55,16 +66,20 @@ public class PrivateStateChanged {
|
||||
util.logEventListenerError(event, l, e);
|
||||
}
|
||||
}
|
||||
} catch (OrmException e) {
|
||||
} catch (PatchListNotAvailableException
|
||||
| PermissionBackendException
|
||||
| IOException
|
||||
| GpgException
|
||||
| OrmException e) {
|
||||
log.error("Couldn't fire event", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static class Event extends AbstractChangeEvent
|
||||
private static class Event extends AbstractRevisionEvent
|
||||
implements PrivateStateChangedListener.Event {
|
||||
|
||||
protected Event(ChangeInfo change, AccountInfo who, Timestamp when) {
|
||||
super(change, who, when, NotifyHandling.ALL);
|
||||
protected Event(ChangeInfo change, RevisionInfo revision, AccountInfo who, Timestamp when) {
|
||||
super(change, revision, who, when, NotifyHandling.ALL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,13 +17,19 @@ package com.google.gerrit.server.extensions.events;
|
||||
import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
||||
import com.google.gerrit.extensions.common.AccountInfo;
|
||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.common.RevisionInfo;
|
||||
import com.google.gerrit.extensions.events.WorkInProgressStateChangedListener;
|
||||
import com.google.gerrit.extensions.registration.DynamicSet;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.server.GpgException;
|
||||
import com.google.gerrit.server.patch.PatchListNotAvailableException;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import java.sql.Timestamp;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -42,13 +48,18 @@ public class WorkInProgressStateChanged {
|
||||
this.util = util;
|
||||
}
|
||||
|
||||
public void fire(Change change, Account account, Timestamp when) {
|
||||
public void fire(Change change, PatchSet patchSet, Account account, Timestamp when) {
|
||||
|
||||
if (!listeners.iterator().hasNext()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Event event = new Event(util.changeInfo(change), util.accountInfo(account), when);
|
||||
Event event =
|
||||
new Event(
|
||||
util.changeInfo(change),
|
||||
util.revisionInfo(change.getProject(), patchSet),
|
||||
util.accountInfo(account),
|
||||
when);
|
||||
for (WorkInProgressStateChangedListener l : listeners) {
|
||||
try {
|
||||
l.onWorkInProgressStateChanged(event);
|
||||
@@ -56,16 +67,20 @@ public class WorkInProgressStateChanged {
|
||||
util.logEventListenerError(event, l, e);
|
||||
}
|
||||
}
|
||||
} catch (OrmException e) {
|
||||
} catch (PatchListNotAvailableException
|
||||
| PermissionBackendException
|
||||
| IOException
|
||||
| GpgException
|
||||
| OrmException e) {
|
||||
log.error("Couldn't fire event", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static class Event extends AbstractChangeEvent
|
||||
private static class Event extends AbstractRevisionEvent
|
||||
implements WorkInProgressStateChangedListener.Event {
|
||||
|
||||
protected Event(ChangeInfo change, AccountInfo who, Timestamp when) {
|
||||
super(change, who, when, NotifyHandling.ALL);
|
||||
protected Event(ChangeInfo change, RevisionInfo revision, AccountInfo who, Timestamp when) {
|
||||
super(change, revision, who, when, NotifyHandling.ALL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user