class GitManager {

    public GitCommitEntry updateFiles(Pipeline pipeline, PipelineSourceItemsVO sourceItemVOList)
            throws GitClientException {
        if (CollectionUtils.isEmpty(sourceItemVOList.getItems())) {
            return null;
        }
        String lastCommitId = sourceItemVOList.getLastCommitId();
        Assert.isTrue(lastCommitId.equals(pipeline.getCurrentVersion().getCommitId()),
                messageHelper.getMessage(MessageConstants.ERROR_REPOSITORY_WAS_UPDATED));
        GitlabClient gitlabClient = getGitlabClientForPipeline(pipeline);
        GitPushCommitEntry gitPushCommitEntry = new GitPushCommitEntry();
        if (StringUtils.isNullOrEmpty(sourceItemVOList.getComment())) {
            gitPushCommitEntry.setCommitMessage(String.format("Updating files %s", StringUtils.join(", ",
                    String.valueOf(sourceItemVOList.getItems().stream().map(PipelineSourceItemVO::getPath)))));
        } else {
            gitPushCommitEntry.setCommitMessage(sourceItemVOList.getComment());
        }
        for (PipelineSourceItemVO sourceItemVO : sourceItemVOList.getItems()) {
            String sourcePath = sourceItemVO.getPath();
            Arrays.stream(sourcePath.split(PATH_DELIMITER)).forEach(pathPart ->
                    Assert.isTrue(GitUtils.checkGitNaming(pathPart),
                            messageHelper.getMessage(MessageConstants.ERROR_INVALID_PIPELINE_FILE_NAME, sourcePath)));

            String action;
            if (!StringUtils.isNullOrEmpty(sourceItemVO.getPreviousPath())) {
                action = ACTION_MOVE;
            } else {
                boolean fileExists = false;
                try {
                    fileExists = gitlabClient.getFileContents(sourcePath, GIT_MASTER_REPOSITORY) != null;
                } catch (UnexpectedResponseStatusException exception) {
                    LOGGER.debug(exception.getMessage(), exception);
                }
                if (fileExists) {
                    action = "update";
                } else {
                    action = "create";
                }
            }
            GitPushCommitActionEntry gitPushCommitActionEntry = new GitPushCommitActionEntry();
            gitPushCommitActionEntry.setFilePath(sourcePath);
            gitPushCommitActionEntry.setAction(action);
            if (StringUtils.isNullOrEmpty(sourceItemVO.getPreviousPath())) {
                gitPushCommitActionEntry.setContent(sourceItemVO.getContents());
            } else {
                gitPushCommitActionEntry.setPreviousPath(sourceItemVO.getPreviousPath());
            }
            gitPushCommitEntry.getActions().add(gitPushCommitActionEntry);
        }
        return gitlabClient.commit(gitPushCommitEntry);
    }

}