<commit_before>require 'zadar/services/detect_iso_remote_type'
require 'zadar/adapters/remote_iso_repo'

module Zadar
  module Services
    class AddRemoteIsoRepo < Service
      attr_reader :name, :url

      def initialize options
        @name = options[:name].to_s
        @url  = options[:url].to_s

        failure! "Remote iso repository name is missing" if name.empty?
        failure! "Remote iso repository url is missing"  if url.empty?
      end

      def call
        super do
          repo_type = Services::DetectIsoRemoteType.new(url: url).call.type
          report "Detected repository type '#{repo_type}'"
          remote = Adapters::RemoteIsoRepo.new(type: repo_type.to_s, url: url)
          remote.validate!
          create_repo_dir
          new_repo = Models::RemoteIsoRepo.create(url: url, name: name)
          remote.files.each do |file|
            Models::RemoteIsoFile.create(file.to_h)
          end
          report "Repository '#{name}' has been created successfuly"
          report "#{remote.files.size} files has been detected"
        end
      end

      def create_repo_dir
        FileUtils.mkdir_p(File.join(
          Zadar.current_project.path,
          'iso',<commit_msg>Add check for iso dir presence<commit_after>require 'zadar/services/detect_iso_remote_type'
require 'zadar/adapters/remote_iso_repo'

module Zadar
  module Services
    class AddRemoteIsoRepo < Service
      attr_reader :name, :url

      def initialize options
        @name = options[:name].to_s
        @url  = options[:url].to_s

        failure! "Remote iso repository name is missing" if name.empty?
        failure! "Remote iso repository url is missing"  if url.empty?
      end

      def call
        super do
          repo_type = Services::DetectIsoRemoteType.new(url: url).call.type
          report "Detected repository type '#{repo_type}'"
          remote = Adapters::RemoteIsoRepo.new(type: repo_type.to_s, url: url)
          remote.validate!
          create_repo_dir
          new_repo = Models::RemoteIsoRepo.create(url: url, name: name)
          remote.files.each do |file|
            Models::RemoteIsoFile.create(file.to_h)
          end
          report "Repository '#{name}' has been created successfuly"
          report "#{remote.files.size} files has been detected"
        end
      end

      def create_repo_dir
        existing_repo = Models::RemoteIsoRepo.find(dirname: nil)
        failure! "Repository path already exists" if Dir.exists?(existing_repo)

        FileUtils.mkdir_p(File.join(
          Zadar.current_project.path,
          'iso',
{'fraction_non_alphanumeric': 0.08842752787389466, 'fraction_numerical': 0.0, 'mean_word_length': 2.478609625668449, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1071452', 'n_tokens_mistral': 783, 'n_tokens_neox': 761, 'n_words': 192}