SideBySide2: Add range to PatchLineComment
Added a column named "range", a quadruple (start_line, start_character, end_line, end_character) that represents a comment range. Modified RPCs to include the range info. Updated schema to version 80. Change-Id: Idec295e15e3ab019ea04e4c2f3967eeecc0be55c
This commit is contained in:
@@ -18,6 +18,7 @@ import com.google.common.base.Strings;
|
||||
import com.google.gerrit.common.changes.Side;
|
||||
import com.google.gerrit.extensions.restapi.Url;
|
||||
import com.google.gerrit.reviewdb.client.PatchLineComment;
|
||||
import com.google.gerrit.reviewdb.client.CommentRange;
|
||||
import com.google.gerrit.server.account.AccountInfo;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
@@ -33,6 +34,7 @@ public class CommentInfo {
|
||||
String message;
|
||||
Timestamp updated;
|
||||
AccountInfo author;
|
||||
CommentRange range;
|
||||
|
||||
CommentInfo(PatchLineComment c, AccountInfo.Loader accountLoader) {
|
||||
id = Url.encode(c.getKey().get());
|
||||
@@ -46,6 +48,7 @@ public class CommentInfo {
|
||||
inReplyTo = Url.encode(c.getParentUuid());
|
||||
message = Strings.emptyToNull(c.getMessage());
|
||||
updated = c.getWrittenOn();
|
||||
range = c.getRange();
|
||||
if (accountLoader != null) {
|
||||
author = accountLoader.get(c.getAuthor());
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.extensions.restapi.Url;
|
||||
import com.google.gerrit.reviewdb.client.Patch;
|
||||
import com.google.gerrit.reviewdb.client.PatchLineComment;
|
||||
import com.google.gerrit.reviewdb.client.PatchLineComment.Status;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.ChangeUtil;
|
||||
import com.google.gerrit.server.change.PutDraft.Input;
|
||||
@@ -51,18 +50,22 @@ class CreateDraft implements RestModifyView<RevisionResource, Input> {
|
||||
throw new BadRequestException("message must be non-empty");
|
||||
} else if (in.line != null && in.line <= 0) {
|
||||
throw new BadRequestException("line must be > 0");
|
||||
} else if (in.line != null && in.range != null && in.line != in.range.getEndLine()) {
|
||||
throw new BadRequestException("range endLine must be on the same line as the comment");
|
||||
}
|
||||
|
||||
int line = in.line != null
|
||||
? in.line
|
||||
: in.range != null ? in.range.getEndLine() : 0;
|
||||
|
||||
PatchLineComment c = new PatchLineComment(
|
||||
new PatchLineComment.Key(
|
||||
new Patch.Key(rsrc.getPatchSet().getId(), in.path),
|
||||
ChangeUtil.messageUUID(db.get())),
|
||||
in.line != null ? in.line : 0,
|
||||
rsrc.getAccountId(),
|
||||
Url.decode(in.inReplyTo));
|
||||
c.setStatus(Status.DRAFT);
|
||||
line, rsrc.getAccountId(), Url.decode(in.inReplyTo));
|
||||
c.setSide(in.side == Side.PARENT ? (short) 0 : (short) 1);
|
||||
c.setMessage(in.message.trim());
|
||||
c.setRange(in.range);
|
||||
db.get().patchComments().insert(Collections.singleton(c));
|
||||
return Response.created(new CommentInfo(c, null));
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ import com.google.gerrit.reviewdb.client.ChangeMessage;
|
||||
import com.google.gerrit.reviewdb.client.Patch;
|
||||
import com.google.gerrit.reviewdb.client.PatchLineComment;
|
||||
import com.google.gerrit.reviewdb.client.PatchSetApproval;
|
||||
import com.google.gerrit.reviewdb.client.CommentRange;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.ChangeUtil;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
@@ -116,6 +117,7 @@ public class PostReview implements RestModifyView<RevisionResource, Input> {
|
||||
int line;
|
||||
String inReplyTo;
|
||||
String message;
|
||||
CommentRange range;
|
||||
}
|
||||
|
||||
static class Output {
|
||||
@@ -365,6 +367,7 @@ public class PostReview implements RestModifyView<RevisionResource, Input> {
|
||||
e.setWrittenOn(timestamp);
|
||||
e.setSide(c.side == Side.PARENT ? (short) 0 : (short) 1);
|
||||
e.setMessage(c.message);
|
||||
e.setRange(c.range);
|
||||
(create ? ins : upd).add(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.extensions.restapi.Url;
|
||||
import com.google.gerrit.reviewdb.client.Patch;
|
||||
import com.google.gerrit.reviewdb.client.PatchLineComment;
|
||||
import com.google.gerrit.reviewdb.client.CommentRange;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.change.PutDraft.Input;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
@@ -41,6 +42,7 @@ class PutDraft implements RestModifyView<DraftResource, Input> {
|
||||
Integer line;
|
||||
String inReplyTo;
|
||||
Timestamp updated; // Accepted but ignored.
|
||||
CommentRange range;
|
||||
|
||||
@DefaultInput
|
||||
String message;
|
||||
@@ -67,6 +69,8 @@ class PutDraft implements RestModifyView<DraftResource, Input> {
|
||||
throw new BadRequestException("id must match URL");
|
||||
} else if (in.line != null && in.line < 0) {
|
||||
throw new BadRequestException("line must be >= 0");
|
||||
} else if (in.line != null && in.range != null && in.line != in.range.getEndLine()) {
|
||||
throw new BadRequestException("range endLine must be on the same line as the comment");
|
||||
}
|
||||
|
||||
if (in.path != null
|
||||
@@ -92,13 +96,14 @@ class PutDraft implements RestModifyView<DraftResource, Input> {
|
||||
if (in.side != null) {
|
||||
e.setSide(in.side == Side.PARENT ? (short) 0 : (short) 1);
|
||||
}
|
||||
if (in.line != null) {
|
||||
e.setLine(in.line);
|
||||
}
|
||||
if (in.inReplyTo != null) {
|
||||
e.setParentUuid(Url.decode(in.inReplyTo));
|
||||
}
|
||||
e.setMessage(in.message.trim());
|
||||
if (in.range != null || in.line != null) {
|
||||
e.setRange(in.range);
|
||||
e.setLine(in.range != null ? in.range.getEndLine() : in.line);
|
||||
}
|
||||
e.updated();
|
||||
return e;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ import java.util.List;
|
||||
/** A version of the database schema. */
|
||||
public abstract class SchemaVersion {
|
||||
/** The current schema version. */
|
||||
public static final Class<Schema_79> C = Schema_79.class;
|
||||
public static final Class<Schema_80> C = Schema_80.class;
|
||||
|
||||
public static class Module extends AbstractModule {
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
// Copyright (C) 2013 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.server.schema;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
public class Schema_80 extends SchemaVersion {
|
||||
|
||||
@Inject
|
||||
Schema_80(Provider<Schema_79> prior) {
|
||||
super(prior);
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,7 @@ import com.google.gerrit.reviewdb.client.Patch;
|
||||
import com.google.gerrit.reviewdb.client.PatchLineComment;
|
||||
import com.google.gerrit.reviewdb.client.PatchLineComment.Status;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.client.CommentRange;
|
||||
import com.google.gerrit.reviewdb.server.PatchLineCommentAccess;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.account.AccountInfo;
|
||||
@@ -111,13 +112,13 @@ public class CommentsTest extends TestCase {
|
||||
long timeBase = System.currentTimeMillis();
|
||||
plc1 = newPatchLineComment(psId1, "Comment1", null,
|
||||
"FileOne.txt", Side.REVISION, 1, account1, timeBase,
|
||||
"First Comment");
|
||||
"First Comment", new CommentRange(1, 2, 3, 4));
|
||||
plc2 = newPatchLineComment(psId1, "Comment2", "Comment1",
|
||||
"FileOne.txt", Side.REVISION, 1, account2, timeBase + 1000,
|
||||
"Reply to First Comment");
|
||||
"Reply to First Comment", new CommentRange(1, 2, 3, 4));
|
||||
plc3 = newPatchLineComment(psId1, "Comment3", "Comment1",
|
||||
"FileOne.txt", Side.PARENT, 1, account1, timeBase + 2000,
|
||||
"First Parent Comment");
|
||||
"First Parent Comment", new CommentRange(1, 2, 3, 4));
|
||||
|
||||
expect(plca.publishedByPatchSet(psId1))
|
||||
.andAnswer(results(plc1, plc2, plc3)).anyTimes();
|
||||
@@ -206,16 +207,18 @@ public class CommentsTest extends TestCase {
|
||||
assertEquals(plc.getSide() == 0 ? Side.PARENT : Side.REVISION,
|
||||
Objects.firstNonNull(ci.side, Side.REVISION));
|
||||
assertEquals(plc.getWrittenOn(), ci.updated);
|
||||
assertEquals(plc.getRange(), ci.range);
|
||||
}
|
||||
|
||||
private static PatchLineComment newPatchLineComment(PatchSet.Id psId,
|
||||
String uuid, String inReplyToUuid, String filename, Side side, int line,
|
||||
Account.Id authorId, long millis, String message) {
|
||||
Account.Id authorId, long millis, String message, CommentRange range) {
|
||||
Patch.Key p = new Patch.Key(psId, filename);
|
||||
PatchLineComment.Key id = new PatchLineComment.Key(p, uuid);
|
||||
PatchLineComment plc =
|
||||
new PatchLineComment(id, line, authorId, inReplyToUuid);
|
||||
plc.setMessage(message);
|
||||
plc.setRange(range);
|
||||
plc.setSide(side == Side.PARENT ? (short) 0 : (short) 1);
|
||||
plc.setStatus(Status.PUBLISHED);
|
||||
plc.setWrittenOn(new Timestamp(millis));
|
||||
|
||||
Reference in New Issue
Block a user