Class CommentsUtil

java.lang.Object
com.google.gerrit.server.CommentsUtil

public class CommentsUtil extends Object
Utility functions to manipulate Comments.
  • Field Details

    • COMMENT_ORDER

      public static final com.google.common.collect.Ordering<Comment> COMMENT_ORDER
    • COMMENT_INFO_ORDER

      public static final com.google.common.collect.Ordering<CommentInfo> COMMENT_INFO_ORDER
  • Method Details

    • getCommentPsId

      public static PatchSet.Id getCommentPsId(Change.Id changeId, Comment comment)
    • extractMessageId

      public static String extractMessageId(String tag)
    • newHumanComment

      public HumanComment newHumanComment(ChangeNotes changeNotes, CurrentUser currentUser, Instant when, String path, PatchSet.Id psId, short side, String message, Boolean unresolved, String parentUuid)
    • newRobotComment

      public RobotComment newRobotComment(ChangeContext ctx, String path, PatchSet.Id psId, short side, String message, String robotId, String robotRunId)
    • getPublishedHumanComment

      public Optional<HumanComment> getPublishedHumanComment(ChangeNotes notes, Comment.Key key)
    • getPublishedHumanComment

      public Optional<HumanComment> getPublishedHumanComment(ChangeNotes notes, String uuid)
    • publishedHumanCommentsByChange

      public List<HumanComment> publishedHumanCommentsByChange(ChangeNotes notes)
    • robotCommentsByChange

      public List<RobotComment> robotCommentsByChange(ChangeNotes notes)
    • getRobotComment

      public Optional<RobotComment> getRobotComment(ChangeNotes notes, String uuid)
    • publishedByChangeFile

      public List<HumanComment> publishedByChangeFile(ChangeNotes notes, String file)
    • publishedByPatchSet

      public List<HumanComment> publishedByPatchSet(ChangeNotes notes, PatchSet.Id psId)
    • robotCommentsByPatchSet

      public List<RobotComment> robotCommentsByPatchSet(ChangeNotes notes, PatchSet.Id psId)
    • linkCommentsToChangeMessages

      public static void linkCommentsToChangeMessages(List<? extends CommentInfo> comments, List<ChangeMessage> changeMessages, boolean skipAutoGeneratedMessages)
      This method populates the "changeMessageId" field of the comments parameter based on timestamp matching. The comments objects will be modified.

      Each comment will be matched to the nearest next change message in timestamp

      Parameters:
      comments - the list of comments
      changeMessages - list of change messages
    • draftByPatchSetAuthor

      public List<HumanComment> draftByPatchSetAuthor(PatchSet.Id psId, Account.Id author, ChangeNotes notes)
    • draftByChangeAuthor

      public List<HumanComment> draftByChangeAuthor(ChangeNotes notes, Account.Id author)
    • putHumanComments

      public void putHumanComments(ChangeUpdate update, Comment.Status status, Iterable<HumanComment> comments)
    • putRobotComments

      public void putRobotComments(ChangeUpdate update, Iterable<RobotComment> comments)
    • deleteHumanComments

      public void deleteHumanComments(ChangeUpdate update, Iterable<HumanComment> comments)
    • deleteCommentByRewritingHistory

      public void deleteCommentByRewritingHistory(ChangeUpdate update, Comment.Key commentKey, String newMessage)
    • setCommentCommitId

      public void setCommentCommitId(Comment c, Change change, PatchSet ps)
    • determineCommitId

      public Optional<org.eclipse.jgit.lib.ObjectId> determineCommitId(Change change, PatchSet patchset, short side)
      Determines the SHA-1 of the commit referenced by the (change, patchset, side) triple.
      Parameters:
      change - the change to which the commit belongs
      patchset - the patchset to which the commit belongs
      side - the side indicating which commit of the patchset to take. 1 is the patchset commit, 0 the parent commit (or auto-merge for changes representing merge commits); -x the xth parent commit of a merge commit
      Returns:
      the commit SHA-1 or an empty Optional if the side isn't available for the given change/patchset
      Throws:
      com.google.gerrit.exceptions.StorageException - if the SHA-1 is unavailable for an unknown reason
    • getDraftRefs

      public Collection<org.eclipse.jgit.lib.Ref> getDraftRefs(Change.Id changeId)
      Get NoteDb draft refs for a change.

      This is just a simple ref scan, so the results may potentially include refs for zombie draft comments. A zombie draft is one which has been published but the write to delete the draft ref from All-Users failed.

      Parameters:
      changeId - change ID.
      Returns:
      raw refs from All-Users repo.
    • sort

      public static <T extends Comment> List<T> sort(List<T> comments)