Search in sources :

Example 1 with PATCHSET_LEVEL

use of com.google.gerrit.entities.Patch.PATCHSET_LEVEL in project gerrit by GerritCodeReview.

the class CommentSender method getGroupedInlineComments.

/**
 * Returns 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<>();
    // 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;
            // Get the modified files:
            Map<String, FileDiffOutput> modifiedFiles = null;
            try {
                modifiedFiles = listModifiedFiles(c.key.patchSetId);
            } catch (DiffNotAvailableException e) {
                logger.atSevere().withCause(e).log("Failed to get modified files");
            }
            groups.add(currentGroup);
            if (modifiedFiles != null && !modifiedFiles.isEmpty()) {
                try {
                    currentGroup.fileData = new PatchFile(repo, modifiedFiles, c.key.filename);
                } catch (IOException e) {
                    logger.atWarning().withCause(e).log("Cannot load %s from %s in %s", c.key.filename, modifiedFiles.values().iterator().next().newCommitId().name(), projectState.getName());
                    currentGroup.fileData = null;
                }
            }
        }
        if (currentGroup.filename.equals(PATCHSET_LEVEL) || currentGroup.fileData != null) {
            currentGroup.comments.add(c);
        }
    }
    groups.sort(Comparator.comparing(g -> g.filename, FilenameComparator.INSTANCE));
    return groups;
}
Also used : Patch(com.google.gerrit.entities.Patch) EmailException(com.google.gerrit.exceptions.EmailException) Protocol(com.google.gerrit.server.mail.receive.Protocol) Inject(com.google.inject.Inject) ZonedDateTime(java.time.ZonedDateTime) Comment(com.google.gerrit.entities.Comment) HumanComment(com.google.gerrit.entities.HumanComment) CommentsUtil(com.google.gerrit.server.CommentsUtil) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Assisted(com.google.inject.assistedinject.Assisted) HashSet(java.util.HashSet) PATCHSET_LEVEL(com.google.gerrit.entities.Patch.PATCHSET_LEVEL) Strings(com.google.common.base.Strings) Config(org.eclipse.jgit.lib.Config) DiffNotAvailableException(com.google.gerrit.server.patch.DiffNotAvailableException) FileDiffOutput(com.google.gerrit.server.patch.filediff.FileDiffOutput) Map(java.util.Map) RobotComment(com.google.gerrit.entities.RobotComment) NoSuchEntityException(com.google.gerrit.exceptions.NoSuchEntityException) Change(com.google.gerrit.entities.Change) FieldName(org.apache.james.mime4j.dom.field.FieldName) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) StorageException(com.google.gerrit.exceptions.StorageException) Account(com.google.gerrit.entities.Account) MailHeader(com.google.gerrit.mail.MailHeader) IOException(java.io.IOException) 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) NotifyType(com.google.gerrit.entities.NotifyConfig.NotifyType) Project(com.google.gerrit.entities.Project) MailProcessingUtil(com.google.gerrit.mail.MailProcessingUtil) LabelVote(com.google.gerrit.server.util.LabelVote) Optional(java.util.Optional) PatchFile(com.google.gerrit.server.patch.PatchFile) Comparator(java.util.Comparator) Collections(java.util.Collections) FluentLogger(com.google.common.flogger.FluentLogger) Repository(org.eclipse.jgit.lib.Repository) Comment(com.google.gerrit.entities.Comment) HumanComment(com.google.gerrit.entities.HumanComment) RobotComment(com.google.gerrit.entities.RobotComment) DiffNotAvailableException(com.google.gerrit.server.patch.DiffNotAvailableException) PatchFile(com.google.gerrit.server.patch.PatchFile) ArrayList(java.util.ArrayList) IOException(java.io.IOException) FileDiffOutput(com.google.gerrit.server.patch.filediff.FileDiffOutput)

Aggregations

Strings (com.google.common.base.Strings)1 FluentLogger (com.google.common.flogger.FluentLogger)1 FilenameComparator (com.google.gerrit.common.data.FilenameComparator)1 Account (com.google.gerrit.entities.Account)1 Change (com.google.gerrit.entities.Change)1 Comment (com.google.gerrit.entities.Comment)1 HumanComment (com.google.gerrit.entities.HumanComment)1 NotifyType (com.google.gerrit.entities.NotifyConfig.NotifyType)1 Patch (com.google.gerrit.entities.Patch)1 PATCHSET_LEVEL (com.google.gerrit.entities.Patch.PATCHSET_LEVEL)1 Project (com.google.gerrit.entities.Project)1 RobotComment (com.google.gerrit.entities.RobotComment)1 EmailException (com.google.gerrit.exceptions.EmailException)1 NoSuchEntityException (com.google.gerrit.exceptions.NoSuchEntityException)1 StorageException (com.google.gerrit.exceptions.StorageException)1 NotifyHandling (com.google.gerrit.extensions.api.changes.NotifyHandling)1 MailHeader (com.google.gerrit.mail.MailHeader)1 MailProcessingUtil (com.google.gerrit.mail.MailProcessingUtil)1 CommentsUtil (com.google.gerrit.server.CommentsUtil)1 GerritServerConfig (com.google.gerrit.server.config.GerritServerConfig)1