Class: Chef::Knife::GithubClone

Inherits:
Chef::Knife show all
Defined in:
lib/chef/knife/github_clone.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) repo_clone(repo, cookbook)



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/chef/knife/github_clone.rb', line 78

def repo_clone(repo, cookbook)
  if repo.nil? || repo.empty?
    ui.info("Processing [?] #{cookbook}")
    Chef::Log.info("Cannot find the repository: #{cookbook} within github")
    return nil
  end

  repo_link = get_repo_clone_link()
  if repo[cookbook].nil? || repo[cookbook][repo_link].nil? || repo[cookbook][repo_link].empty?
    ui.info("Processing [?] #{cookbook}")
    Chef::Log.info("Cannot find the link for the repository with the name: #{cookbook}")
    return nil
  end

 	github_url = repo[cookbook][repo_link]
  cookbook_path = cookbook_path_valid?(cookbook, true)
  unless cookbook_path.nil?
    ui.info("Processing [C] #{cookbook}")
    Chef::Log.info("Cloning repository to: #{cookbook_path}")
    shell_out!("git clone #{github_url} #{cookbook_path}") 
  end
end

- (Object) run



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/chef/knife/github_clone.rb', line 47

def run

  #executing shell commands
	extend Chef::Mixin::ShellOut

  # validate base options from base module.
  validate_base_options      

  # Display information if debug mode is on.
  display_debug_info

  # Gather all repo information from github.
  all_repos = get_all_repos(@github_organizations.reverse)

  # Get all chef cookbooks and versions (hopefully chef does the error handeling).
  cookbooks = rest.get_rest("/cookbooks?num_version=1")

  # Get the cookbook names from the command line
  @cookbook_name = name_args.first unless name_args.empty?
  if @cookbook_name
    repo = all_repos.select { |k,v| v["name"] == @cookbook_name }
    repo_clone(repo, @cookbook_name)
  elsif config[:all]
    cookbooks.each do |c,v|
      repo_clone(all_repos, c)
    end
  else
    Chef::Log.error("Please specify a repository name")
  end
end