Search in sources :

Example 1 with PositionedEntity

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

the class CommentPorter method portSamePatchsetAndSide.

private ImmutableList<HumanComment> portSamePatchsetAndSide(Project.NameKey project, Change change, PatchSet originalPatchset, PatchSet targetPatchset, List<HumanComment> comments, short side) {
    try (TraceTimer ignored = TraceContext.newTimer("Porting comments same patchset and side", Metadata.builder().projectName(project.get()).changeId(change.getChangeId()).patchSetId(originalPatchset.number()).commentSide(side).build())) {
        ImmutableSet<Mapping> mappings;
        try {
            mappings = loadMappings(project, change, originalPatchset, targetPatchset, side);
        } catch (Exception e) {
            logger.atWarning().withCause(e).log("Could not determine some necessary diff mappings for porting comments on change %s" + " from patchset %s to patchset %s. Mapping %d affected comments to the fallback" + " destination.", change.getChangeId(), originalPatchset.id().getId(), targetPatchset.id().getId(), comments.size());
            mappings = getFallbackMappings(comments);
        }
        ImmutableList<PositionedEntity<HumanComment>> positionedComments = comments.stream().map(this::toPositionedEntity).collect(toImmutableList());
        ImmutableMap<PositionedEntity<HumanComment>, HumanComment> origToPortedMap = positionTransformer.transform(positionedComments, mappings).stream().collect(ImmutableMap.toImmutableMap(Function.identity(), PositionedEntity::getEntityAtUpdatedPosition));
        collectMetrics(origToPortedMap);
        return ImmutableList.copyOf(origToPortedMap.values());
    }
}
Also used : PositionedEntity(com.google.gerrit.server.patch.GitPositionTransformer.PositionedEntity) TraceTimer(com.google.gerrit.server.logging.TraceContext.TraceTimer) Mapping(com.google.gerrit.server.patch.GitPositionTransformer.Mapping) FileMapping(com.google.gerrit.server.patch.GitPositionTransformer.FileMapping) HumanComment(com.google.gerrit.entities.HumanComment) DiffNotAvailableException(com.google.gerrit.server.patch.DiffNotAvailableException)

Example 2 with PositionedEntity

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

the class CommentPorter method collectMetrics.

/**
 * Collect metrics from the original and ported comments.
 *
 * @param portMap map of the ported comments. The keys contain a {@link PositionedEntity} of the
 *     original comment, and the values contain the transformed comments.
 */
private void collectMetrics(ImmutableMap<PositionedEntity<HumanComment>, HumanComment> portMap) {
    for (Map.Entry<PositionedEntity<HumanComment>, HumanComment> entry : portMap.entrySet()) {
        HumanComment original = entry.getKey().getEntity();
        HumanComment transformed = entry.getValue();
        if (!Patch.isMagic(original.key.filename)) {
            if (Patch.PATCHSET_LEVEL.equals(transformed.key.filename)) {
                metrics.portedAsPatchsetLevel.increment();
            } else if (extractLineRange(original).isPresent()) {
                if (extractLineRange(transformed).isPresent()) {
                    metrics.portedAsRangeComments.increment();
                } else {
                    // line range was present in the original comment, but the ported comment is a file
                    // level comment.
                    metrics.portedAsFileLevel.increment();
                }
            }
        }
    }
}
Also used : PositionedEntity(com.google.gerrit.server.patch.GitPositionTransformer.PositionedEntity) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HumanComment(com.google.gerrit.entities.HumanComment)

Aggregations

HumanComment (com.google.gerrit.entities.HumanComment)2 PositionedEntity (com.google.gerrit.server.patch.GitPositionTransformer.PositionedEntity)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 TraceTimer (com.google.gerrit.server.logging.TraceContext.TraceTimer)1 DiffNotAvailableException (com.google.gerrit.server.patch.DiffNotAvailableException)1 FileMapping (com.google.gerrit.server.patch.GitPositionTransformer.FileMapping)1 Mapping (com.google.gerrit.server.patch.GitPositionTransformer.Mapping)1 Map (java.util.Map)1