Class: Chef::Knife::StashProjectDelete

Inherits:
Chef::Knife show all
Includes:
StashBase
Defined in:
lib/chef/knife/stash_project_delete.rb

Instance Method Summary collapse

Methods included from StashBase

#display_stash_error, #get_all_values, #get_config, #get_repo_https_url, #get_repo_ssh_url, #get_stash_connection, included

Instance Method Details

#runObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/chef/knife/stash_project_delete.rb', line 23

def run
  $stdout.sync = true
  
  key = name_args.first

  if key.nil?
    ui.fatal "You need a project key!"
    show_usage
    exit 1
  end

  stash = get_stash_connection

  if get_config(:noop)
    ui.info "#{ui.color "Skipping project deletion process because --noop specified.", :red}"
  else
    if get_config(:delete_repos)
      url = "projects/#{key}/repos"
      response = stash.get url
      if response.success?
        get_all_values stash,url,response do |values|
          values.each do |repo|
            repo_delete = StashRepoDelete.new
            repo_delete.name_args = [ key, repo['name'] ]
            repo_delete.run
          end
        end
      else
        display_stash_error "Could not delete Stash project repositories!", response
        exit 1
      end
    end
    response = stash.delete "projects/#{key}"
    if response.success?
      ui.info "Deleted Stash Project: #{key}"
    else
      display_stash_error "Could not delete Stash project!", response
      exit 1
    end
  end
  
end