Publish draft patchsets in UI and SSH
Adds Publish button to draft patchsets in UI and an option to publish draft patchsets in the review ssh command. Publishing a draft patchset makes it visible. Publishing a draft patchset in a draft change irreversibly upgrades the change status to NEW. Change-Id: I8ad8ed9d69f3f9e876a9288f568ae3e003a0e257
This commit is contained in:
@@ -14,6 +14,7 @@ SYNOPSIS
|
||||
[--force-message]
|
||||
[--submit]
|
||||
[--abandon | --restore]
|
||||
[--publish]
|
||||
[--verified <N>] [--code-review <N>]
|
||||
{COMMIT | CHANGEID,PATCHSET}...
|
||||
|
||||
@@ -71,7 +72,7 @@ successfully, even if the label could not be changed.
|
||||
(option is mutually exclusive with --submit and --restore)
|
||||
|
||||
--restore::
|
||||
Restore the specified abandonned patch set(s).
|
||||
Restore the specified abandoned patch set(s).
|
||||
(option is mutually exclusive with --abandon)
|
||||
|
||||
--submit::
|
||||
@@ -79,6 +80,10 @@ successfully, even if the label could not be changed.
|
||||
Submit the specified patch set(s) for merging.
|
||||
(option is mutually exclusive with --abandon)
|
||||
|
||||
--publish::
|
||||
Publish the specified draft patch set(s).
|
||||
(option is mutually exclusive with --submit, --restore, and --abandon)
|
||||
|
||||
--code-review::
|
||||
--verified::
|
||||
Set the approval category to the value 'N'. The exact
|
||||
|
@@ -37,4 +37,7 @@ public interface ChangeManageService extends RemoteJsonService {
|
||||
@SignInRequired
|
||||
void restoreChange(PatchSet.Id patchSetId, String message,
|
||||
AsyncCallback<ChangeDetail> callback);
|
||||
|
||||
@SignInRequired
|
||||
void publish(PatchSet.Id patchSetId, AsyncCallback<ChangeDetail> callback);
|
||||
}
|
||||
|
@@ -138,6 +138,8 @@ public interface ChangeConstants extends Constants {
|
||||
String headingRestoreMessage();
|
||||
String buttonRestoreChangeSend();
|
||||
|
||||
String buttonPublishPatchSet();
|
||||
|
||||
String pagedChangeListPrev();
|
||||
String pagedChangeListNext();
|
||||
|
||||
|
@@ -115,6 +115,8 @@ buttonPublishCommentsCancel = Cancel
|
||||
headingCoverMessage = Cover Message:
|
||||
headingPatchComments = Patch Comments:
|
||||
|
||||
buttonPublishPatchSet = Publish
|
||||
|
||||
pagedChangeListPrev = ⇦Prev
|
||||
pagedChangeListNext = Next⇨
|
||||
|
||||
|
@@ -176,6 +176,9 @@ class PatchSetComplexDisclosurePanel extends ComplexDisclosurePanel implements O
|
||||
populateActions(detail);
|
||||
}
|
||||
}
|
||||
if (detail.getPatchSet().isDraft()) {
|
||||
populatePublishAction();
|
||||
}
|
||||
}
|
||||
populateDiffAllActions(detail);
|
||||
body.add(patchTable);
|
||||
@@ -546,6 +549,29 @@ class PatchSetComplexDisclosurePanel extends ComplexDisclosurePanel implements O
|
||||
actionsPanel.add(b);
|
||||
}
|
||||
|
||||
private void populatePublishAction() {
|
||||
final Button b = new Button(Util.C.buttonPublishPatchSet());
|
||||
b.addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(final ClickEvent event) {
|
||||
b.setEnabled(false);
|
||||
Util.MANAGE_SVC.publish(patchSet.getId(),
|
||||
new GerritCallback<ChangeDetail>() {
|
||||
public void onSuccess(ChangeDetail result) {
|
||||
changeScreen.update(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
b.setEnabled(true);
|
||||
super.onFailure(caught);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
actionsPanel.add(b);
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
AccountDiffPreference diffPrefs;
|
||||
if (patchTable == null) {
|
||||
|
@@ -25,16 +25,19 @@ class ChangeManageServiceImpl implements ChangeManageService {
|
||||
private final AbandonChange.Factory abandonChangeFactory;
|
||||
private final RestoreChange.Factory restoreChangeFactory;
|
||||
private final RevertChange.Factory revertChangeFactory;
|
||||
private final PublishAction.Factory publishAction;
|
||||
|
||||
@Inject
|
||||
ChangeManageServiceImpl(final SubmitAction.Factory patchSetAction,
|
||||
final AbandonChange.Factory abandonChangeFactory,
|
||||
final RestoreChange.Factory restoreChangeFactory,
|
||||
final RevertChange.Factory revertChangeFactory) {
|
||||
final RevertChange.Factory revertChangeFactory,
|
||||
final PublishAction.Factory publishAction) {
|
||||
this.submitAction = patchSetAction;
|
||||
this.abandonChangeFactory = abandonChangeFactory;
|
||||
this.restoreChangeFactory = restoreChangeFactory;
|
||||
this.revertChangeFactory = revertChangeFactory;
|
||||
this.publishAction = publishAction;
|
||||
}
|
||||
|
||||
public void submit(final PatchSet.Id patchSetId,
|
||||
@@ -56,4 +59,9 @@ class ChangeManageServiceImpl implements ChangeManageService {
|
||||
final AsyncCallback<ChangeDetail> callback) {
|
||||
restoreChangeFactory.create(patchSetId, message).to(callback);
|
||||
}
|
||||
|
||||
public void publish(final PatchSet.Id patchSetId,
|
||||
final AsyncCallback<ChangeDetail> callback) {
|
||||
publishAction.create(patchSetId).to(callback);
|
||||
}
|
||||
}
|
||||
|
@@ -36,6 +36,7 @@ public class ChangeModule extends RpcServletModule {
|
||||
factory(PatchSetDetailFactory.Factory.class);
|
||||
factory(PatchSetPublishDetailFactory.Factory.class);
|
||||
factory(SubmitAction.Factory.class);
|
||||
factory(PublishAction.Factory.class);
|
||||
}
|
||||
});
|
||||
rpc(ChangeDetailServiceImpl.class);
|
||||
|
@@ -0,0 +1,70 @@
|
||||
// Copyright (C) 2011 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.httpd.rpc.changedetail;
|
||||
|
||||
import com.google.gerrit.common.data.ChangeDetail;
|
||||
import com.google.gerrit.common.errors.NoSuchEntityException;
|
||||
import com.google.gerrit.httpd.rpc.Handler;
|
||||
import com.google.gerrit.reviewdb.Change;
|
||||
import com.google.gerrit.reviewdb.PatchSet;
|
||||
import com.google.gerrit.reviewdb.ReviewDb;
|
||||
import com.google.gerrit.server.ChangeUtil;
|
||||
import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException;
|
||||
import com.google.gerrit.server.project.ChangeControl;
|
||||
import com.google.gerrit.server.project.NoSuchChangeException;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
|
||||
class PublishAction extends Handler<ChangeDetail> {
|
||||
interface Factory {
|
||||
PublishAction create(PatchSet.Id patchSetId);
|
||||
}
|
||||
|
||||
private final ReviewDb db;
|
||||
private final ChangeDetailFactory.Factory changeDetailFactory;
|
||||
private final ChangeControl.Factory changeControlFactory;
|
||||
|
||||
private final PatchSet.Id patchSetId;
|
||||
|
||||
@Inject
|
||||
PublishAction(final ReviewDb db,
|
||||
final ChangeDetailFactory.Factory changeDetailFactory,
|
||||
final ChangeControl.Factory changeControlFactory,
|
||||
@Assisted final PatchSet.Id patchSetId) {
|
||||
this.db = db;
|
||||
this.changeControlFactory = changeControlFactory;
|
||||
this.changeDetailFactory = changeDetailFactory;
|
||||
|
||||
this.patchSetId = patchSetId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChangeDetail call() throws OrmException, NoSuchEntityException,
|
||||
IllegalStateException, PatchSetInfoNotAvailableException,
|
||||
NoSuchChangeException {
|
||||
|
||||
final Change.Id changeId = patchSetId.getParentKey();
|
||||
final ChangeControl changeControl =
|
||||
changeControlFactory.validateFor(changeId);
|
||||
|
||||
if (!changeControl.isOwner() && !changeControl.isVisible(db)) {
|
||||
throw new IllegalStateException("Cannot publish patchset");
|
||||
}
|
||||
|
||||
ChangeUtil.publishDraftPatchSet(db, patchSetId);
|
||||
return changeDetailFactory.create(changeId).call();
|
||||
}
|
||||
}
|
@@ -403,6 +403,43 @@ public class ChangeUtil {
|
||||
hooks.doChangeRestoreHook(updatedChange, user.getAccount(), message, db);
|
||||
}
|
||||
|
||||
public static void publishDraftPatchSet(final ReviewDb db,
|
||||
final PatchSet.Id patchSetId) throws OrmException, NoSuchChangeException{
|
||||
final Change.Id changeId = patchSetId.getParentKey();
|
||||
final PatchSet patch = db.patchSets().get(patchSetId);
|
||||
if (patch == null || !patch.isDraft()) {
|
||||
throw new NoSuchChangeException(changeId);
|
||||
}
|
||||
|
||||
db.patchSets().atomicUpdate(patchSetId, new AtomicUpdate<PatchSet>() {
|
||||
@Override
|
||||
public PatchSet update(PatchSet patchset) {
|
||||
if (patchset.isDraft()) {
|
||||
patchset.setDraft(false);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
final Change change = db.changes().get(changeId);
|
||||
if (change.getStatus() == Change.Status.DRAFT) {
|
||||
db.changes().atomicUpdate(changeId,
|
||||
new AtomicUpdate<Change>() {
|
||||
@Override
|
||||
public Change update(Change change) {
|
||||
if (change.getStatus() == Change.Status.DRAFT
|
||||
&& change.currentPatchSetId().equals(patchSetId)) {
|
||||
change.setStatus(Change.Status.NEW);
|
||||
ChangeUtil.updated(change);
|
||||
return change;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static <T extends ReplyToChangeSender> void updatedChange(
|
||||
final ReviewDb db, final IdentifiedUser user, final Change change,
|
||||
final ChangeMessage cmsg, ReplyToChangeSender.Factory<T> senderFactory,
|
||||
|
@@ -104,6 +104,9 @@ public class ReviewCommand extends BaseCommand {
|
||||
+ "even if the label score cannot be applied due to change being closed")
|
||||
private boolean forceMessage = false;
|
||||
|
||||
@Option(name = "--publish", usage = "publish a draft patch set")
|
||||
private boolean publishPatchSet;
|
||||
|
||||
@Inject
|
||||
private ReviewDb db;
|
||||
|
||||
@@ -155,6 +158,17 @@ public class ReviewCommand extends BaseCommand {
|
||||
if (submitChange) {
|
||||
throw error("abandon and submit actions are mutually exclusive");
|
||||
}
|
||||
if (publishPatchSet) {
|
||||
throw error("abandon and publish actions are mutually exclusive");
|
||||
}
|
||||
}
|
||||
if (publishPatchSet) {
|
||||
if (restoreChange) {
|
||||
throw error("publish and restore actions are mutually exclusive");
|
||||
}
|
||||
if (submitChange) {
|
||||
throw error("publish and submit actions are mutually exclusive");
|
||||
}
|
||||
}
|
||||
|
||||
boolean ok = true;
|
||||
@@ -315,6 +329,13 @@ public class ReviewCommand extends BaseCommand {
|
||||
throw new Failure(1, "Unsupported status " + result.get(0).status);
|
||||
}
|
||||
}
|
||||
if (publishPatchSet) {
|
||||
if (changeControl.isOwner() && changeControl.isVisible(db)) {
|
||||
ChangeUtil.publishDraftPatchSet(db, patchSetId);
|
||||
} else {
|
||||
throw error("Not permitted to publish draft patchset");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Set<PatchSet.Id> parsePatchSetId(final String patchIdentity)
|
||||
|
Reference in New Issue
Block a user