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:
Jason Tsay
2011-07-22 18:42:36 -07:00
committed by Mohan Zhang
parent 172a1fd899
commit 61cdb499e6
10 changed files with 177 additions and 2 deletions

View File

@@ -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,