Search in sources :

Example 6 with PatchList

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

the class ChangeEmail method getChangeDetail.

/** Create the change message and the affected file list. */
public String getChangeDetail() {
    try {
        StringBuilder detail = new StringBuilder();
        if (patchSetInfo != null) {
            detail.append(patchSetInfo.getMessage().trim()).append("\n");
        } else {
            detail.append(change.getSubject().trim()).append("\n");
        }
        if (patchSet != null) {
            detail.append("---\n");
            PatchList patchList = getPatchList();
            for (PatchListEntry p : patchList.getPatches()) {
                if (Patch.isMagic(p.getNewName())) {
                    continue;
                }
                detail.append(p.getChangeType().getCode()).append(" ").append(p.getNewName()).append("\n");
            }
            detail.append(MessageFormat.format(//
            "" + //
            "{0,choice,0#0 files|1#1 file|1<{0} files} changed, " + //
            "{1,choice,0#0 insertions|1#1 insertion|1<{1} insertions}(+), " + //
            "{2,choice,0#0 deletions|1#1 deletion|1<{2} deletions}(-)" + "\n", //
            patchList.getPatches().size() - 1, //
            patchList.getInsertions(), patchList.getDeletions()));
            detail.append("\n");
        }
        return detail.toString();
    } catch (Exception err) {
        log.warn("Cannot format change detail", err);
        return "";
    }
}
Also used : PatchList(com.google.gerrit.server.patch.PatchList) PatchListEntry(com.google.gerrit.server.patch.PatchListEntry) PatchListNotAvailableException(com.google.gerrit.server.patch.PatchListNotAvailableException) OrmException(com.google.gwtorm.server.OrmException) PatchSetInfoNotAvailableException(com.google.gerrit.server.patch.PatchSetInfoNotAvailableException) EmailException(com.google.gerrit.common.errors.EmailException) IOException(java.io.IOException)

Example 7 with PatchList

use of com.google.gerrit.server.patch.PatchList 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)

Example 8 with PatchList

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

the class EventFactory method addPatchSetFileNames.

public void addPatchSetFileNames(PatchSetAttribute patchSetAttribute, Change change, PatchSet patchSet) {
    try {
        PatchList patchList = patchListCache.get(change, patchSet);
        for (PatchListEntry patch : patchList.getPatches()) {
            if (patchSetAttribute.files == null) {
                patchSetAttribute.files = new ArrayList<>();
            }
            PatchAttribute p = new PatchAttribute();
            p.file = patch.getNewName();
            p.fileOld = patch.getOldName();
            p.type = patch.getChangeType();
            p.deletions -= patch.getDeletions();
            p.insertions = patch.getInsertions();
            patchSetAttribute.files.add(p);
        }
    } catch (PatchListNotAvailableException e) {
        log.warn("Cannot get patch list", e);
    }
}
Also used : PatchAttribute(com.google.gerrit.server.data.PatchAttribute) PatchList(com.google.gerrit.server.patch.PatchList) PatchListNotAvailableException(com.google.gerrit.server.patch.PatchListNotAvailableException) PatchListEntry(com.google.gerrit.server.patch.PatchListEntry)

Aggregations

PatchList (com.google.gerrit.server.patch.PatchList)8 PatchListEntry (com.google.gerrit.server.patch.PatchListEntry)5 PatchListNotAvailableException (com.google.gerrit.server.patch.PatchListNotAvailableException)4 IOException (java.io.IOException)4 Term (com.googlecode.prolog_cafe.lang.Term)3 EmailException (com.google.gerrit.common.errors.EmailException)2 OrmException (com.google.gwtorm.server.OrmException)2 SymbolTerm (com.googlecode.prolog_cafe.lang.SymbolTerm)2 VariableTerm (com.googlecode.prolog_cafe.lang.VariableTerm)2 Pattern (java.util.regex.Pattern)2 Repository (org.eclipse.jgit.lib.Repository)2 Strings (com.google.common.base.Strings)1 Ordering (com.google.common.collect.Ordering)1 FilenameComparator (com.google.gerrit.common.data.FilenameComparator)1 NoSuchEntityException (com.google.gerrit.common.errors.NoSuchEntityException)1 NotifyHandling (com.google.gerrit.extensions.api.changes.NotifyHandling)1 FileInfo (com.google.gerrit.extensions.common.FileInfo)1 Change (com.google.gerrit.reviewdb.client.Change)1 Comment (com.google.gerrit.reviewdb.client.Comment)1 Patch (com.google.gerrit.reviewdb.client.Patch)1