Class: Chef::Knife::StashRepoCreate

Inherits:
Chef::Knife show all
Includes:
StashBase
Defined in:
lib/chef/knife/stash_repo_create.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



17
18
19
20
21
22
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
# File 'lib/chef/knife/stash_repo_create.rb', line 17

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

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

  name = name_args[1]

  if name.nil?
    ui.fatal "You need a repository name!"
    show_usage
    exit 1
  end

  args = name_args[2]
  if args.nil?
    args = ""
  end

  stash = get_stash_connection
  repo = { :name => name, :scmId => "git" }

  if get_config(:noop)
    ui.info "#{ui.color "Skipping repo creation process because --noop specified.", :red}"
  else
    response = stash.post do |post|
      post.url "projects/#{project_key}/repos"
      post.headers['Content-Type'] = "application/json"
      post.body = JSON.generate(repo)
    end
    if response.success?
      ui.info "Created Stash Repository: #{project_key}/#{name}"
      ui.info "Available via (HTTPS): #{get_repo_https_url(project_key,name)}"
      ui.info "Available via (SSH): #{get_repo_ssh_url(project_key,name)}"
    else
      display_stash_error "Could not create Stash repository!", response
      exit 1
    end
  end
  
end