Sha256: 9da0822cdccc90a836269ec11a9eb0fc72482d76d01d87860b22deddd443eb75

Contents?: true

Size: 1.15 KB

Versions: 4

Compression:

Stored size: 1.15 KB

Contents

require 'securerandom'
class Fourchette::Tarball
  include Fourchette::Logger

  def url(github_git_url, branch_name, github_repo)
    filepath = prepare_tarball(github_git_url, branch_name)
    tarball_to_url(filepath, github_repo)
  end

  def filepath(uuid, expiration)
    "tmp/#{uuid}/#{expiration}.tar.gz"
  end

  private
  def prepare_tarball(github_git_url, branch_name)
    clone_path = "tmp/#{SecureRandom.uuid}"
    clone(github_git_url, branch_name, clone_path)
    tar(clone_path)
  end

  def clone(github_git_url,branch_name, clone_path)
    logger.info "Cloning repository..."
    repo = Git.clone(github_git_url, clone_path, recursive: true)
    repo.checkout(branch_name)
  end

  def tar(path)
    logger.info "Preparing tarball..."
    filepath = "#{path}/#{expiration_timestamp}.tar.gz"
    system("tar -zcf #{filepath} -C #{path} .")
    filepath
  end

  def expiration_timestamp
    Time.now.to_i + 300
  end

  def tarball_to_url(filepath, github_repo)
    logger.info "Tarball to URL as a service in progress..."
    cleaned_path = filepath.gsub('tmp/', '').gsub('.tar.gz', '')
    "#{ENV['FOURCHETTE_APP_URL']}/#{github_repo}/#{cleaned_path}"
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fourchette-0.1.2 lib/fourchette/tarball.rb
fourchette-0.1.1 lib/fourchette/tarball.rb
fourchette-0.1.0 lib/fourchette/tarball.rb
fourchette-0.0.8 lib/fourchette/tarball.rb