<commit_before>module RedmineGitolite

  module AdminRepositoriesHelper

    def handle_repository_add(repository, force = false)
      repo_name = repository.gitolite_repository_name
      repo_path = repository.gitolite_repository_path
      repo_conf = @gitolite_config.repos[repo_name]

      if !repo_conf
        logger.info { "#{@action} : repository '#{repo_name}' does not exist in Gitolite, create it ..." }
        logger.debug { "#{@action} : repository path '#{repo_path}'" }
      else
        if force == true
          logger.warn { "#{@action} : repository '#{repo_name}' already exists in Gitolite, force mode !" }
          logger.debug { "#{@action} : repository path '#{repo_path}'" }
          @gitolite_config.rm_repo(repo_name)
        else
          logger.warn { "#{@action} : repository '#{repo_name}' already exists in Gitolite, exit !" }
          logger.debug { "#{@action} : repository path '#{repo_path}'" }
          return false
        end
      end

      do_update_repository(repository)
    end


    def handle_repository_update(repository)
      repo_name = repository.gitolite_repository_name
      repo_path = repository.gitolite_repository_path
      repo_conf = @gitolite_config.repos[repo_name]

      if repo_conf
        logger.info { "#{@action} : repository '#{repo_name}' exists in Gitolite, update it ..." }
        logger.debug { "#{@action} : repository path '#{repo_path}'" }
        @gitolite_config.rm_repo(repo_name)
      else
        logger.warn { "#{@action} : repository '#{repo_name}' does not exist in Gitolite, exit !" }
        logger.debug { "#{@action} : repository path '#{repo_path}'" }
        return false
      end

      do_update_repository(repository)
    end


    def handle_repository_delete(repository_data)
      repo_name = repository_data['repo_name']
      repo_path = repository_data['repo_path']
      repo_conf = @gitolite_config.repos[repo_name]

      if !repo_conf
        logger.warn { "#{@action} : repository '#{repo_name}' does not exist in Gitolite, exit !" }
        logger.debug { "#{@action} : repository path '#{repo_path}'" }
        return false
      else
        logger.info { "#{@action} : repository '#{repo_name}' exists in Gitolite, delete it ..." }
        logger.debug { "#{@action} : repository path '#{repo_path}'" }
        @gitolite_config.rm_repo(repo_name)
      end
    end


    def handle_repositories_move(project)
      projects = project.self_and_descendants

      # Only take projects that have Git repos.
      git_projects = projects.uniq.select{|p| p.gitolite_repos.any?}
      return if git_projects.empty?

      git_projects.reverse.each do |project|
        repo_list = []

        project.gitolite_repos.reverse.each do |repository|
          repo_list.push(repository.gitolite_repository_name)
          do_move_repositories(repository)
        end

        gitolite_admin_repo_commit("#{@action} : #{project.identifier} | #{repo_list}")
      end
    end


    def do_update_repository(repository)
      repo_name = repository.gitolite_repository_name
      repo_conf = @gitolite_config.repos[repo_name]
      project   = repository.project

      # Create new repo object
      repo_conf = Gitolite::Config::Repo.new(repo_name)

      # Set post-receive hook params
      repo_conf.set_git_config("redmineGitolite.projectId", repository.project.identifier.to_s)
      repo_conf.set_git_config("redmineGitolite.repositoryId", "#{repository.identifier || ''}")
      repo_conf.set_git_config("redmineGitolite.repositoryKey", repository.extra.key)

      if User.anonymous.allowed_to?(:view_changesets, project) && (repository.extra.git_http == 1 || repository.extra.git_http == 2)
        repo_conf.set_git_config("http.uploadpack", 'true')
      else
        repo_conf.set_git_config("http.uploadpack", 'false')
      end

      # Set mail-notifications hook params<commit_msg>Allow repo cloning over http<commit_after>module RedmineGitolite

  module AdminRepositoriesHelper

    def handle_repository_add(repository, force = false)
      repo_name = repository.gitolite_repository_name
      repo_path = repository.gitolite_repository_path
      repo_conf = @gitolite_config.repos[repo_name]

      if !repo_conf
        logger.info { "#{@action} : repository '#{repo_name}' does not exist in Gitolite, create it ..." }
        logger.debug { "#{@action} : repository path '#{repo_path}'" }
      else
        if force == true
          logger.warn { "#{@action} : repository '#{repo_name}' already exists in Gitolite, force mode !" }
          logger.debug { "#{@action} : repository path '#{repo_path}'" }
          @gitolite_config.rm_repo(repo_name)
        else
          logger.warn { "#{@action} : repository '#{repo_name}' already exists in Gitolite, exit !" }
          logger.debug { "#{@action} : repository path '#{repo_path}'" }
          return false
        end
      end

      do_update_repository(repository)
    end


    def handle_repository_update(repository)
      repo_name = repository.gitolite_repository_name
      repo_path = repository.gitolite_repository_path
      repo_conf = @gitolite_config.repos[repo_name]

      if repo_conf
        logger.info { "#{@action} : repository '#{repo_name}' exists in Gitolite, update it ..." }
        logger.debug { "#{@action} : repository path '#{repo_path}'" }
        @gitolite_config.rm_repo(repo_name)
      else
        logger.warn { "#{@action} : repository '#{repo_name}' does not exist in Gitolite, exit !" }
        logger.debug { "#{@action} : repository path '#{repo_path}'" }
        return false
      end

      do_update_repository(repository)
    end


    def handle_repository_delete(repository_data)
      repo_name = repository_data['repo_name']
      repo_path = repository_data['repo_path']
      repo_conf = @gitolite_config.repos[repo_name]

      if !repo_conf
        logger.warn { "#{@action} : repository '#{repo_name}' does not exist in Gitolite, exit !" }
        logger.debug { "#{@action} : repository path '#{repo_path}'" }
        return false
      else
        logger.info { "#{@action} : repository '#{repo_name}' exists in Gitolite, delete it ..." }
        logger.debug { "#{@action} : repository path '#{repo_path}'" }
        @gitolite_config.rm_repo(repo_name)
      end
    end


    def handle_repositories_move(project)
      projects = project.self_and_descendants

      # Only take projects that have Git repos.
      git_projects = projects.uniq.select{|p| p.gitolite_repos.any?}
      return if git_projects.empty?

      git_projects.reverse.each do |project|
        repo_list = []

        project.gitolite_repos.reverse.each do |repository|
          repo_list.push(repository.gitolite_repository_name)
          do_move_repositories(repository)
        end

        gitolite_admin_repo_commit("#{@action} : #{project.identifier} | #{repo_list}")
      end
    end


    def do_update_repository(repository)
      repo_name = repository.gitolite_repository_name
      repo_conf = @gitolite_config.repos[repo_name]
      project   = repository.project

      # Create new repo object
      repo_conf = Gitolite::Config::Repo.new(repo_name)

      # Set post-receive hook params
      repo_conf.set_git_config("redmineGitolite.projectId", repository.project.identifier.to_s)
      repo_conf.set_git_config("redmineGitolite.repositoryId", "#{repository.identifier || ''}")
      repo_conf.set_git_config("redmineGitolite.repositoryKey", repository.extra.key)

      if User.anonymous.allowed_to?(:view_changesets, project) && (repository.extra.git_http == 1 || repository.extra.git_http == 2 || repository.extra.git_http == 3)
        repo_conf.set_git_config("http.uploadpack", 'true')
      else
        repo_conf.set_git_config("http.uploadpack", 'false')
      end

      # Set mail-notifications hook params
{'fraction_non_alphanumeric': 0.11414770560569468, 'fraction_numerical': 0.0006355662895640015, 'mean_word_length': 3.1043296817944706, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '669276', 'n_tokens_mistral': 2421, 'n_tokens_neox': 2304, 'n_words': 479}