<commit_before>require 'gitolite'
require 'lockfile'

module RedmineGitolite

  class Admin

    include RedmineGitolite::AdminHelper

    def initialize(object_id, action, options)
      @gitolite_admin_dir                = RedmineGitolite::Config.gitolite_admin_dir
      @gitolite_config_file              = RedmineGitolite::ConfigRedmine.get_setting(:gitolite_config_file)
      @gitolite_default_config_file      = RedmineGitolite::Config::GITOLITE_DEFAULT_CONFIG_FILE
      @gitolite_config_file_path         = File.join(@gitolite_admin_dir, 'conf', @gitolite_config_file)
      @gitolite_default_config_file_path = File.join(@gitolite_admin_dir, 'conf', @gitolite_default_config_file)
      @gitolite_identifier_prefix        = RedmineGitolite::ConfigRedmine.get_setting(:gitolite_identifier_prefix)

      @delete_git_repositories   = RedmineGitolite::ConfigRedmine.get_setting(:delete_git_repositories, true)
      @gitolite_server_port      = RedmineGitolite::ConfigRedmine.get_setting(:gitolite_server_port)
      @gitolite_admin_url        = RedmineGitolite::Config.gitolite_admin_url
      @gitolite_admin_ssh_script_path = RedmineGitolite::Config.gitolite_admin_ssh_script_path
      @lock_file_path = File.join(RedmineGitolite::Config.get_temp_dir_path, 'redmine_git_hosting_lock')

      @object_id      = object_id
      @action         = action
      @options        = options
    end


    def purge_recycle_bin
      repositories_array = @object_id
      recycle = RedmineGitolite::Recycle.new
      recycle.delete_expired_files(repositories_array)
      logger.info { "#{@action} : done !" }
    end


    private


    def logger
      RedmineGitolite::Log.get_logger(:worker)
    end


    def gitolite_admin_repo_clone

      ## Get or clone Gitolite Admin repo
      if (File.exists? "#{@gitolite_admin_dir}") && (File.exists? "#{@gitolite_admin_dir}/.git") && (File.exists? "#{@gitolite_admin_dir}/keydir") && (File.exists? "#{@gitolite_admin_dir}/conf")
        @gitolite_admin = Gitolite::GitoliteAdmin.new(@gitolite_admin_dir)
      else
        logger.info { "Clone Gitolite Admin Repo : #{@gitolite_admin_url} (port : #{@gitolite_server_port}) to #{@gitolite_admin_dir}" }

        begin
          RedmineGitolite::GitHosting.execute_command(:local_cmd, "rm -rf '#{@gitolite_admin_dir}'")
          RedmineGitolite::GitHosting.execute_command(:local_cmd, "export GIT_SSH=#{@gitolite_admin_ssh_script_path} && git clone ssh://#{@gitolite_admin_url} #{@gitolite_admin_dir}")
          RedmineGitolite::GitHosting.execute_command(:local_cmd, "chmod 700 '#{@gitolite_admin_dir}'")
        rescue RedmineGitolite::GitHosting::GitHostingException => e
          logger.error { e.command }
          logger.error { e.output }
          logger.error { "Cannot clone Gitolite Admin repository !!" }
          return false
        end

        @gitolite_admin = Gitolite::GitoliteAdmin.new(@gitolite_admin_dir)
      end

      ## Set Gitolite config file
      if @gitolite_config_file != @gitolite_default_config_file
        if !File.exists?(@gitolite_config_file_path)<commit_msg>Pass debug parameter to GitoliteAdmin<commit_after>require 'gitolite'
require 'lockfile'

module RedmineGitolite

  class Admin

    include RedmineGitolite::AdminHelper

    def initialize(object_id, action, options)
      @gitolite_admin_dir                = RedmineGitolite::Config.gitolite_admin_dir
      @gitolite_config_file              = RedmineGitolite::ConfigRedmine.get_setting(:gitolite_config_file)
      @gitolite_default_config_file      = RedmineGitolite::Config::GITOLITE_DEFAULT_CONFIG_FILE
      @gitolite_config_file_path         = File.join(@gitolite_admin_dir, 'conf', @gitolite_config_file)
      @gitolite_default_config_file_path = File.join(@gitolite_admin_dir, 'conf', @gitolite_default_config_file)
      @gitolite_identifier_prefix        = RedmineGitolite::ConfigRedmine.get_setting(:gitolite_identifier_prefix)

      @delete_git_repositories   = RedmineGitolite::ConfigRedmine.get_setting(:delete_git_repositories, true)
      @gitolite_server_port      = RedmineGitolite::ConfigRedmine.get_setting(:gitolite_server_port)
      @gitolite_admin_url        = RedmineGitolite::Config.gitolite_admin_url
      @gitolite_admin_ssh_script_path = RedmineGitolite::Config.gitolite_admin_ssh_script_path
      @lock_file_path = File.join(RedmineGitolite::Config.get_temp_dir_path, 'redmine_git_hosting_lock')
      @gitolite_debug = RedmineGitolite::ConfigRedmine.get_setting(:gitolite_log_level) == 'debug' ? true : false

      @object_id      = object_id
      @action         = action
      @options        = options
    end


    def purge_recycle_bin
      repositories_array = @object_id
      recycle = RedmineGitolite::Recycle.new
      recycle.delete_expired_files(repositories_array)
      logger.info { "#{@action} : done !" }
    end


    private


    def logger
      RedmineGitolite::Log.get_logger(:worker)
    end


    def gitolite_admin_repo_clone

      ## Get or clone Gitolite Admin repo
      if (File.exists? "#{@gitolite_admin_dir}") && (File.exists? "#{@gitolite_admin_dir}/.git") && (File.exists? "#{@gitolite_admin_dir}/keydir") && (File.exists? "#{@gitolite_admin_dir}/conf")
        @gitolite_admin = Gitolite::GitoliteAdmin.new(@gitolite_admin_dir, :debug => @gitolite_debug)
      else
        logger.info { "Clone Gitolite Admin Repo : #{@gitolite_admin_url} (port : #{@gitolite_server_port}) to #{@gitolite_admin_dir}" }

        begin
          RedmineGitolite::GitHosting.execute_command(:local_cmd, "rm -rf '#{@gitolite_admin_dir}'")
          RedmineGitolite::GitHosting.execute_command(:local_cmd, "export GIT_SSH=#{@gitolite_admin_ssh_script_path} && git clone ssh://#{@gitolite_admin_url} #{@gitolite_admin_dir}")
          RedmineGitolite::GitHosting.execute_command(:local_cmd, "chmod 700 '#{@gitolite_admin_dir}'")
        rescue RedmineGitolite::GitHosting::GitHostingException => e
          logger.error { e.command }
          logger.error { e.output }
          logger.error { "Cannot clone Gitolite Admin repository !!" }
          return false
        end

        @gitolite_admin = Gitolite::GitoliteAdmin.new(@gitolite_admin_dir, :debug => @gitolite_debug)
      end

      ## Set Gitolite config file
      if @gitolite_config_file != @gitolite_default_config_file
        if !File.exists?(@gitolite_config_file_path)
{'fraction_non_alphanumeric': 0.10121836925960637, 'fraction_numerical': 0.0009372071227741331, 'mean_word_length': 3.9674166020170674, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '7032484', 'n_tokens_mistral': 2185, 'n_tokens_neox': 2039, 'n_words': 292}