Add support for Robot Comments
Extend the PostReview REST endpoint to support posting of robot comments. For this ReviewInput got a new field that can contain a list of robot comments. For reading robot comments new REST endpoints have been added. Robot comments are only supported with NoteDb, but not with ReviewDb. Robot comments are always stored as JSON, even if notedb.writeJson is set to false. In NoteDb robot comments are not stored in the change meta ref but in a separate refs/changes/XX/YYYY/robot-comments ref. By storing robot comments in a separate ref we can delete robot comments without rewriting the history of the change meta branch which is needed for auditing and hence cannot be rewritten. Deletion of robot comments is not implemented in this change, but we may want to support this later as the amount and size of robot comments can be large. Draft robot comments are not supported, but robot comments are always published comments. Change-Id: I2d8a5ca59e9a8b2c34863c54a3a9576599f69526 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -149,6 +149,7 @@ public final class Change {
|
||||
}
|
||||
int ce = nextNonDigit(ref, cs);
|
||||
if (ref.substring(ce).equals(RefNames.META_SUFFIX)
|
||||
|| ref.substring(ce).equals(RefNames.ROBOT_COMMENTS_SUFFIX)
|
||||
|| PatchSet.Id.fromRef(ref, ce) >= 0) {
|
||||
return new Change.Id(Integer.parseInt(ref.substring(cs, ce)));
|
||||
}
|
||||
|
||||
@@ -68,6 +68,9 @@ public class RefNames {
|
||||
/** Suffix of a meta ref in the NoteDb. */
|
||||
public static final String META_SUFFIX = "/meta";
|
||||
|
||||
/** Suffix of a ref that stores robot comments in the NoteDb. */
|
||||
public static final String ROBOT_COMMENTS_SUFFIX = "/robot-comments";
|
||||
|
||||
public static final String EDIT_PREFIX = "edit-";
|
||||
|
||||
public static String fullName(String ref) {
|
||||
@@ -92,6 +95,14 @@ public class RefNames {
|
||||
return r.toString();
|
||||
}
|
||||
|
||||
public static String robotCommentsRef(Change.Id id) {
|
||||
StringBuilder r = new StringBuilder();
|
||||
r.append(REFS_CHANGES);
|
||||
r.append(shard(id.get()));
|
||||
r.append(ROBOT_COMMENTS_SUFFIX);
|
||||
return r.toString();
|
||||
}
|
||||
|
||||
public static String refsUsers(Account.Id accountId) {
|
||||
StringBuilder r = new StringBuilder();
|
||||
r.append(REFS_USERS);
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
// Copyright (C) 2016 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.reviewdb.client;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Objects;
|
||||
|
||||
public class RobotComment extends Comment {
|
||||
public String robotId;
|
||||
public String robotRunId;
|
||||
public String url;
|
||||
|
||||
public RobotComment(Key key, Account.Id author, Timestamp writtenOn,
|
||||
short side, String message, String serverId, String robotId,
|
||||
String robotRunId) {
|
||||
super(key, author, writtenOn, side, message, serverId);
|
||||
this.robotId = robotId;
|
||||
this.robotRunId = robotRunId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringBuilder()
|
||||
.append("RobotComment{")
|
||||
.append("key=").append(key).append(',')
|
||||
.append("robotId=").append(robotId).append(',')
|
||||
.append("robotRunId=").append(robotRunId).append(',')
|
||||
.append("lineNbr=").append(lineNbr).append(',')
|
||||
.append("author=").append(author.getId().get()).append(',')
|
||||
.append("writtenOn=").append(writtenOn.toString()).append(',')
|
||||
.append("side=").append(side).append(',')
|
||||
.append("message=").append(Objects.toString(message, "")).append(',')
|
||||
.append("parentUuid=")
|
||||
.append(Objects.toString(parentUuid, "")).append(',')
|
||||
.append("range=").append(Objects.toString(range, "")).append(',')
|
||||
.append("revId=").append(revId != null ? revId : "").append(',')
|
||||
.append("tag=").append(Objects.toString(tag, "")).append(',')
|
||||
.append("url=").append(url)
|
||||
.append('}')
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user