<commit_before>desc "publish the documentation"
task :publish => :compile do
  def env(key, default=nil)
    value = ENV[key].to_s.strip
    if default
      if value == ''
        value = default
      end
    else
      fail "Please specify #{key}" if value == ''
    end

    value
  end

  git_short_sha = `git log -1 --format=%h`.strip
  remote_name   = env('REMOTE_NAME', 'origin')

  repo_url = `git config --get remote.#{remote_name}.url`.strip

  rm_rf "build"
  sh("git clone #{repo_url} build --branch gh-pages --depth 1 --quiet")
  build_version = ENV['GOCD_VERSION'] || GOCD_VERSION
  cd "build" do
    rm_rf build_version
    cp_r '../public', build_version
    response = %x[git status]
    unless response.include?('nothing to commit')
      sh("git add --all .")
      sh("git commit -m 'Updating site to latest commit (#{git_short_sha})'")
      sh("git push")
    end
  end
end<commit_msg>Use env function<commit_after>desc "publish the documentation"
task :publish => :compile do
  def env(key, default=nil)
    value = ENV[key].to_s.strip
    if default
      if value == ''
        value = default
      end
    else
      fail "Please specify #{key}" if value == ''
    end

    value
  end

  git_short_sha = `git log -1 --format=%h`.strip
  remote_name   = env('REMOTE_NAME', 'origin')

  repo_url = `git config --get remote.#{remote_name}.url`.strip

  rm_rf "build"
  sh("git clone #{repo_url} build --branch gh-pages --depth 1 --quiet")
  build_version = env('GOCD_VERSION', GOCD_VERSION)
  cd "build" do
    rm_rf build_version
    cp_r '../public', build_version
    response = %x[git status]
    unless response.include?('nothing to commit')
      sh("git add --all .")
      sh("git commit -m 'Updating site to latest commit (#{git_short_sha})'")
      sh("git push")
    end
  end
end
{'fraction_non_alphanumeric': 0.13593835993395706, 'fraction_numerical': 0.002201430930104568, 'mean_word_length': 2.803347280334728, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5791029', 'n_tokens_mistral': 612, 'n_tokens_neox': 597, 'n_words': 179}