<commit_before># encoding: utf-8
require 'git_cloner_dsl'
require "uri"
require 'fileutils'

module GitCloner
  #  GitCloner Core
  class Core
    GIT_CLONER_FILE = "Gitclonerfile"
    GIT_CLONER_TEMPLATE =<<-EOS
# encoding: utf-8

# default_output place
# default_output allow only String
# default_output's default value => "./"
default_output "./"

# git repositries
# repos allow only Array(in Array, Hash[:place, :output, :copies])
# copies is option.
# copies must have Array[Hash{:from, :to}].
# you can copy files or directories.
# repos's default value => []
repos [
  {
    place: 'https://github.com/tbpgr/rspec_piccolo.git',
    output: './tmp',
    copies: [
      {from: "./tmp/rspec_piccolo/lib/rspec_piccolo", to: "./"}, 
      {from: "./tmp/rspec_piccolo/spec", to: "./sample"}
    ]
  }
]
    EOS

    #== generate Gitclonerfile to current directory.
    def init
      File.open(GIT_CLONER_FILE, "w") { |f|f.puts(GIT_CLONER_TEMPLATE) }
    end

    #== clone git repositories
    def clone
      dsl = get_dsl
      base_dir = Dir.pwd
      default_output = dsl.git_cloner.default_output
      repos = dsl.git_cloner.repos
      git_clone(default_output, repos, base_dir)
    end

    private

    def get_dsl
      src = read_dsl
      dsl = GitCloner::Dsl.new
      dsl.instance_eval src
      dsl
    end

    def read_dsl
      File.open(GIT_CLONER_FILE) { |f|f.read }
    end

    def git_clone(default_output, repos, base_dir)
      fail ArgumentError, 'invalid repos. repos must be Array.' unless repos.is_a? Array
      repos.each do |repo|
        fail ArgumentError, 'invalid repos. repos-Array must have Hash' unless repo.is_a?(Hash)
        fail ArgumentError, 'invalid key. Hash must contain :place key' unless repo.key?(:place)
        repo_name = get_repo_name repo[:place]
        output_dir = get_output_dir(repo[:output], default_output)
        make_output_dir(output_dir)
        Dir.chdir(output_dir)
        result = system("git clone #{repo[:place]} --depth=1")
        remove_dot_git_directory repo_name<commit_msg>rename method git_clone to clone_repositories<commit_after># encoding: utf-8
require 'git_cloner_dsl'
require "uri"
require 'fileutils'

module GitCloner
  #  GitCloner Core
  class Core
    GIT_CLONER_FILE = "Gitclonerfile"
    GIT_CLONER_TEMPLATE =<<-EOS
# encoding: utf-8

# default_output place
# default_output allow only String
# default_output's default value => "./"
default_output "./"

# git repositries
# repos allow only Array(in Array, Hash[:place, :output, :copies])
# copies is option.
# copies must have Array[Hash{:from, :to}].
# you can copy files or directories.
# repos's default value => []
repos [
  {
    place: 'https://github.com/tbpgr/rspec_piccolo.git',
    output: './tmp',
    copies: [
      {from: "./tmp/rspec_piccolo/lib/rspec_piccolo", to: "./"}, 
      {from: "./tmp/rspec_piccolo/spec", to: "./sample"}
    ]
  }
]
    EOS

    #== generate Gitclonerfile to current directory.
    def init
      File.open(GIT_CLONER_FILE, "w") { |f|f.puts(GIT_CLONER_TEMPLATE) }
    end

    #== clone git repositories
    def clone
      dsl = get_dsl
      base_dir = Dir.pwd
      default_output = dsl.git_cloner.default_output
      repos = dsl.git_cloner.repos
      clone_repositories(default_output, repos, base_dir)
    end

    private

    def get_dsl
      src = read_dsl
      dsl = GitCloner::Dsl.new
      dsl.instance_eval src
      dsl
    end

    def read_dsl
      File.open(GIT_CLONER_FILE) { |f|f.read }
    end

    def clone_repositories(default_output, repos, base_dir)
      fail ArgumentError, 'invalid repos. repos must be Array.' unless repos.is_a? Array
      repos.each do |repo|
        fail ArgumentError, 'invalid repos. repos-Array must have Hash' unless repo.is_a?(Hash)
        fail ArgumentError, 'invalid key. Hash must contain :place key' unless repo.key?(:place)
        repo_name = get_repo_name repo[:place]
        output_dir = get_output_dir(repo[:output], default_output)
        make_output_dir(output_dir)
        Dir.chdir(output_dir)
        result = system("git clone #{repo[:place]} --depth=1")
        remove_dot_git_directory repo_name
{'fraction_non_alphanumeric': 0.11233797407585214, 'fraction_numerical': 0.0014402304368698992, 'mean_word_length': 3.0495626822157433, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '1320893', 'n_tokens_mistral': 1485, 'n_tokens_neox': 1424, 'n_words': 343}