class PipelineCodeHandler {

    public List<DocWriteRequest> processGitEvents(final Long id,
                                                  final List<PipelineEvent> events) throws EntityNotFoundException {
        return pipelineLoader.loadEntity(id).map(entry -> {
            final Pipeline pipeline = entry.getEntity().getPipeline();
            String indexNameForPipelineCode = String.format(
                    "%s%s-%d", indexPrefix, pipelineCodeIndexName, pipeline.getId());
            PermissionsContainer permissions = new PermissionsContainer(
                    cloudPipelineAPIClient.loadPermissionsForEntity(id, AclClass.PIPELINE));

            Map<String, List<GitEventDescription>> versionEvents = events
                    .stream()
                    .map(this::mapPipelineEventToGitEvent)
                    .collect(Collectors.groupingBy(event -> event.getEventData().getVersion()));

            return versionEvents.values().stream()
                    .map(e -> createRequestsForVersionEvents(e, indexNameForPipelineCode, pipeline, permissions))
                    .flatMap(Collection::stream)
                    .collect(Collectors.toList());
        }).orElse(Collections.emptyList());
    }

    public  PipelineCodeHandler(final @Value("${sync.index.common.prefix}") String indexPrefix,
                               final @Value("${sync.pipeline-code.index.name}") String pipelineCodeIndexName,
                               final CloudPipelineAPIClient cloudPipelineAPIClient,
                               final ElasticIndexService indexService,
                               final @Value("${sync.pipeline-code.index.paths}") String pipelineFileIndexPaths,
                               final ObjectMapper objectMapper,
                               final PipelineLoader pipelineLoader,
                               final PipelineCodeMapper codeMapper,
                               final @Value("${sync.pipeline-code.default-branch}") String defaultBranchName,
                               final @Value("${sync.pipeline-code.max.bytes:10240}") Integer codeLimitBytes);

}