use of com.google.gerrit.extensions.api.changes.DraftInput in project gerrit by GerritCodeReview.
the class CommentsIT method listChangeWithDrafts.
@Test
public void listChangeWithDrafts() throws Exception {
for (Integer line : lines) {
PushOneCommit.Result r = createChange();
String changeId = r.getChangeId();
String revId = r.getCommit().getName();
DraftInput comment = newDraft("file1", Side.REVISION, line, "comment 1");
addDraft(changeId, revId, comment);
assertThat(gApi.changes().query("change:" + changeId + " has:draft").get()).hasSize(1);
}
}
use of com.google.gerrit.extensions.api.changes.DraftInput in project gerrit by GerritCodeReview.
the class ChangeRebuilderIT method putDraft.
private void putDraft(TestAccount account, Change.Id id, int line, String msg, Boolean unresolved) throws Exception {
DraftInput in = new DraftInput();
in.line = line;
in.message = msg;
in.path = PushOneCommit.FILE_NAME;
in.unresolved = unresolved;
AcceptanceTestRequestScope.Context old = setApiUser(account);
try {
gApi.changes().id(id.get()).current().createDraft(in);
} finally {
atrScope.set(old);
}
}
use of com.google.gerrit.extensions.api.changes.DraftInput in project gerrit by GerritCodeReview.
the class NoteDbPrimaryIT method deleteDraftComment.
@Test
public void deleteDraftComment() throws Exception {
PushOneCommit.Result r = createChange();
Change.Id id = r.getChange().getId();
setNoteDbPrimary(id);
DraftInput din = new DraftInput();
din.path = PushOneCommit.FILE_NAME;
din.line = 1;
din.message = "A comment";
gApi.changes().id(id.get()).current().createDraft(din);
CommentInfo di = Iterables.getOnlyElement(gApi.changes().id(id.get()).current().drafts().get(PushOneCommit.FILE_NAME));
assertThat(di.message).isEqualTo(din.message);
assertThat(db.patchComments().draftByChangeFileAuthor(id, din.path, admin.id)).isEmpty();
gApi.changes().id(id.get()).current().draft(di.id).delete();
assertThat(gApi.changes().id(id.get()).current().drafts()).isEmpty();
}
use of com.google.gerrit.extensions.api.changes.DraftInput in project gerrit by GerritCodeReview.
the class NoteDbPrimaryIT method rebuildReviewDb.
@Test
public void rebuildReviewDb() throws Exception {
Change c = createChange().getChange().change();
Change.Id id = c.getId();
CommentInput cin = new CommentInput();
cin.line = 1;
cin.message = "Published comment";
ReviewInput rin = ReviewInput.approve();
rin.comments = ImmutableMap.of(PushOneCommit.FILE_NAME, ImmutableList.of(cin));
gApi.changes().id(id.get()).current().review(ReviewInput.approve());
DraftInput din = new DraftInput();
din.path = PushOneCommit.FILE_NAME;
din.line = 1;
din.message = "Draft comment";
gApi.changes().id(id.get()).current().createDraft(din);
gApi.changes().id(id.get()).current().review(ReviewInput.approve());
gApi.changes().id(id.get()).current().createDraft(din);
assertThat(db.changeMessages().byChange(id)).isNotEmpty();
assertThat(db.patchSets().byChange(id)).isNotEmpty();
assertThat(db.patchSetApprovals().byChange(id)).isNotEmpty();
assertThat(db.patchComments().byChange(id)).isNotEmpty();
ChangeBundle noteDbBundle = ChangeBundle.fromNotes(commentsUtil, notesFactory.create(db, project, id));
setNoteDbPrimary(id);
db.changeMessages().delete(db.changeMessages().byChange(id));
db.patchSets().delete(db.patchSets().byChange(id));
db.patchSetApprovals().delete(db.patchSetApprovals().byChange(id));
db.patchComments().delete(db.patchComments().byChange(id));
ChangeMessage bogusMessage = ChangeMessagesUtil.newMessage(c.currentPatchSetId(), identifiedUserFactory.create(admin.getId()), TimeUtil.nowTs(), "some message", null);
db.changeMessages().insert(Collections.singleton(bogusMessage));
rebuilderWrapper.rebuildReviewDb(db, project, id);
assertThat(db.changeMessages().byChange(id)).isNotEmpty();
assertThat(db.patchSets().byChange(id)).isNotEmpty();
assertThat(db.patchSetApprovals().byChange(id)).isNotEmpty();
assertThat(db.patchComments().byChange(id)).isNotEmpty();
ChangeBundle reviewDbBundle = bundleReader.fromReviewDb(ReviewDbUtil.unwrapDb(db), id);
assertThat(reviewDbBundle.differencesFrom(noteDbBundle)).isEmpty();
}
use of com.google.gerrit.extensions.api.changes.DraftInput 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