WIP state changed event
Some ticket handling and integration systems will need to know when the WIP state has changed on a change. If a change is uploaded as a WIP change it would in many instances not warrant any action from said systems, but once the change is umarked as WIP it would, so there needs to be an event that advertises that state change. Bug: Issue 7360 Change-Id: Ia8f600e2bb5b8e4acf2bbd030e9d17c835884d62
This commit is contained in:
@@ -261,6 +261,19 @@ oldTopic:: Topic name before it was changed.
|
||||
eventCreatedOn:: Time in seconds since the UNIX epoch when this event was
|
||||
created.
|
||||
|
||||
=== Work In Progress State Changed
|
||||
|
||||
Sent when the the link:intro-user.html#wip[WIP] state of the change has changed.
|
||||
|
||||
type:: wip-state-changed
|
||||
|
||||
change:: link:json.html#change[change attribute]
|
||||
|
||||
changer:: link:json.html#account[account attribute]
|
||||
|
||||
eventCreatedOn:: Time in seconds since the UNIX epoch when this event was
|
||||
created.
|
||||
|
||||
=== Vote Deleted
|
||||
|
||||
Sent when a vote was removed from a change.
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
// Copyright (C) 2017 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.extensions.events;
|
||||
|
||||
public interface WorkInProgressStateChangedListener {
|
||||
interface Event extends ChangeEvent {}
|
||||
|
||||
void onWorkInProgressStateChanged(Event event);
|
||||
}
|
||||
@@ -25,6 +25,7 @@ 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.WorkInProgressStateChanged;
|
||||
import com.google.gerrit.server.notedb.ChangeNotes;
|
||||
import com.google.gerrit.server.notedb.ChangeUpdate;
|
||||
import com.google.gerrit.server.update.BatchUpdateOp;
|
||||
@@ -58,6 +59,7 @@ public class WorkInProgressOp implements BatchUpdateOp {
|
||||
private final boolean workInProgress;
|
||||
private final Input in;
|
||||
private final NotifyHandling notify;
|
||||
private final WorkInProgressStateChanged stateChanged;
|
||||
|
||||
private Change change;
|
||||
private ChangeNotes notes;
|
||||
@@ -69,11 +71,13 @@ public class WorkInProgressOp implements BatchUpdateOp {
|
||||
ChangeMessagesUtil cmUtil,
|
||||
EmailReviewComments.Factory email,
|
||||
PatchSetUtil psUtil,
|
||||
WorkInProgressStateChanged stateChanged,
|
||||
@Assisted boolean workInProgress,
|
||||
@Assisted Input in) {
|
||||
this.cmUtil = cmUtil;
|
||||
this.email = email;
|
||||
this.psUtil = psUtil;
|
||||
this.stateChanged = stateChanged;
|
||||
this.workInProgress = workInProgress;
|
||||
this.in = in;
|
||||
notify =
|
||||
@@ -121,6 +125,7 @@ public class WorkInProgressOp implements BatchUpdateOp {
|
||||
|
||||
@Override
|
||||
public void postUpdate(Context ctx) {
|
||||
stateChanged.fire(change, ctx.getAccount(), ctx.getWhen());
|
||||
if (workInProgress || notify.ordinal() < NotifyHandling.OWNER_REVIEWERS.ordinal()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ import com.google.gerrit.extensions.events.RevisionCreatedListener;
|
||||
import com.google.gerrit.extensions.events.TopicEditedListener;
|
||||
import com.google.gerrit.extensions.events.UsageDataPublishedListener;
|
||||
import com.google.gerrit.extensions.events.VoteDeletedListener;
|
||||
import com.google.gerrit.extensions.events.WorkInProgressStateChangedListener;
|
||||
import com.google.gerrit.extensions.registration.DynamicItem;
|
||||
import com.google.gerrit.extensions.registration.DynamicMap;
|
||||
import com.google.gerrit.extensions.registration.DynamicSet;
|
||||
@@ -321,6 +322,7 @@ public class GerritGlobalModule extends FactoryModule {
|
||||
DynamicSet.setOf(binder(), ReviewerAddedListener.class);
|
||||
DynamicSet.setOf(binder(), ReviewerDeletedListener.class);
|
||||
DynamicSet.setOf(binder(), VoteDeletedListener.class);
|
||||
DynamicSet.setOf(binder(), WorkInProgressStateChangedListener.class);
|
||||
DynamicSet.setOf(binder(), RevisionCreatedListener.class);
|
||||
DynamicSet.setOf(binder(), TopicEditedListener.class);
|
||||
DynamicSet.setOf(binder(), AgreementSignupListener.class);
|
||||
|
||||
@@ -37,6 +37,7 @@ public class EventTypes {
|
||||
register(ReviewerDeletedEvent.TYPE, ReviewerDeletedEvent.class);
|
||||
register(TopicChangedEvent.TYPE, TopicChangedEvent.class);
|
||||
register(VoteDeletedEvent.TYPE, VoteDeletedEvent.class);
|
||||
register(WorkInProgressStateChangedEvent.TYPE, WorkInProgressStateChangedEvent.class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -37,6 +37,7 @@ import com.google.gerrit.extensions.events.ReviewerDeletedListener;
|
||||
import com.google.gerrit.extensions.events.RevisionCreatedListener;
|
||||
import com.google.gerrit.extensions.events.TopicEditedListener;
|
||||
import com.google.gerrit.extensions.events.VoteDeletedListener;
|
||||
import com.google.gerrit.extensions.events.WorkInProgressStateChangedListener;
|
||||
import com.google.gerrit.extensions.registration.DynamicItem;
|
||||
import com.google.gerrit.extensions.registration.DynamicSet;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
@@ -77,6 +78,7 @@ public class StreamEventsApiListener
|
||||
ChangeAbandonedListener,
|
||||
ChangeMergedListener,
|
||||
ChangeRestoredListener,
|
||||
WorkInProgressStateChangedListener,
|
||||
CommentAddedListener,
|
||||
GitReferenceUpdatedListener,
|
||||
HashtagsEditedListener,
|
||||
@@ -105,6 +107,8 @@ public class StreamEventsApiListener
|
||||
DynamicSet.bind(binder(), RevisionCreatedListener.class).to(StreamEventsApiListener.class);
|
||||
DynamicSet.bind(binder(), TopicEditedListener.class).to(StreamEventsApiListener.class);
|
||||
DynamicSet.bind(binder(), VoteDeletedListener.class).to(StreamEventsApiListener.class);
|
||||
DynamicSet.bind(binder(), WorkInProgressStateChangedListener.class)
|
||||
.to(StreamEventsApiListener.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -462,6 +466,21 @@ public class StreamEventsApiListener
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWorkInProgressStateChanged(WorkInProgressStateChangedListener.Event ev) {
|
||||
try {
|
||||
Change change = getChange(ev.getChange());
|
||||
WorkInProgressStateChangedEvent event = new WorkInProgressStateChangedEvent(change);
|
||||
|
||||
event.change = changeAttributeSupplier(change);
|
||||
event.changer = accountAttributeSupplier(ev.getWho());
|
||||
|
||||
dispatcher.get().postEvent(change, event);
|
||||
} catch (OrmException | PermissionBackendException e) {
|
||||
log.error("Failed to dispatch event", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVoteDeleted(VoteDeletedListener.Event ev) {
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
// Copyright (C) 2017 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.events;
|
||||
|
||||
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 {
|
||||
static final String TYPE = "wip-state-changed";
|
||||
public Supplier<AccountAttribute> changer;
|
||||
|
||||
protected WorkInProgressStateChangedEvent(Change change) {
|
||||
super(TYPE, change);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
// Copyright (C) 2017 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.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.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.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import java.sql.Timestamp;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class WorkInProgressStateChanged {
|
||||
private static final Logger log = LoggerFactory.getLogger(WorkInProgressStateChanged.class);
|
||||
|
||||
private final DynamicSet<WorkInProgressStateChangedListener> listeners;
|
||||
private final EventUtil util;
|
||||
|
||||
@Inject
|
||||
WorkInProgressStateChanged(
|
||||
DynamicSet<WorkInProgressStateChangedListener> listeners, EventUtil util) {
|
||||
this.listeners = listeners;
|
||||
this.util = util;
|
||||
}
|
||||
|
||||
public void fire(Change change, Account account, Timestamp when) {
|
||||
|
||||
if (!listeners.iterator().hasNext()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Event event = new Event(util.changeInfo(change), util.accountInfo(account), when);
|
||||
for (WorkInProgressStateChangedListener l : listeners) {
|
||||
try {
|
||||
l.onWorkInProgressStateChanged(event);
|
||||
} catch (Exception e) {
|
||||
util.logEventListenerError(event, l, e);
|
||||
}
|
||||
}
|
||||
} catch (OrmException e) {
|
||||
log.error("Couldn't fire event", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static class Event extends AbstractChangeEvent
|
||||
implements WorkInProgressStateChangedListener.Event {
|
||||
|
||||
protected Event(ChangeInfo change, AccountInfo who, Timestamp when) {
|
||||
super(change, who, when, NotifyHandling.ALL);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user