Send event to stream when draft change is published

When a change is uploaded as a draft, a `patchset-created` event is
sent to the event stream, but since drafts are private to the owner,
the event is not publicly visible.  Furthermore, when the draft is
later published, no publicly visible event is sent.

The result of this is that external tools that rely on the event stream
to detect new changes will not receive events for any changes that are
first uploaded as draft.

This patch adds a new event, `draft-published`, which is sent to the
event stream when a draft change is published.  The content of this
event is the same as `patchset-created`.

Bug: Issue 1437
Change-Id: I72f6dde99a82253ba796c1c13226a8b33f0e82bf
This commit is contained in:
David Pursehouse
2012-06-12 18:34:37 +09:00
committed by Shawn O. Pearce
parent e11af58719
commit d556c19fbd
8 changed files with 117 additions and 8 deletions

View File

@@ -15,6 +15,7 @@
package com.google.gerrit.server.changedetail;
import com.google.gerrit.common.ChangeHooks;
import com.google.gerrit.common.data.ReviewResult;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
@@ -37,14 +38,17 @@ public class PublishDraft implements Callable<ReviewResult> {
private final ChangeControl.Factory changeControlFactory;
private final ReviewDb db;
private final ChangeHooks hooks;
private final PatchSet.Id patchSetId;
@Inject
PublishDraft(ChangeControl.Factory changeControlFactory,
ReviewDb db, @Assisted final PatchSet.Id patchSetId) {
ReviewDb db, @Assisted final PatchSet.Id patchSetId,
final ChangeHooks hooks) {
this.changeControlFactory = changeControlFactory;
this.db = db;
this.hooks = hooks;
this.patchSetId = patchSetId;
}
@@ -70,19 +74,26 @@ public class PublishDraft implements Callable<ReviewResult> {
result.addError(new ReviewResult.Error(
ReviewResult.Error.Type.PUBLISH_NOT_PERMITTED));
} else {
db.patchSets().atomicUpdate(patchSetId, new AtomicUpdate<PatchSet>() {
boolean published = false;
final PatchSet updatedPatch = db.patchSets().atomicUpdate(patchSetId,
new AtomicUpdate<PatchSet>() {
@Override
public PatchSet update(PatchSet patchset) {
if (patchset.isDraft()) {
patchset.setDraft(false);
return patchset;
}
return null;
}
});
if ((updatedPatch != null) && (!updatedPatch.isDraft())) {
published = true;
}
final Change change = db.changes().get(changeId);
if (change.getStatus() == Change.Status.DRAFT) {
db.changes().atomicUpdate(changeId,
final Change updatedChange = db.changes().atomicUpdate(changeId,
new AtomicUpdate<Change>() {
@Override
public Change update(Change change) {
@@ -95,6 +106,15 @@ public class PublishDraft implements Callable<ReviewResult> {
}
}
});
if ((updatedChange != null) &&
(updatedChange.getStatus() == Change.Status.NEW)) {
published = true;
}
}
if (published) {
hooks.doDraftPublishedHook(change, patch, db);
}
}