use of com.google.gerrit.entities.HumanComment in project gerrit by GerritCodeReview.
the class ReceiveCommits method insertChangesAndPatchSets.
private void insertChangesAndPatchSets(ImmutableList<CreateRequest> newChanges, Task replaceProgress) {
try (TraceTimer traceTimer = newTimer("insertChangesAndPatchSets", Metadata.builder().resourceCount(newChanges.size()))) {
ReceiveCommand magicBranchCmd = magicBranch != null ? magicBranch.cmd : null;
if (magicBranchCmd != null && magicBranchCmd.getResult() != NOT_ATTEMPTED) {
logger.atWarning().log("Skipping change updates on %s because ref update failed: %s %s", project.getName(), magicBranchCmd.getResult(), Strings.nullToEmpty(magicBranchCmd.getMessage()));
return;
}
try (BatchUpdate bu = batchUpdateFactory.create(project.getNameKey(), user.materializedCopy(), TimeUtil.now());
ObjectInserter ins = repo.newObjectInserter();
ObjectReader reader = ins.newReader();
RevWalk rw = new RevWalk(reader)) {
bu.setRepository(repo, rw, ins);
bu.setRefLogMessage("push");
if (magicBranch != null) {
bu.setNotify(magicBranch.getNotifyForNewChange());
}
logger.atFine().log("Adding %d replace requests", newChanges.size());
for (ReplaceRequest replace : replaceByChange.values()) {
replace.addOps(bu, replaceProgress);
if (magicBranch != null) {
bu.setNotifyHandling(replace.ontoChange, magicBranch.getNotifyHandling(replace.notes));
if (magicBranch.shouldPublishComments()) {
bu.addOp(replace.notes.getChangeId(), publishCommentsOp.create(replace.psId, project.getNameKey()));
Optional<ChangeNotes> changeNotes = getChangeNotes(replace.notes.getChangeId());
if (!changeNotes.isPresent()) {
// If not present, no need to update attention set here since this is a new change.
continue;
}
List<HumanComment> drafts = commentsUtil.draftByChangeAuthor(changeNotes.get(), user.getAccountId());
if (drafts.isEmpty()) {
// If no comments, attention set shouldn't update since the user didn't reply.
continue;
}
replyAttentionSetUpdates.processAutomaticAttentionSetRulesOnReply(bu, changeNotes.get(), isReadyForReview(changeNotes.get()), user, drafts);
}
}
}
logger.atFine().log("Adding %d create requests", newChanges.size());
for (CreateRequest create : newChanges) {
create.addOps(bu);
}
logger.atFine().log("Adding %d group update requests", newChanges.size());
updateGroups.forEach(r -> r.addOps(bu));
logger.atFine().log("Executing batch");
try {
bu.execute();
} catch (UpdateException e) {
throw asRestApiException(e);
}
replaceByChange.values().stream().forEach(req -> result.addChange(ReceiveCommitsResult.ChangeStatus.REPLACED, req.ontoChange));
newChanges.stream().forEach(req -> result.addChange(ReceiveCommitsResult.ChangeStatus.CREATED, req.changeId));
if (magicBranchCmd != null) {
magicBranchCmd.setResult(OK);
}
for (ReplaceRequest replace : replaceByChange.values()) {
String rejectMessage = replace.getRejectMessage();
if (rejectMessage == null) {
if (replace.inputCommand.getResult() == NOT_ATTEMPTED) {
// Not necessarily the magic branch, so need to set OK on the original value.
replace.inputCommand.setResult(OK);
}
} else {
logger.atFine().log("Rejecting due to message from ReplaceOp");
reject(replace.inputCommand, rejectMessage);
}
}
} catch (ResourceConflictException e) {
addError(e.getMessage());
reject(magicBranchCmd, "conflict");
} catch (BadRequestException | UnprocessableEntityException | AuthException e) {
logger.atFine().withCause(e).log("Rejecting due to client error");
reject(magicBranchCmd, e.getMessage());
} catch (RestApiException | IOException e) {
throw new StorageException("Can't insert change/patch set for " + project.getName(), e);
}
if (magicBranch != null && magicBranch.submit) {
try {
submit(newChanges, replaceByChange.values());
} catch (ResourceConflictException e) {
addError(e.getMessage());
reject(magicBranchCmd, "conflict");
} catch (RestApiException | StorageException | UpdateException | IOException | ConfigInvalidException | PermissionBackendException e) {
logger.atSevere().withCause(e).log("Error submitting changes to %s", project.getName());
reject(magicBranchCmd, "error during submit");
}
}
}
}
use of com.google.gerrit.entities.HumanComment in project gerrit by GerritCodeReview.
the class ListPortedComments method apply.
@Override
public Response<Map<String, List<CommentInfo>>> apply(RevisionResource revisionResource) throws PermissionBackendException {
PatchSet targetPatchset = revisionResource.getPatchSet();
List<HumanComment> allComments = commentsUtil.publishedHumanCommentsByChange(revisionResource.getNotes());
ImmutableList<HumanComment> portedComments = commentPorter.portComments(revisionResource.getNotes(), targetPatchset, allComments, ImmutableList.of(new UnresolvedCommentFilter()));
return Response.ok(format(portedComments));
}
use of com.google.gerrit.entities.HumanComment in project gerrit by GerritCodeReview.
the class DraftComments method parse.
@Override
public DraftCommentResource parse(RevisionResource rev, IdString id) throws ResourceNotFoundException, AuthException {
checkIdentifiedUser();
String uuid = id.get();
for (HumanComment c : commentsUtil.draftByPatchSetAuthor(rev.getPatchSet().id(), rev.getAccountId(), rev.getNotes())) {
if (uuid.equals(c.key.uuid)) {
return new DraftCommentResource(rev, c);
}
}
throw new ResourceNotFoundException(id);
}
use of com.google.gerrit.entities.HumanComment in project gerrit by GerritCodeReview.
the class ListPortedDrafts method apply.
@Override
public Response<Map<String, List<CommentInfo>>> apply(RevisionResource revisionResource) throws PermissionBackendException, RestApiException {
if (!revisionResource.getUser().isIdentifiedUser()) {
throw new AuthException("requires authentication; only authenticated users can have drafts");
}
PatchSet targetPatchset = revisionResource.getPatchSet();
List<HumanComment> draftComments = commentsUtil.draftByChangeAuthor(revisionResource.getNotes(), revisionResource.getAccountId());
ImmutableList<HumanComment> portedDraftComments = commentPorter.portComments(revisionResource.getNotes(), targetPatchset, draftComments, ImmutableList.of());
return Response.ok(format(portedDraftComments));
}
use of com.google.gerrit.entities.HumanComment in project gerrit by GerritCodeReview.
the class ChangeNotesStateTest method serializePublishedComments.
@Test
public void serializePublishedComments() throws Exception {
HumanComment c1 = new HumanComment(new Comment.Key("uuid1", "file1", 1), Account.id(1001), Instant.ofEpochMilli(1212L), (short) 1, "message 1", "serverId", false);
c1.setCommitId(ObjectId.fromString("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
String c1Json = Serializer.GSON.toJson(c1);
HumanComment c2 = new HumanComment(new Comment.Key("uuid2", "file2", 2), Account.id(1002), Instant.ofEpochMilli(3434L), (short) 2, "message 2", "serverId", true);
c2.setCommitId(ObjectId.fromString("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"));
String c2Json = Serializer.GSON.toJson(c2);
assertRoundTrip(newBuilder().publishedComments(ImmutableListMultimap.of(c2.getCommitId(), c2, c1.getCommitId(), c1)).build(), ChangeNotesStateProto.newBuilder().setMetaId(SHA_BYTES).setChangeId(ID.get()).setColumns(colsProto).addPublishedComment(c2Json).addPublishedComment(c1Json).build());
}
Aggregations