Search in sources :

Example 6 with PatchListNotAvailableException

use of com.google.gerrit.server.patch.PatchListNotAvailableException in project gerrit by GerritCodeReview.

the class CommentSender method getGroupedInlineComments.

/**
   * @return a list of FileCommentGroup objects representing the inline comments grouped by the
   *     file.
   */
private List<CommentSender.FileCommentGroup> getGroupedInlineComments(Repository repo) {
    List<CommentSender.FileCommentGroup> groups = new ArrayList<>();
    // Get the patch list:
    PatchList patchList = null;
    if (repo != null) {
        try {
            patchList = getPatchList();
        } catch (PatchListNotAvailableException e) {
            log.error("Failed to get patch list", e);
        }
    }
    // Loop over the comments and collect them into groups based on the file
    // location of the comment.
    FileCommentGroup currentGroup = null;
    for (Comment c : inlineComments) {
        // If it's a new group:
        if (currentGroup == null || !c.key.filename.equals(currentGroup.filename) || c.key.patchSetId != currentGroup.patchSetId) {
            currentGroup = new FileCommentGroup();
            currentGroup.filename = c.key.filename;
            currentGroup.patchSetId = c.key.patchSetId;
            groups.add(currentGroup);
            if (patchList != null) {
                try {
                    currentGroup.fileData = new PatchFile(repo, patchList, c.key.filename);
                } catch (IOException e) {
                    log.warn(String.format("Cannot load %s from %s in %s", c.key.filename, patchList.getNewId().name(), projectState.getProject().getName()), e);
                    currentGroup.fileData = null;
                }
            }
        }
        if (currentGroup.fileData != null) {
            currentGroup.comments.add(c);
        }
    }
    Collections.sort(groups, Comparator.comparing(g -> g.filename, FilenameComparator.INSTANCE));
    return groups;
}
Also used : PatchListNotAvailableException(com.google.gerrit.server.patch.PatchListNotAvailableException) OrmException(com.google.gwtorm.server.OrmException) Change(com.google.gerrit.reviewdb.client.Change) Protocol(com.google.gerrit.server.mail.receive.Protocol) Inject(com.google.inject.Inject) ZonedDateTime(java.time.ZonedDateTime) LoggerFactory(org.slf4j.LoggerFactory) CommentsUtil(com.google.gerrit.server.CommentsUtil) Patch(com.google.gerrit.reviewdb.client.Patch) HashMap(java.util.HashMap) KeyUtil(com.google.gwtorm.client.KeyUtil) ArrayList(java.util.ArrayList) Assisted(com.google.inject.assistedinject.Assisted) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) Comment(com.google.gerrit.reviewdb.client.Comment) Config(org.eclipse.jgit.lib.Config) Map(java.util.Map) MailUtil(com.google.gerrit.server.mail.MailUtil) PatchList(com.google.gerrit.server.patch.PatchList) Project(com.google.gerrit.reviewdb.client.Project) Logger(org.slf4j.Logger) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) EmailException(com.google.gerrit.common.errors.EmailException) Set(java.util.Set) IOException(java.io.IOException) NotifyType(com.google.gerrit.server.account.WatchConfig.NotifyType) ZoneId(java.time.ZoneId) NotifyHandling(com.google.gerrit.extensions.api.changes.NotifyHandling) Collectors.toList(java.util.stream.Collectors.toList) FilenameComparator(com.google.gerrit.common.data.FilenameComparator) List(java.util.List) Ordering(com.google.common.collect.Ordering) LabelVote(com.google.gerrit.server.util.LabelVote) Optional(java.util.Optional) NoSuchEntityException(com.google.gerrit.common.errors.NoSuchEntityException) PatchFile(com.google.gerrit.server.patch.PatchFile) Comparator(java.util.Comparator) Collections(java.util.Collections) Repository(org.eclipse.jgit.lib.Repository) RobotComment(com.google.gerrit.reviewdb.client.RobotComment) Comment(com.google.gerrit.reviewdb.client.Comment) RobotComment(com.google.gerrit.reviewdb.client.RobotComment) PatchList(com.google.gerrit.server.patch.PatchList) PatchFile(com.google.gerrit.server.patch.PatchFile) PatchListNotAvailableException(com.google.gerrit.server.patch.PatchListNotAvailableException) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Aggregations

PatchListNotAvailableException (com.google.gerrit.server.patch.PatchListNotAvailableException)6 IOException (java.io.IOException)5 PatchList (com.google.gerrit.server.patch.PatchList)3 OrmException (com.google.gwtorm.server.OrmException)3 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)2 Patch (com.google.gerrit.reviewdb.client.Patch)2 GpgException (com.google.gerrit.server.GpgException)2 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)2 Strings (com.google.common.base.Strings)1 Ordering (com.google.common.collect.Ordering)1 FilenameComparator (com.google.gerrit.common.data.FilenameComparator)1 EmailException (com.google.gerrit.common.errors.EmailException)1 NoSuchEntityException (com.google.gerrit.common.errors.NoSuchEntityException)1 NotifyHandling (com.google.gerrit.extensions.api.changes.NotifyHandling)1 Change (com.google.gerrit.reviewdb.client.Change)1 Comment (com.google.gerrit.reviewdb.client.Comment)1 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)1 Project (com.google.gerrit.reviewdb.client.Project)1 RobotComment (com.google.gerrit.reviewdb.client.RobotComment)1 UserIdentity (com.google.gerrit.reviewdb.client.UserIdentity)1