<commit_before>require 'chatops_deployer/globals'
require 'chatops_deployer/error'
require 'chatops_deployer/command'
require 'chatops_deployer/template'
require 'chatops_deployer/logger'
require 'digest/sha1'
require 'fileutils'
require 'yaml'

module ChatopsDeployer
  class Project
    include Logger
    class Error < ChatopsDeployer::Error; end

    attr_reader :sha1, :branch_directory, :config
    attr_accessor :env
    def initialize(repository, branch, config_file="chatops_deployer.yml")
      @sha1 = Digest::SHA1.hexdigest(repository + branch)
      @repository = repository
      @branch = branch
      @config_file = config_file
      @env = {}

      matchdata = @repository.match(/.*github.com\/(.*)\/(.*).git/)
      raise_error("Bad github repository: #{@repository}") if matchdata.nil?
      org, repo = matchdata.captures
      @branch_directory = File.join(WORKSPACE, org, repo, 'repositories', @branch)
      @project_directory = File.join(WORKSPACE, org, repo)
      @common_cache_dir = File.join(@project_directory, 'cache')
    end

    def fetch_repo
      #logger.info "Fetching #{@repository}:#{@branch}"
      #unless Dir.entries('.').size == 2
        #logger.info "Branch already cloned. Deleting everything before cloning again"
        #FileUtils.rm_rf '.'
      #end
      logger.info "Cloning branch #{@repository}:#{@branch}"
      git_clone = Command.run(command: ['git', 'clone', "--branch=#{@branch}", '--depth=1', @repository, '.'], logger: logger)
      unless git_clone.success?
        raise_error("Cannot clone git repository: #{@repository}, branch: #{@branch}")
      end
    end

    def delete_repo
      logger.info "Deleting #{@repository}:#{@branch}"
      FileUtils.rm_rf @branch_directory
    end

    def cloned?
      Dir.entries('.').size > 2<commit_msg>Generate SHA1 based on org, repo and branchname<commit_after>require 'chatops_deployer/globals'
require 'chatops_deployer/error'
require 'chatops_deployer/command'
require 'chatops_deployer/template'
require 'chatops_deployer/logger'
require 'digest/sha1'
require 'fileutils'
require 'yaml'

module ChatopsDeployer
  class Project
    include Logger
    class Error < ChatopsDeployer::Error; end

    attr_reader :sha1, :branch_directory, :config
    attr_accessor :env
    def initialize(repository, branch, config_file="chatops_deployer.yml")
      @repository = repository
      @branch = branch
      @config_file = config_file
      @env = {}

      matchdata = @repository.match(/.*github.com\/(.*)\/(.*).git/)
      raise_error("Bad github repository: #{@repository}") if matchdata.nil?
      org, repo = matchdata.captures
      @sha1 = Digest::SHA1.hexdigest(org + repo + branch)
      @branch_directory = File.join(WORKSPACE, org, repo, 'repositories', @branch)
      @project_directory = File.join(WORKSPACE, org, repo)
      @common_cache_dir = File.join(@project_directory, 'cache')
    end

    def fetch_repo
      #logger.info "Fetching #{@repository}:#{@branch}"
      #unless Dir.entries('.').size == 2
        #logger.info "Branch already cloned. Deleting everything before cloning again"
        #FileUtils.rm_rf '.'
      #end
      logger.info "Cloning branch #{@repository}:#{@branch}"
      git_clone = Command.run(command: ['git', 'clone', "--branch=#{@branch}", '--depth=1', @repository, '.'], logger: logger)
      unless git_clone.success?
        raise_error("Cannot clone git repository: #{@repository}, branch: #{@branch}")
      end
    end

    def delete_repo
      logger.info "Deleting #{@repository}:#{@branch}"
      FileUtils.rm_rf @branch_directory
    end

    def cloned?
      Dir.entries('.').size > 2
{'fraction_non_alphanumeric': 0.1362144420131291, 'fraction_numerical': 0.004102844638949671, 'mean_word_length': 3.617424242424242, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2207173', 'n_tokens_mistral': 1145, 'n_tokens_neox': 1116, 'n_words': 259}