use of com.google.gerrit.extensions.common.ChangeInfo in project gerrit by GerritCodeReview.
the class CommentsIT method queryChangesWithUnresolvedCommentCount.
@Test
public void queryChangesWithUnresolvedCommentCount() throws Exception {
// PS1 has three comments in three different threads, PS2 has one comment in one thread.
PushOneCommit.Result result = createChange("change 1", FILE_NAME, "content 1");
String changeId1 = result.getChangeId();
addComment(result, "comment 1", false, true, null);
addComment(result, "comment 2", false, null, null);
addComment(result, "comment 3", false, false, null);
PushOneCommit.Result result2 = amendChange(changeId1);
addComment(result2, "comment4", false, true, null);
// Change2 has two comments in one thread, the first is unresolved and the second is resolved.
result = createChange("change 2", FILE_NAME, "content 2");
String changeId2 = result.getChangeId();
addComment(result, "comment 1", false, true, null);
Map<String, List<CommentInfo>> comments = getPublishedComments(changeId2, result.getCommit().name());
assertThat(comments).hasSize(1);
assertThat(comments.get(FILE_NAME)).hasSize(1);
addComment(result, "comment 2", false, false, comments.get(FILE_NAME).get(0).id);
// Change3 has two comments in one thread, the first is resolved, the second is unresolved.
result = createChange("change 3", FILE_NAME, "content 3");
String changeId3 = result.getChangeId();
addComment(result, "comment 1", false, false, null);
comments = getPublishedComments(result.getChangeId(), result.getCommit().name());
assertThat(comments).hasSize(1);
assertThat(comments.get(FILE_NAME)).hasSize(1);
addComment(result, "comment 2", false, true, comments.get(FILE_NAME).get(0).id);
AcceptanceTestRequestScope.Context ctx = disableDb();
try {
ChangeInfo changeInfo1 = Iterables.getOnlyElement(query(changeId1));
ChangeInfo changeInfo2 = Iterables.getOnlyElement(query(changeId2));
ChangeInfo changeInfo3 = Iterables.getOnlyElement(query(changeId3));
assertThat(changeInfo1.unresolvedCommentCount).isEqualTo(2);
assertThat(changeInfo2.unresolvedCommentCount).isEqualTo(0);
assertThat(changeInfo3.unresolvedCommentCount).isEqualTo(1);
} finally {
enableDb(ctx);
}
}
use of com.google.gerrit.extensions.common.ChangeInfo in project gerrit by GerritCodeReview.
the class ChangeJson method format.
private ChangeInfo format(ChangeData cd, Optional<PatchSet.Id> limitToPsId, boolean fillAccountLoader) throws OrmException {
try {
if (fillAccountLoader) {
accountLoader = accountLoaderFactory.create(has(DETAILED_ACCOUNTS));
ChangeInfo res = toChangeInfo(cd, limitToPsId);
accountLoader.fill();
return res;
}
return toChangeInfo(cd, limitToPsId);
} catch (PatchListNotAvailableException | GpgException | OrmException | IOException | PermissionBackendException | RuntimeException e) {
if (!has(CHECK)) {
Throwables.throwIfInstanceOf(e, OrmException.class);
throw new OrmException(e);
}
return checkOnly(cd);
}
}
use of com.google.gerrit.extensions.common.ChangeInfo in project gerrit by GerritCodeReview.
the class ChangeIT method createMergePatchSetInheritParent.
@Test
public void createMergePatchSetInheritParent() throws Exception {
PushOneCommit.Result start = pushTo("refs/heads/master");
start.assertOkStatus();
// create a change for master
PushOneCommit.Result r = createChange();
r.assertOkStatus();
String changeId = r.getChangeId();
String parent = r.getCommit().getParent(0).getName();
// advance master branch
testRepo.reset(start.getCommit());
PushOneCommit.Result currentMaster = pushTo("refs/heads/master");
currentMaster.assertOkStatus();
// push a commit into dev branch
createBranch(new Branch.NameKey(project, "dev"));
PushOneCommit.Result changeA = pushFactory.create(db, user.getIdent(), testRepo, "change A", "A.txt", "A content").to("refs/heads/dev");
changeA.assertOkStatus();
MergeInput mergeInput = new MergeInput();
mergeInput.source = "dev";
MergePatchSetInput in = new MergePatchSetInput();
in.merge = mergeInput;
in.subject = "update change by merge ps2 inherit parent of ps1";
in.inheritParent = true;
gApi.changes().id(changeId).createMergePatchSet(in);
ChangeInfo changeInfo = gApi.changes().id(changeId).get(EnumSet.of(ListChangesOption.ALL_REVISIONS, ListChangesOption.CURRENT_COMMIT, ListChangesOption.CURRENT_REVISION));
assertThat(changeInfo.revisions.size()).isEqualTo(2);
assertThat(changeInfo.subject).isEqualTo(in.subject);
assertThat(changeInfo.revisions.get(changeInfo.currentRevision).commit.parents.get(0).commit).isEqualTo(parent);
assertThat(changeInfo.revisions.get(changeInfo.currentRevision).commit.parents.get(0).commit).isNotEqualTo(currentMaster.getCommit().getName());
}
use of com.google.gerrit.extensions.common.ChangeInfo in project gerrit by GerritCodeReview.
the class ChangeIT method noteDbCommitsOnPatchSetCreation.
@Test
public void noteDbCommitsOnPatchSetCreation() throws Exception {
assume().that(notesMigration.readChanges()).isTrue();
PushOneCommit.Result r = createChange();
pushFactory.create(db, admin.getIdent(), testRepo, PushOneCommit.SUBJECT, "b.txt", "4711", r.getChangeId()).to("refs/for/master").assertOkStatus();
ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
try (Repository repo = repoManager.openRepository(project);
RevWalk rw = new RevWalk(repo)) {
RevCommit commitPatchSetCreation = rw.parseCommit(repo.exactRef(changeMetaRef(new Change.Id(c._number))).getObjectId());
assertThat(commitPatchSetCreation.getShortMessage()).isEqualTo("Create patch set 2");
PersonIdent expectedAuthor = changeNoteUtil.newIdent(accountCache.get(admin.id).getAccount(), c.updated, serverIdent.get(), AnonymousCowardNameProvider.DEFAULT);
assertThat(commitPatchSetCreation.getAuthorIdent()).isEqualTo(expectedAuthor);
assertThat(commitPatchSetCreation.getCommitterIdent()).isEqualTo(new PersonIdent(serverIdent.get(), c.updated));
assertThat(commitPatchSetCreation.getParentCount()).isEqualTo(1);
RevCommit commitChangeCreation = rw.parseCommit(commitPatchSetCreation.getParent(0));
assertThat(commitChangeCreation.getShortMessage()).isEqualTo("Create change");
expectedAuthor = changeNoteUtil.newIdent(accountCache.get(admin.id).getAccount(), c.created, serverIdent.get(), AnonymousCowardNameProvider.DEFAULT);
assertThat(commitChangeCreation.getAuthorIdent()).isEqualTo(expectedAuthor);
assertThat(commitChangeCreation.getCommitterIdent()).isEqualTo(new PersonIdent(serverIdent.get(), c.created));
assertThat(commitChangeCreation.getParentCount()).isEqualTo(0);
}
}
use of com.google.gerrit.extensions.common.ChangeInfo in project gerrit by GerritCodeReview.
the class ChangeReviewersIT method noteDbAddReviewerToReviewerChangeInfo.
@Test
public void noteDbAddReviewerToReviewerChangeInfo() throws Exception {
assume().that(notesMigration.readChanges()).isTrue();
PushOneCommit.Result r = createChange();
String changeId = r.getChangeId();
AddReviewerInput in = new AddReviewerInput();
in.reviewer = user.email;
in.state = CC;
addReviewer(changeId, in);
in.state = REVIEWER;
addReviewer(changeId, in);
gApi.changes().id(changeId).current().review(ReviewInput.dislike());
setApiUser(user);
// NoteDb adds reviewer to a change on every review.
gApi.changes().id(changeId).current().review(ReviewInput.dislike());
deleteReviewer(changeId, user).assertNoContent();
ChangeInfo c = gApi.changes().id(changeId).get();
assertThat(c.reviewerUpdates).isNotNull();
assertThat(c.reviewerUpdates).hasSize(3);
Iterator<ReviewerUpdateInfo> it = c.reviewerUpdates.iterator();
ReviewerUpdateInfo reviewerChange = it.next();
assertThat(reviewerChange.state).isEqualTo(CC);
assertThat(reviewerChange.reviewer._accountId).isEqualTo(user.getId().get());
assertThat(reviewerChange.updatedBy._accountId).isEqualTo(admin.getId().get());
reviewerChange = it.next();
assertThat(reviewerChange.state).isEqualTo(REVIEWER);
assertThat(reviewerChange.reviewer._accountId).isEqualTo(user.getId().get());
assertThat(reviewerChange.updatedBy._accountId).isEqualTo(admin.getId().get());
reviewerChange = it.next();
assertThat(reviewerChange.state).isEqualTo(REMOVED);
assertThat(reviewerChange.reviewer._accountId).isEqualTo(user.getId().get());
assertThat(reviewerChange.updatedBy._accountId).isEqualTo(admin.getId().get());
}
Aggregations