<commit_before>module Deployinator
  module Stacks
    module Gotfootsores
      def gotfootsores_git_repo_url
        "git@github.com:xfactoradvertising/gotfootsoresXL.git"
      end

      def prod_user
        'ubuntu'
      end

      def prod_ip
        '10.248.3.116'
      end

      def checkout_root
        "/tmp"
      end

      def site_root
        '/var/www/sites'
      end

      def site_path
        "#{site_root}/#{stack}"
      end

      def gotfootsores_git_checkout_path
        "#{checkout_root}/#{stack}"
      end

      def gotfootsores_dev_version
        %x{cat #{gotfootsores_git_checkout_path}/version.txt}
      end

      def gotfootsores_dev_build
        Version.get_build(gotfootsores_dev_version)
      end

      def gotfootsores_prod_version
        %x{ssh #{prod_user}@#{prod_ip} 'cat #{site_path}/version.txt'}
      end

      def gotfootsores_prod_build
        Version.get_build(gotfootsores_prod_version)
      end

      def gotfootsores_head_build
        %x{git ls-remote #{gotfootsores_git_repo_url} HEAD | cut -c1-7}.chomp
      end

      def gotfootsores_dev(options={})
        old_build = Version.get_build(gotfootsores_dev_version)

        git_cmd = old_build ? :git_freshen_clone : :github_clone
        send(git_cmd, stack, 'sh -c')

        git_bump_version stack, ''

        build = gotfootsores_head_build

        begin
          # sync files to final destination
          run_cmd %Q{rsync -av --exclude='.git/' --exclude='.gitignore' #{gotfootsores_git_checkout_path}/ #{site_path}}
          # set permissions so webserver can write TODO setup passwordless sudo to chown&chmod instead? or
            # maybe set CAP_CHOWN for deployinator?
          run_cmd %Q{chmod 777 #{site_path}/app/storage/*}
          run_cmd %Q{cd #{site_path} && /usr/local/bin/composer install}
          run_cmd %Q{cd #{site_path} && /usr/local/bin/composer dump-autoload}
          log_and_stream "Done!<br>"
        rescue
          log_and_stream "Failed!<br>"
        end

        log_and_shout(:old_build => old_build, :build => build, :send_email => false) # TODO make email true

      end

      def gotfootsores_prod(options={})
        old_build = Version.get_build(gotfootsores_prod_version)
        build = gotfootsores_dev_build

        begin
          run_cmd %Q{rsync -ave ssh #{site_path} #{prod_user}@#{prod_ip}:#{site_root}}
          log_and_stream "Done!<br>"
        rescue
          log_and_stream "Failed!<br>"
        end

        log_and_shout(:old_build => old_build, :build => build, :env => 'PROD', :send_email => false) # TODO make email true
      end

      def gotfootsores_environments
        [
          {
            :name => 'dev',
            :method => 'gotfootsores_dev',
            :current_version => gotfootsores_dev_version,
            :current_build => gotfootsores_dev_build,<commit_msg>overwrite dev db config with prod<commit_after>module Deployinator
  module Stacks
    module Gotfootsores
      def gotfootsores_git_repo_url
        "git@github.com:xfactoradvertising/gotfootsoresXL.git"
      end

      def prod_user
        'ubuntu'
      end

      def prod_ip
        '10.248.3.116'
      end

      def checkout_root
        "/tmp"
      end

      def site_root
        '/var/www/sites'
      end

      def site_path
        "#{site_root}/#{stack}"
      end

      def gotfootsores_git_checkout_path
        "#{checkout_root}/#{stack}"
      end

      def gotfootsores_dev_version
        %x{cat #{gotfootsores_git_checkout_path}/version.txt}
      end

      def gotfootsores_dev_build
        Version.get_build(gotfootsores_dev_version)
      end

      def gotfootsores_prod_version
        %x{ssh #{prod_user}@#{prod_ip} 'cat #{site_path}/version.txt'}
      end

      def gotfootsores_prod_build
        Version.get_build(gotfootsores_prod_version)
      end

      def gotfootsores_head_build
        %x{git ls-remote #{gotfootsores_git_repo_url} HEAD | cut -c1-7}.chomp
      end

      def gotfootsores_dev(options={})
        old_build = Version.get_build(gotfootsores_dev_version)

        git_cmd = old_build ? :git_freshen_clone : :github_clone
        send(git_cmd, stack, 'sh -c')

        git_bump_version stack, ''

        build = gotfootsores_head_build

        begin
          # sync files to final destination
          run_cmd %Q{rsync -av --exclude='.git/' --exclude='.gitignore' #{gotfootsores_git_checkout_path}/ #{site_path}}
          # set permissions so webserver can write TODO setup passwordless sudo to chown&chmod instead? or
            # maybe set CAP_CHOWN for deployinator?
          run_cmd %Q{chmod 777 #{site_path}/app/storage/*}
          run_cmd %Q{cd #{site_path} && /usr/local/bin/composer install}
          run_cmd %Q{cd #{site_path} && /usr/local/bin/composer dump-autoload}
          log_and_stream "Done!<br>"
        rescue
          log_and_stream "Failed!<br>"
        end

        log_and_shout(:old_build => old_build, :build => build, :send_email => false) # TODO make email true

      end

      def gotfootsores_prod(options={})
        old_build = Version.get_build(gotfootsores_prod_version)
        build = gotfootsores_dev_build

        begin
          run_cmd %Q{rsync -ave ssh #{site_path} #{prod_user}@#{prod_ip}:#{site_root}}

          # replace database config with production version
          run_cmd %Q{ssh #{prod_user}@#{prod_ip} "cd #{site_path}/app/config && mv database.php.PROD database.php"}

          log_and_stream "Done!<br>"
        rescue
          log_and_stream "Failed!<br>"
        end

        log_and_shout(:old_build => old_build, :build => build, :env => 'PROD', :send_email => false) # TODO make email true
      end

      def gotfootsores_environments
        [
          {
            :name => 'dev',
            :method => 'gotfootsores_dev',
            :current_version => gotfootsores_dev_version,
            :current_build => gotfootsores_dev_build,
{'fraction_non_alphanumeric': 0.09745051995974505, 'fraction_numerical': 0.004696410600469641, 'mean_word_length': 2.3518830803822373, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 4, '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': '5864076', 'n_tokens_mistral': 2000, 'n_tokens_neox': 1925, 'n_words': 386}