Mark changes as submitted when the submit action is pushed
A submitted change is a different status, so it can lay around pending until its dependencies are also submitted and they can be merged into the destination branch. Currently we don't actually do the merge, we just mark the state on the change and record who did it. Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -26,6 +26,8 @@
|
|||||||
class='com.google.gerrit.server.ChangeDetailServiceSrv'/>
|
class='com.google.gerrit.server.ChangeDetailServiceSrv'/>
|
||||||
<servlet path='/rpc/ChangeListService'
|
<servlet path='/rpc/ChangeListService'
|
||||||
class='com.google.gerrit.server.ChangeListServiceSrv'/>
|
class='com.google.gerrit.server.ChangeListServiceSrv'/>
|
||||||
|
<servlet path='/rpc/ChangeManageService'
|
||||||
|
class='com.google.gerrit.server.ChangeManageServiceSrv'/>
|
||||||
<servlet path='/rpc/GroupAdminService'
|
<servlet path='/rpc/GroupAdminService'
|
||||||
class='com.google.gerrit.server.GroupAdminServiceSrv'/>
|
class='com.google.gerrit.server.GroupAdminServiceSrv'/>
|
||||||
<servlet path='/rpc/PatchDetailService'
|
<servlet path='/rpc/PatchDetailService'
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
// Copyright 2009 Google Inc.
|
||||||
|
//
|
||||||
|
// 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.client.changes;
|
||||||
|
|
||||||
|
import com.google.gerrit.client.reviewdb.ApprovalCategoryValue;
|
||||||
|
import com.google.gerrit.client.reviewdb.PatchSet;
|
||||||
|
import com.google.gerrit.client.rpc.SignInRequired;
|
||||||
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||||
|
import com.google.gwtjsonrpc.client.RemoteJsonService;
|
||||||
|
import com.google.gwtjsonrpc.client.VoidResult;
|
||||||
|
|
||||||
|
public interface ChangeManageService extends RemoteJsonService {
|
||||||
|
@SignInRequired
|
||||||
|
void patchSetAction(ApprovalCategoryValue.Id value, PatchSet.Id patchSetId,
|
||||||
|
AsyncCallback<VoidResult> callback);
|
||||||
|
}
|
||||||
@@ -19,18 +19,24 @@ import com.google.gerrit.client.SignedInListener;
|
|||||||
import com.google.gerrit.client.data.ApprovalType;
|
import com.google.gerrit.client.data.ApprovalType;
|
||||||
import com.google.gerrit.client.data.ChangeDetail;
|
import com.google.gerrit.client.data.ChangeDetail;
|
||||||
import com.google.gerrit.client.data.PatchSetDetail;
|
import com.google.gerrit.client.data.PatchSetDetail;
|
||||||
|
import com.google.gerrit.client.reviewdb.ApprovalCategory;
|
||||||
|
import com.google.gerrit.client.reviewdb.ApprovalCategoryValue;
|
||||||
import com.google.gerrit.client.reviewdb.PatchSet;
|
import com.google.gerrit.client.reviewdb.PatchSet;
|
||||||
import com.google.gerrit.client.rpc.Common;
|
import com.google.gerrit.client.rpc.Common;
|
||||||
import com.google.gerrit.client.rpc.GerritCallback;
|
import com.google.gerrit.client.rpc.GerritCallback;
|
||||||
import com.google.gwt.core.client.GWT;
|
|
||||||
import com.google.gwt.user.client.ui.Button;
|
import com.google.gwt.user.client.ui.Button;
|
||||||
|
import com.google.gwt.user.client.ui.ClickListener;
|
||||||
import com.google.gwt.user.client.ui.Composite;
|
import com.google.gwt.user.client.ui.Composite;
|
||||||
import com.google.gwt.user.client.ui.DisclosureEvent;
|
import com.google.gwt.user.client.ui.DisclosureEvent;
|
||||||
import com.google.gwt.user.client.ui.DisclosureHandler;
|
import com.google.gwt.user.client.ui.DisclosureHandler;
|
||||||
import com.google.gwt.user.client.ui.FlowPanel;
|
import com.google.gwt.user.client.ui.FlowPanel;
|
||||||
import com.google.gwt.user.client.ui.Grid;
|
import com.google.gwt.user.client.ui.Grid;
|
||||||
import com.google.gwt.user.client.ui.Panel;
|
import com.google.gwt.user.client.ui.Panel;
|
||||||
|
import com.google.gwt.user.client.ui.Widget;
|
||||||
import com.google.gwt.user.client.ui.HTMLTable.CellFormatter;
|
import com.google.gwt.user.client.ui.HTMLTable.CellFormatter;
|
||||||
|
import com.google.gwtjsonrpc.client.VoidResult;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
class PatchSetPanel extends Composite implements DisclosureHandler {
|
class PatchSetPanel extends Composite implements DisclosureHandler {
|
||||||
private static final int R_DOWNLOAD = 0;
|
private static final int R_DOWNLOAD = 0;
|
||||||
@@ -115,16 +121,38 @@ class PatchSetPanel extends Composite implements DisclosureHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void populateActions(final PatchSetDetail detail) {
|
private void populateActions(final PatchSetDetail detail) {
|
||||||
if (changeDetail.getCurrentActions() != null
|
final Set<ApprovalCategory.Id> allowed = changeDetail.getCurrentActions();
|
||||||
&& !changeDetail.getCurrentActions().isEmpty()) {
|
if (allowed == null) {
|
||||||
for (final ApprovalType at : Common.getGerritConfig().getActionTypes()) {
|
// No set of actions, perhaps the user is not signed in?
|
||||||
if (changeDetail.getCurrentActions().contains(at.getCategory().getId())) {
|
return;
|
||||||
final Button b =
|
}
|
||||||
new Button(Util.M.patchSetAction(at.getCategory().getName(),
|
|
||||||
detail.getPatchSet().getPatchSetId()));
|
for (final ApprovalType at : Common.getGerritConfig().getActionTypes()) {
|
||||||
actionsPanel.add(b);
|
final ApprovalCategoryValue max = at.getMax();
|
||||||
}
|
if (max == null || max.getValue() <= 0) {
|
||||||
|
// No positive assertion, don't draw a button.
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
if (!allowed.contains(at.getCategory().getId())) {
|
||||||
|
// User isn't permitted to invoke this.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Button b =
|
||||||
|
new Button(Util.M.patchSetAction(at.getCategory().getName(), detail
|
||||||
|
.getPatchSet().getPatchSetId()));
|
||||||
|
b.addClickListener(new ClickListener() {
|
||||||
|
public void onClick(Widget sender) {
|
||||||
|
Util.MANAGE_SVC.patchSetAction(max.getId(), patchSet.getId(),
|
||||||
|
new GerritCallback<VoidResult>() {
|
||||||
|
public void onSuccess(VoidResult result) {
|
||||||
|
// TODO refresh change screen
|
||||||
|
actionsPanel.remove(b);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
actionsPanel.add(b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ public class Util {
|
|||||||
|
|
||||||
public static final ChangeDetailService DETAIL_SVC;
|
public static final ChangeDetailService DETAIL_SVC;
|
||||||
public static final ChangeListService LIST_SVC;
|
public static final ChangeListService LIST_SVC;
|
||||||
|
public static final ChangeManageService MANAGE_SVC;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
DETAIL_SVC = GWT.create(ChangeDetailService.class);
|
DETAIL_SVC = GWT.create(ChangeDetailService.class);
|
||||||
@@ -31,6 +32,9 @@ public class Util {
|
|||||||
|
|
||||||
LIST_SVC = GWT.create(ChangeListService.class);
|
LIST_SVC = GWT.create(ChangeListService.class);
|
||||||
JsonUtil.bind(LIST_SVC, "rpc/ChangeListService");
|
JsonUtil.bind(LIST_SVC, "rpc/ChangeListService");
|
||||||
|
|
||||||
|
MANAGE_SVC = GWT.create(ChangeManageService.class);
|
||||||
|
JsonUtil.bind(MANAGE_SVC, "rpc/ChangeManageService");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String toLongString(final Change.Status status) {
|
public static String toLongString(final Change.Status status) {
|
||||||
|
|||||||
@@ -66,6 +66,10 @@ public final class ApprovalCategoryValue {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ApprovalCategoryValue.Id getId() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
public ApprovalCategory.Id getCategoryId() {
|
public ApprovalCategory.Id getCategoryId() {
|
||||||
return key.categoryId;
|
return key.categoryId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,12 +51,18 @@ public final class Change {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static final char MIN_OPEN = 'a';
|
||||||
protected static final char STATUS_NEW = 'n';
|
protected static final char STATUS_NEW = 'n';
|
||||||
|
protected static final char STATUS_SUBMITTED = 's';
|
||||||
|
protected static final char MAX_OPEN = 'z';
|
||||||
|
|
||||||
protected static final char STATUS_MERGED = 'M';
|
protected static final char STATUS_MERGED = 'M';
|
||||||
|
|
||||||
public static enum Status {
|
public static enum Status {
|
||||||
NEW(STATUS_NEW, false),
|
NEW(STATUS_NEW, false),
|
||||||
|
|
||||||
|
SUBMITTED(STATUS_SUBMITTED, false),
|
||||||
|
|
||||||
MERGED(STATUS_MERGED, true),
|
MERGED(STATUS_MERGED, true),
|
||||||
|
|
||||||
ABANDONED('A', true);
|
ABANDONED('A', true);
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ public interface ChangeAccess extends Access<Change, Change.Id> {
|
|||||||
@PrimaryKey("changeId")
|
@PrimaryKey("changeId")
|
||||||
Change get(Change.Id id) throws OrmException;
|
Change get(Change.Id id) throws OrmException;
|
||||||
|
|
||||||
@Query("WHERE owner = ? AND status = '" + Change.STATUS_NEW
|
@Query("WHERE owner = ? AND status >= '" + Change.MIN_OPEN
|
||||||
+ "' ORDER BY lastUpdatedOn DESC")
|
+ "' AND status <= '" + Change.MAX_OPEN + "' ORDER BY lastUpdatedOn DESC")
|
||||||
ResultSet<Change> byOwnerOpen(Account.Id id) throws OrmException;
|
ResultSet<Change> byOwnerOpen(Account.Id id) throws OrmException;
|
||||||
|
|
||||||
@Query("WHERE owner = ? AND status = '" + Change.STATUS_MERGED
|
@Query("WHERE owner = ? AND status = '" + Change.STATUS_MERGED
|
||||||
|
|||||||
@@ -87,6 +87,10 @@ public final class ChangeApproval {
|
|||||||
setGranted();
|
setGranted();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ChangeApproval.Key getKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
public Change.Id getChangeId() {
|
public Change.Id getChangeId() {
|
||||||
return key.changeId;
|
return key.changeId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,135 @@
|
|||||||
|
// Copyright 2009 Google Inc.
|
||||||
|
//
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
import com.google.gerrit.client.changes.ChangeManageService;
|
||||||
|
import com.google.gerrit.client.data.ApprovalType;
|
||||||
|
import com.google.gerrit.client.reviewdb.Account;
|
||||||
|
import com.google.gerrit.client.reviewdb.ApprovalCategory;
|
||||||
|
import com.google.gerrit.client.reviewdb.ApprovalCategoryValue;
|
||||||
|
import com.google.gerrit.client.reviewdb.Change;
|
||||||
|
import com.google.gerrit.client.reviewdb.ChangeApproval;
|
||||||
|
import com.google.gerrit.client.reviewdb.PatchSet;
|
||||||
|
import com.google.gerrit.client.reviewdb.ReviewDb;
|
||||||
|
import com.google.gerrit.client.rpc.BaseServiceImplementation;
|
||||||
|
import com.google.gerrit.client.rpc.Common;
|
||||||
|
import com.google.gerrit.client.rpc.NoSuchEntityException;
|
||||||
|
import com.google.gerrit.client.workflow.FunctionState;
|
||||||
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||||
|
import com.google.gwtjsonrpc.client.VoidResult;
|
||||||
|
import com.google.gwtorm.client.OrmException;
|
||||||
|
import com.google.gwtorm.client.Transaction;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ChangeManageServiceImpl extends BaseServiceImplementation
|
||||||
|
implements ChangeManageService {
|
||||||
|
|
||||||
|
public void patchSetAction(final ApprovalCategoryValue.Id value,
|
||||||
|
final PatchSet.Id patchSetId, final AsyncCallback<VoidResult> callback) {
|
||||||
|
run(callback, new Action<VoidResult>() {
|
||||||
|
public VoidResult run(final ReviewDb db) throws OrmException, Failure {
|
||||||
|
final Change change = db.changes().get(patchSetId.getParentKey());
|
||||||
|
if (change == null) {
|
||||||
|
throw new Failure(new NoSuchEntityException());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!patchSetId.equals(change.currentPatchSetId())) {
|
||||||
|
throw new Failure(new IllegalStateException("Patch set " + patchSetId
|
||||||
|
+ " not current"));
|
||||||
|
}
|
||||||
|
if (change.getStatus().isClosed()) {
|
||||||
|
throw new Failure(new IllegalStateException("Change" + change.getId()
|
||||||
|
+ " is closed"));
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<ChangeApproval> allApprovals =
|
||||||
|
new ArrayList<ChangeApproval>(db.changeApprovals().byChange(
|
||||||
|
change.getId()).toList());
|
||||||
|
|
||||||
|
final Account.Id me = Common.getAccountId();
|
||||||
|
final ChangeApproval.Key ak =
|
||||||
|
new ChangeApproval.Key(change.getId(), me, value.getParentKey());
|
||||||
|
ChangeApproval myAction = null;
|
||||||
|
boolean isnew = true;
|
||||||
|
for (final ChangeApproval ca : allApprovals) {
|
||||||
|
if (ak.equals(ca.getKey())) {
|
||||||
|
isnew = false;
|
||||||
|
myAction = ca;
|
||||||
|
myAction.setValue(value.get());
|
||||||
|
myAction.setGranted();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (myAction == null) {
|
||||||
|
myAction = new ChangeApproval(ak, value.get());
|
||||||
|
allApprovals.add(myAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
final ApprovalType actionType =
|
||||||
|
Common.getGerritConfig().getApprovalType(myAction.getCategoryId());
|
||||||
|
if (actionType == null || !actionType.getCategory().isAction()) {
|
||||||
|
throw new Failure(new IllegalArgumentException(actionType
|
||||||
|
.getCategory().getName()
|
||||||
|
+ " not an action"));
|
||||||
|
}
|
||||||
|
|
||||||
|
final FunctionState fs =
|
||||||
|
new FunctionState(Common.getProjectCache().get(
|
||||||
|
change.getDest().getParentKey()), allApprovals);
|
||||||
|
for (ApprovalType c : Common.getGerritConfig().getApprovalTypes()) {
|
||||||
|
c.getCategory().getFunction().run(c, fs);
|
||||||
|
}
|
||||||
|
if (!actionType.getCategory().getFunction().isValid(me, actionType, fs)) {
|
||||||
|
throw new Failure(new IllegalStateException(actionType.getCategory()
|
||||||
|
.getName()
|
||||||
|
+ " not permitted"));
|
||||||
|
}
|
||||||
|
fs.normalize(actionType, myAction);
|
||||||
|
if (myAction.getValue() <= 0) {
|
||||||
|
throw new Failure(new IllegalStateException(actionType.getCategory()
|
||||||
|
.getName()
|
||||||
|
+ " not permitted"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ApprovalCategory.SUBMIT.equals(actionType.getCategory().getId())) {
|
||||||
|
if (change.getStatus() == Change.Status.NEW) {
|
||||||
|
change.setStatus(Change.Status.SUBMITTED);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Failure(new IllegalArgumentException(actionType
|
||||||
|
.getCategory().getName()
|
||||||
|
+ " cannot be perfomed by Gerrit"));
|
||||||
|
}
|
||||||
|
|
||||||
|
final Transaction txn = db.beginTransaction();
|
||||||
|
db.changes().update(Collections.singleton(change), txn);
|
||||||
|
if (change.getStatus().isClosed()) {
|
||||||
|
db.changeApprovals().update(fs.getDirtyChangeApprovals(), txn);
|
||||||
|
}
|
||||||
|
if (isnew) {
|
||||||
|
db.changeApprovals().insert(Collections.singleton(myAction), txn);
|
||||||
|
} else {
|
||||||
|
db.changeApprovals().update(Collections.singleton(myAction), txn);
|
||||||
|
}
|
||||||
|
txn.commit();
|
||||||
|
|
||||||
|
return VoidResult.INSTANCE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
// Copyright 2009 Google Inc.
|
||||||
|
//
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
|
||||||
|
/** Publishes {@link ChangeManageServiceImpl} over JSON. */
|
||||||
|
public class ChangeManageServiceSrv extends GerritJsonServlet {
|
||||||
|
@Override
|
||||||
|
protected Object createServiceHandle() throws Exception {
|
||||||
|
return new ChangeManageServiceImpl();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -114,6 +114,16 @@
|
|||||||
<url-pattern>/rpc/ChangeListService</url-pattern>
|
<url-pattern>/rpc/ChangeListService</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>ChangeManageService</servlet-name>
|
||||||
|
<servlet-class>com.google.gerrit.server.ChangeManageServiceSrv</servlet-class>
|
||||||
|
<load-on-startup>1</load-on-startup>
|
||||||
|
</servlet>
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>ChangeManageService</servlet-name>
|
||||||
|
<url-pattern>/rpc/ChangeManageService</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
<servlet>
|
<servlet>
|
||||||
<servlet-name>PatchDetailService</servlet-name>
|
<servlet-name>PatchDetailService</servlet-name>
|
||||||
<servlet-class>com.google.gerrit.server.PatchDetailServiceSrv</servlet-class>
|
<servlet-class>com.google.gerrit.server.PatchDetailServiceSrv</servlet-class>
|
||||||
|
|||||||
Reference in New Issue
Block a user