use of com.google.gerrit.entities.HumanComment in project gerrit by GerritCodeReview.
the class CommentThreadsTest method completeThreadCanBeRequestedByReplyToRootComment.
@Test
public void completeThreadCanBeRequestedByReplyToRootComment() {
HumanComment root = createComment("root");
HumanComment child = asReply(createComment("child"), "root");
HumanComment reply = asReply(createComment("reply"), "root");
ImmutableList<HumanComment> comments = ImmutableList.of(root, child);
ImmutableSet<CommentThread<HumanComment>> commentThreads = CommentThreads.forComments(comments).getThreadsForChildren(ImmutableList.of(reply));
ImmutableSet<CommentThread<HumanComment>> expectedThreads = ImmutableSet.of(toThread(root, child));
assertThat(commentThreads).isEqualTo(expectedThreads);
}
use of com.google.gerrit.entities.HumanComment in project gerrit by GerritCodeReview.
the class AbstractParserTest method newRangeComment.
protected static HumanComment newRangeComment(String uuid, String file, String message, int line) {
HumanComment c = new HumanComment(new Comment.Key(uuid, file, 1), Account.id(0), Instant.EPOCH, (short) 0, message, "", false);
c.range = new Comment.Range(line, 1, line + 1, 1);
c.lineNbr = line + 1;
return c;
}
use of com.google.gerrit.entities.HumanComment in project gerrit by GerritCodeReview.
the class AbstractParserTest method newComment.
protected static HumanComment newComment(String uuid, String file, String message, int line) {
HumanComment c = new HumanComment(new Comment.Key(uuid, file, 1), Account.id(0), Instant.EPOCH, (short) 0, message, "", false);
c.lineNbr = line;
return c;
}
use of com.google.gerrit.entities.HumanComment in project gerrit by GerritCodeReview.
the class ReceiveCommits method requestReplaceAndValidateComments.
/**
* Update an existing change. If draft comments are to be published, these are validated and may
* be withheld.
*
* @return True if the command succeeded, false if it was rejected.
*/
private boolean requestReplaceAndValidateComments(ReceiveCommand cmd, boolean checkMergedInto, Change change, RevCommit newCommit) throws IOException {
try (TraceTimer traceTimer = newTimer("requestReplaceAndValidateComments")) {
if (change.isClosed()) {
reject(cmd, changeFormatter.changeClosed(ChangeReportFormatter.Input.builder().setChange(change).build()));
return false;
}
ReplaceRequest req = new ReplaceRequest(change.getId(), newCommit, cmd, checkMergedInto);
if (replaceByChange.containsKey(req.ontoChange)) {
reject(cmd, "duplicate request");
return false;
}
if (magicBranch != null && magicBranch.shouldPublishComments()) {
List<HumanComment> drafts = commentsUtil.draftByChangeAuthor(notesFactory.createChecked(change), user.getAccountId());
ImmutableList<CommentForValidation> draftsForValidation = drafts.stream().map(comment -> CommentForValidation.create(CommentSource.HUMAN, comment.lineNbr > 0 ? CommentType.INLINE_COMMENT : CommentType.FILE_COMMENT, comment.message, comment.message.length())).collect(toImmutableList());
CommentValidationContext ctx = CommentValidationContext.create(change.getChangeId(), change.getProject().get(), change.getDest().branch());
ImmutableList<CommentValidationFailure> commentValidationFailures = PublishCommentUtil.findInvalidComments(ctx, commentValidators, draftsForValidation);
magicBranch.setWithholdComments(!commentValidationFailures.isEmpty());
commentValidationFailures.forEach(failure -> addMessage("Comment validation failure: " + failure.getMessage(), ValidationMessage.Type.WARNING));
}
replaceByChange.put(req.ontoChange, req);
return true;
}
}
use of com.google.gerrit.entities.HumanComment in project gerrit by GerritCodeReview.
the class CommitRewriter method collectAccounts.
/**
* Retrieves accounts, that are associated with a change (e.g. reviewers, commenters, etc.). These
* accounts are used to verify that commits do not contain user data. See {@link #verifyCommit}
*
* @param changeNotes {@link ChangeNotes} of the change to retrieve associated accounts from.
* @return {@link AccountState} of accounts, that are associated with the change.
*/
private ImmutableSet<AccountState> collectAccounts(ChangeNotes changeNotes) {
Set<Account.Id> accounts = new HashSet<>();
accounts.add(changeNotes.getChange().getOwner());
for (PatchSetApproval patchSetApproval : changeNotes.getApprovals().values()) {
if (patchSetApproval.accountId() != null) {
accounts.add(patchSetApproval.accountId());
}
if (patchSetApproval.realAccountId() != null) {
accounts.add(patchSetApproval.realAccountId());
}
}
accounts.addAll(changeNotes.getAllPastReviewers());
accounts.addAll(changeNotes.getPastAssignees());
changeNotes.getAttentionSetUpdates().forEach(attentionSetUpdate -> accounts.add(attentionSetUpdate.account()));
for (SubmitRecord submitRecord : changeNotes.getSubmitRecords()) {
if (submitRecord.labels != null) {
accounts.addAll(submitRecord.labels.stream().map(label -> label.appliedBy).filter(Objects::nonNull).collect(Collectors.toSet()));
}
}
for (HumanComment comment : changeNotes.getHumanComments().values()) {
if (comment.author != null) {
accounts.add(comment.author.getId());
}
if (comment.getRealAuthor() != null) {
accounts.add(comment.getRealAuthor().getId());
}
}
return ImmutableSet.copyOf(accountCache.get(accounts).values());
}
Aggregations