use of com.google.gerrit.entities.PatchSet 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 IOException {
LabelTypes labelTypes = d.getLabelTypes();
ChangeAttribute c = eventFactory.asChangeAttribute(d.change(), d.notes());
eventFactory.extend(c, d.change());
if (!trackingFooters.isEmpty()) {
eventFactory.addTrackingIds(c, d.trackingFooters());
}
if (includeAllReviewers) {
eventFactory.addAllReviewers(c, d.notes());
}
if (includeSubmitRecords) {
SubmitRuleOptions options = SubmitRuleOptions.builder().recomputeOnClosedChanges(true).build();
eventFactory.addSubmitRecords(c, submitRuleEvaluatorFactory.create(options).evaluate(d));
}
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(rw, c, d.patchSets(), includeApprovals ? d.approvals().asMap() : null, includeFiles, d.change(), labelTypes);
}
if (includeCurrentPatchSet) {
PatchSet current = d.currentPatchSet();
if (current != null) {
c.currentPatchSet = eventFactory.asPatchSetAttribute(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(rw, c, d.patchSets(), 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());
}
List<PluginDefinedInfo> pluginInfos = pluginInfosByChange.get(d.getId());
if (!pluginInfos.isEmpty()) {
c.plugins = pluginInfos;
}
return c;
}
use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.
the class UserInPredicate method match.
@Override
public boolean match(ApprovalContext ctx) {
Account.Id accountId;
if (field == Field.UPLOADER) {
PatchSet patchSet = ctx.target();
accountId = patchSet.uploader();
} else if (field == Field.APPROVER) {
accountId = ctx.patchSetApproval().accountId();
} else {
throw new IllegalStateException("unknown field in group membership check: " + field);
}
return identifiedUserFactory.create(accountId).getEffectiveGroups().contains(group);
}
use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.
the class ChangeData method isMergeable.
@Nullable
public Boolean isMergeable() {
if (mergeable == null) {
Change c = change();
if (c == null) {
return null;
}
if (c.isMerged()) {
mergeable = true;
} else if (c.isAbandoned()) {
return null;
} else if (c.isWorkInProgress()) {
return null;
} else {
if (!lazyload()) {
return null;
}
PatchSet ps = currentPatchSet();
if (ps == null) {
return null;
}
try (Repository repo = repoManager.openRepository(project())) {
Ref ref = repo.getRefDatabase().exactRef(c.getDest().branch());
SubmitTypeRecord str = submitTypeRecord();
if (!str.isOk()) {
// No need to log, as SubmitRuleEvaluator already did it for us.
return false;
}
String mergeStrategy = mergeUtilFactory.create(projectCache.get(project()).orElseThrow(illegalState(project()))).mergeStrategyName();
mergeable = mergeabilityCache.get(ps.commitId(), ref, str.type, mergeStrategy, c.getDest(), repo);
} catch (IOException e) {
throw new StorageException(e);
}
}
}
return mergeable;
}
use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.
the class PortedCommentsIT method portedDraftCommentHasPatchsetFilled.
@Test
public void portedDraftCommentHasPatchsetFilled() throws Exception {
// Set up change and patchsets.
Account.Id authorId = accountOps.newAccount().create();
Change.Id changeId = changeOps.newChange().create();
PatchSet.Id patchset1Id = changeOps.change(changeId).currentPatchset().get().patchsetId();
PatchSet.Id patchset2Id = changeOps.change(changeId).newPatchset().create();
// Add comment.
String commentUuid = newDraftComment(patchset1Id).author(authorId).create();
Map<String, List<CommentInfo>> portedComments = getPortedDraftCommentsOfUser(patchset2Id, authorId);
CommentInfo portedComment = extractSpecificComment(portedComments, commentUuid);
// We explicitly need to request that the patchset field is filled, which we could have missed
// for drafts. -> Test that aspect. Don't verify the actual patchset number as that's already
// covered by the previous test.
assertThat(portedComment).patchSet().isNotNull();
}
use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.
the class CommentsIT method updatedDraftStillPointsToParentComment.
@Test
public void updatedDraftStillPointsToParentComment() throws Exception {
Account.Id accountId = accountOperations.newAccount().create();
Change.Id changeId = changeOperations.newChange().create();
PatchSet.Id patchsetId = changeOperations.change(changeId).currentPatchset().get().patchsetId();
String parentCommentUuid = changeOperations.change(changeId).patchset(patchsetId).newComment().create();
String draftCommentUuid = changeOperations.change(changeId).patchset(patchsetId).newDraftComment().parentUuid(parentCommentUuid).author(accountId).create();
// Each user can only see their own drafts.
requestScopeOperations.setApiUser(accountId);
DraftInput draftInput = CommentsUtil.newDraft(FILE_NAME, Side.REVISION, 0, "bar");
draftInput.message = "Another comment text.";
gApi.changes().id(changeId.get()).revision(patchsetId.get()).draft(draftCommentUuid).update(draftInput);
TestHumanComment comment = changeOperations.change(changeId).draftComment(draftCommentUuid).get();
assertThat(comment.parentUuid()).hasValue(parentCommentUuid);
}
Aggregations