use of com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput in project gerrit by GerritCodeReview.
the class ImpersonationIT method voteOnBehalfOfWithRobotComment.
@GerritConfig(name = "notedb.writeJson", value = "true")
@Test
public void voteOnBehalfOfWithRobotComment() throws Exception {
assume().that(notesMigration.readChanges()).isTrue();
allowCodeReviewOnBehalfOf();
PushOneCommit.Result r = createChange();
ReviewInput in = new ReviewInput();
in.onBehalfOf = user.id.toString();
in.label("Code-Review", 1);
RobotCommentInput ci = new RobotCommentInput();
ci.robotId = "my-robot";
ci.robotRunId = "abcd1234";
ci.path = Patch.COMMIT_MSG;
ci.side = Side.REVISION;
ci.line = 1;
ci.message = "message";
in.robotComments = ImmutableMap.of(ci.path, ImmutableList.of(ci));
gApi.changes().id(r.getChangeId()).current().review(in);
ChangeData cd = r.getChange();
RobotComment c = Iterables.getOnlyElement(commentsUtil.robotCommentsByChange(cd.notes()));
assertThat(c.message).isEqualTo(ci.message);
assertThat(c.robotId).isEqualTo(ci.robotId);
assertThat(c.robotRunId).isEqualTo(ci.robotRunId);
assertThat(c.author.getId()).isEqualTo(user.id);
assertThat(c.getRealAuthor().getId()).isEqualTo(admin.id);
}
use of com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput in project gerrit by GerritCodeReview.
the class PostReview method checkRobotComments.
private void checkRobotComments(RevisionResource revision, Map<String, List<RobotCommentInput>> in) throws BadRequestException, OrmException {
cleanUpComments(in);
for (Map.Entry<String, List<RobotCommentInput>> e : in.entrySet()) {
String commentPath = e.getKey();
for (RobotCommentInput c : e.getValue()) {
ensureSizeOfJsonInputIsWithinBounds(c);
ensureRobotIdIsSet(c.robotId, commentPath);
ensureRobotRunIdIsSet(c.robotRunId, commentPath);
ensureFixSuggestionsAreAddable(c.fixSuggestions, commentPath);
}
}
checkComments(revision, in);
}
use of com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput in project gerrit by GerritCodeReview.
the class AbstractQueryChangesTest method refStateFields.
@Test
public void refStateFields() throws Exception {
// This test method manages primary storage manually.
assume().that(notesMigration.changePrimaryStorage()).isEqualTo(PrimaryStorage.REVIEW_DB);
Account.Id user = createAccount("user");
Project.NameKey project = new Project.NameKey("repo");
TestRepository<Repo> repo = createProject(project.get());
String path = "file";
RevCommit commit = repo.parseBody(repo.commit().message("one").add(path, "contents").create());
Change change = insert(repo, newChangeForCommit(repo, commit));
Change.Id id = change.getId();
int c = id.get();
String changeId = change.getKey().get();
requestContext.setContext(newRequestContext(user));
// Ensure one of each type of supported ref is present for the change. If
// any more refs are added, update this test to reflect them.
// Edit
gApi.changes().id(changeId).edit().create();
// Star
gApi.accounts().self().starChange(change.getId().toString());
if (notesMigration.readChanges()) {
// Robot comment.
ReviewInput rin = new ReviewInput();
RobotCommentInput rcin = new RobotCommentInput();
rcin.robotId = "happyRobot";
rcin.robotRunId = "1";
rcin.line = 1;
rcin.message = "nit: trailing whitespace";
rcin.path = path;
rin.robotComments = ImmutableMap.of(path, ImmutableList.of(rcin));
gApi.changes().id(c).current().review(rin);
}
// Draft.
DraftInput din = new DraftInput();
din.path = path;
din.line = 1;
din.message = "draft";
gApi.changes().id(c).current().createDraft(din);
if (notesMigration.readChanges()) {
// Force NoteDb primary.
change = ReviewDbUtil.unwrapDb(db).changes().get(id);
change.setNoteDbState(NoteDbChangeState.NOTE_DB_PRIMARY_STATE);
ReviewDbUtil.unwrapDb(db).changes().update(Collections.singleton(change));
indexer.index(db, change);
}
QueryOptions opts = IndexedChangeQuery.createOptions(indexConfig, 0, 1, StalenessChecker.FIELDS);
ChangeData cd = indexes.getSearchIndex().get(id, opts).get();
String cs = RefNames.shard(c);
int u = user.get();
String us = RefNames.shard(u);
List<String> expectedStates = Lists.newArrayList("repo:refs/users/" + us + "/edit-" + c + "/1", "All-Users:refs/starred-changes/" + cs + "/" + u);
if (notesMigration.readChanges()) {
expectedStates.add("repo:refs/changes/" + cs + "/meta");
expectedStates.add("repo:refs/changes/" + cs + "/robot-comments");
expectedStates.add("All-Users:refs/draft-comments/" + cs + "/" + u);
}
assertThat(cd.getRefStates().stream().map(String::new).map(s -> s.substring(0, s.lastIndexOf(':'))).collect(toList())).containsExactlyElementsIn(expectedStates);
List<String> expectedPatterns = Lists.newArrayList("repo:refs/users/*/edit-" + c + "/*");
expectedPatterns.add("All-Users:refs/starred-changes/" + cs + "/*");
if (notesMigration.readChanges()) {
expectedPatterns.add("All-Users:refs/draft-comments/" + cs + "/*");
}
assertThat(cd.getRefStatePatterns().stream().map(String::new).collect(toList())).containsExactlyElementsIn(expectedPatterns);
}
Aggregations