use of com.google.gerrit.server.data.ChangeAttribute in project gerrit by GerritCodeReview.
the class OutputStreamQuery method buildChangeAttribute.
private ChangeAttribute buildChangeAttribute(ChangeData d, Map<Project.NameKey, Repository> repos, Map<Project.NameKey, RevWalk> revWalks) throws OrmException, IOException {
ChangeControl cc = d.changeControl().forUser(user);
LabelTypes labelTypes = cc.getLabelTypes();
ChangeAttribute c = eventFactory.asChangeAttribute(db, d.change());
eventFactory.extend(c, d.change());
if (!trackingFooters.isEmpty()) {
eventFactory.addTrackingIds(c, trackingFooters.extract(d.commitFooters()));
}
if (includeAllReviewers) {
eventFactory.addAllReviewers(db, c, d.notes());
}
if (includeSubmitRecords) {
eventFactory.addSubmitRecords(c, new SubmitRuleEvaluator(d).setAllowClosed(true).setAllowDraft(true).evaluate());
}
if (includeCommitMessage) {
eventFactory.addCommitMessage(c, d.commitMessage());
}
RevWalk rw = null;
if (includePatchSets || includeCurrentPatchSet || includeDependencies) {
Project.NameKey p = d.change().getProject();
rw = revWalks.get(p);
// Cache and reuse repos and revwalks.
if (rw == null) {
Repository repo = repoManager.openRepository(p);
checkState(repos.put(p, repo) == null);
rw = new RevWalk(repo);
revWalks.put(p, rw);
}
}
if (includePatchSets) {
eventFactory.addPatchSets(db, rw, c, d.visiblePatchSets(), includeApprovals ? d.approvals().asMap() : null, includeFiles, d.change(), labelTypes);
}
if (includeCurrentPatchSet) {
PatchSet current = d.currentPatchSet();
if (current != null && cc.isPatchVisible(current, d.db())) {
c.currentPatchSet = eventFactory.asPatchSetAttribute(db, rw, d.change(), current);
eventFactory.addApprovals(c.currentPatchSet, d.currentApprovals(), labelTypes);
if (includeFiles) {
eventFactory.addPatchSetFileNames(c.currentPatchSet, d.change(), d.currentPatchSet());
}
if (includeComments) {
eventFactory.addPatchSetComments(c.currentPatchSet, d.publishedComments());
}
}
}
if (includeComments) {
eventFactory.addComments(c, d.messages());
if (includePatchSets) {
eventFactory.addPatchSets(db, rw, c, d.visiblePatchSets(), includeApprovals ? d.approvals().asMap() : null, includeFiles, d.change(), labelTypes);
for (PatchSetAttribute attribute : c.patchSets) {
eventFactory.addPatchSetComments(attribute, d.publishedComments());
}
}
}
if (includeDependencies) {
eventFactory.addDependencies(rw, c, d.change(), d.currentPatchSet());
}
c.plugins = queryProcessor.create(d);
return c;
}
use of com.google.gerrit.server.data.ChangeAttribute in project gerrit by GerritCodeReview.
the class QueryIT method allReviewersOptionJSON.
@Test
public void allReviewersOptionJSON() throws Exception {
String changeId = createChange().getChangeId();
AddReviewerInput in = new AddReviewerInput();
in.reviewer = user.email;
gApi.changes().id(changeId).addReviewer(in);
List<ChangeAttribute> changes = executeSuccessfulQuery(changeId);
assertThat(changes.size()).isEqualTo(1);
assertThat(changes.get(0).allReviewers).isNull();
changes = executeSuccessfulQuery("--all-reviewers " + changeId);
assertThat(changes.size()).isEqualTo(1);
assertThat(changes.get(0).allReviewers).isNotNull();
assertThat(changes.get(0).allReviewers.size()).isEqualTo(1);
}
use of com.google.gerrit.server.data.ChangeAttribute in project gerrit by GerritCodeReview.
the class QueryIT method commentOptionInPatchSetsJSON.
@Test
public void commentOptionInPatchSetsJSON() throws Exception {
String changeId = createChange().getChangeId();
ReviewInput review = new ReviewInput();
ReviewInput.CommentInput comment = new ReviewInput.CommentInput();
comment.path = PushOneCommit.FILE_NAME;
comment.side = Side.REVISION;
comment.message = "comment 1";
review.comments = new HashMap<>();
review.comments.put(comment.path, Lists.newArrayList(comment));
gApi.changes().id(changeId).current().review(review);
List<ChangeAttribute> changes = executeSuccessfulQuery("--patch-sets " + changeId);
assertThat(changes.size()).isEqualTo(1);
assertThat(changes.get(0).patchSets.get(0).comments).isNull();
changes = executeSuccessfulQuery("--patch-sets --comments " + changeId);
assertThat(changes.size()).isEqualTo(1);
assertThat(changes.get(0).patchSets.get(0).comments).isNotNull();
assertThat(changes.get(0).patchSets.get(0).comments.size()).isEqualTo(1);
changes = executeSuccessfulQuery("--patch-sets --comments --files " + changeId);
assertThat(changes.size()).isEqualTo(1);
assertThat(changes.get(0).patchSets.get(0).comments).isNotNull();
assertThat(changes.get(0).patchSets.get(0).comments.size()).isEqualTo(1);
assertThat(changes.get(0).patchSets.get(0).files).isNotNull();
assertThat(changes.get(0).patchSets.get(0).files.size()).isEqualTo(2);
gApi.changes().id(changeId).current().review(ReviewInput.approve());
changes = executeSuccessfulQuery("--patch-sets --comments --files --all-approvals " + changeId);
assertThat(changes.size()).isEqualTo(1);
assertThat(changes.get(0).patchSets.get(0).comments).isNotNull();
assertThat(changes.get(0).patchSets.get(0).comments.size()).isEqualTo(1);
assertThat(changes.get(0).patchSets.get(0).files).isNotNull();
assertThat(changes.get(0).patchSets.get(0).files.size()).isEqualTo(2);
assertThat(changes.get(0).patchSets.get(0).approvals).isNotNull();
assertThat(changes.get(0).patchSets.get(0).approvals.size()).isEqualTo(1);
}
use of com.google.gerrit.server.data.ChangeAttribute in project gerrit by GerritCodeReview.
the class QueryIT method queryWithNonVisibleCurrentPatchSet.
@Test
public void queryWithNonVisibleCurrentPatchSet() throws Exception {
String changeId = createChange().getChangeId();
amendChangeAsDraft(changeId);
String query = "--current-patch-set --patch-sets " + changeId;
List<ChangeAttribute> changes = executeSuccessfulQuery(query);
assertThat(changes.size()).isEqualTo(1);
assertThat(changes.get(0).patchSets).isNotNull();
assertThat(changes.get(0).patchSets).hasSize(2);
assertThat(changes.get(0).currentPatchSet).isNotNull();
SshSession userSession = new SshSession(server, user);
initSsh(user);
userSession.open();
changes = executeSuccessfulQuery(query, userSession);
assertThat(changes.size()).isEqualTo(1);
assertThat(changes.get(0).patchSets).hasSize(1);
assertThat(changes.get(0).currentPatchSet).isNull();
userSession.close();
}
use of com.google.gerrit.server.data.ChangeAttribute in project gerrit by GerritCodeReview.
the class QueryIT method commentOptionsInCurrentPatchSetJSON.
@Test
public void commentOptionsInCurrentPatchSetJSON() throws Exception {
String changeId = createChange().getChangeId();
ReviewInput review = new ReviewInput();
ReviewInput.CommentInput comment = new ReviewInput.CommentInput();
comment.path = PushOneCommit.FILE_NAME;
comment.side = Side.REVISION;
comment.message = "comment 1";
review.comments = new HashMap<>();
review.comments.put(comment.path, Lists.newArrayList(comment));
gApi.changes().id(changeId).current().review(review);
List<ChangeAttribute> changes = executeSuccessfulQuery("--current-patch-set " + changeId);
assertThat(changes.size()).isEqualTo(1);
assertThat(changes.get(0).currentPatchSet.comments).isNull();
changes = executeSuccessfulQuery("--current-patch-set --comments " + changeId);
assertThat(changes.size()).isEqualTo(1);
assertThat(changes.get(0).currentPatchSet.comments).isNotNull();
assertThat(changes.get(0).currentPatchSet.comments.size()).isEqualTo(1);
}
Aggregations