Port AddReviewer to new REST API

Reviewers can now be added by a POST to /changes/*/reviewers with body
containing the reviewer string to search for.

The new code closely parallels the old but is simplified where
possible. The new handler only supports putting a single reviewer,
which is all the old handler was ever used for. Error handling is also
simplified, using server-supplied error text.

The response body includes a list "reviewers" of reviewers that were
newly added (which may be empty if), or an "error" string and optional
"confirm" boolean. If "confirm" is true, the error text describes why
confirmation is required, and redoing the POST with "confirmed": true in
the JSON body indicates confirmation.

Change-Id: If3d72bc1d3be7f6b96bfae7819d8b4b575104eaa
This commit is contained in:
Dave Borowitz
2013-02-12 12:10:26 -08:00
committed by Edwin Kempin
parent d386499438
commit 675879a733
10 changed files with 405 additions and 51 deletions

View File

@@ -22,7 +22,6 @@ import com.google.gerrit.common.data.ApprovalTypes;
import com.google.gerrit.common.data.PermissionRange;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.ApprovalCategoryValue;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.PatchSetApproval;
import com.google.gerrit.reviewdb.server.ReviewDb;
@@ -58,7 +57,7 @@ public class ReviewerJson {
List<ReviewerInfo> infos = Lists.newArrayListWithCapacity(rsrcs.size());
AccountInfo.Loader loader = accountLoaderFactory.create(true);
for (ReviewerResource rsrc : rsrcs) {
ReviewerInfo info = formatOne(rsrc);
ReviewerInfo info = format(rsrc, null);
loader.put(info);
infos.add(info);
}
@@ -70,17 +69,15 @@ public class ReviewerJson {
return format(ImmutableList.<ReviewerResource> of(rsrc));
}
private ReviewerInfo formatOne(ReviewerResource rsrc) throws OrmException {
Account.Id id = rsrc.getUser().getAccountId();
ReviewerInfo out = new ReviewerInfo(id);
public ReviewerInfo format(ReviewerInfo out, ChangeControl control,
List<PatchSetApproval> approvals) throws OrmException {
PatchSet.Id psId = control.getChange().currentPatchSetId();
Change change = rsrc.getChange();
PatchSet.Id psId = change.currentPatchSetId();
if (approvals == null) {
approvals = db.get().patchSetApprovals()
.byPatchSetUser(psId, out._id).toList();
}
List<PatchSetApproval> approvals = db.get().patchSetApprovals()
.byPatchSetUser(psId, id).toList();
ChangeControl control = rsrc.getControl().forUser(rsrc.getUser());
FunctionState fs = functionState.create(control, psId, approvals);
for (ApprovalType at : approvalTypes.getApprovalTypes()) {
CategoryFunction.forCategory(at.getCategory()).run(at, fs);
@@ -106,6 +103,12 @@ public class ReviewerJson {
return out;
}
private ReviewerInfo format(ReviewerResource rsrc,
List<PatchSetApproval> approvals) throws OrmException {
return format(new ReviewerInfo(rsrc.getUser().getAccountId()),
rsrc.getUserControl(), approvals);
}
public static class ReviewerInfo extends AccountInfo {
final String kind = "gerritcodereview#reviewer";
Map<String, String> approvals;
@@ -114,4 +117,10 @@ public class ReviewerJson {
super(id);
}
}
public static class PostResult {
List<ReviewerInfo> reviewers;
Boolean confirm;
String error;
}
}