class Berkflow::ThorTasks

Constants

REGEX

Public Instance Methods

release() click to toggle source
# File lib/berkflow/thor_tasks.rb, line 24
def release
  cookbook = Ridley::Chef::Cookbook.from_path(File.dirname(options[:berksfile]))
  begin
    say "Creating GitHub release (#{cookbook.version})"
    release = github_client.create_release(repository, cookbook.version)
  rescue Octokit::UnprocessableEntity
    say "Release already exists, skipping..."
    release = github_client.releases(repository).find { |release| release[:tag_name] == cookbook.version }
  end

  berksfile = Berkshelf::Berksfile.from_file(options[:berksfile])
  pkg_dir   = File.join(File.dirname(File.expand_path(berksfile.filepath)), "pkg")
  out_file  = File.join(pkg_dir, "cookbooks-#{Time.now.to_i}.tar.gz")
  FileUtils.mkdir_p(pkg_dir)
  berksfile.package(out_file)

  begin
    say "Uploading #{File.basename(out_file)} to GitHub..."
    github_client.upload_asset(release[:url], out_file, name: "cookbooks.tar.gz", content_type: "application/x-tar")
  rescue Errno::EPIPE; end
end

Private Instance Methods

extract_repository() click to toggle source
# File lib/berkflow/thor_tasks.rb, line 56
def extract_repository
  _, repository = `git remote show origin | grep Push`.scan(REGEX).first
  repository
end
github_client() click to toggle source
# File lib/berkflow/thor_tasks.rb, line 48
def github_client
  @github_client ||= Octokit::Client.new(access_token: options[:github_token])
end
repository() click to toggle source
# File lib/berkflow/thor_tasks.rb, line 52
def repository
  @repository ||= extract_repository
end