Class: KnifeGithubRepoFork::GithubRepoFork

Inherits:
Chef::Knife
  • Object
show all
Defined in:
lib/chef/knife/github_repo_fork.rb

Instance Method Summary collapse

Instance Method Details

#runObject



41
42
43
44
45
46
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
# File 'lib/chef/knife/github_repo_fork.rb', line 41

def run
  # validate base options from base module.
  validate_base_options      

  # Display information if debug mode is on.
  display_debug_info

  # Get the name_args from the command line
  name = name_args[0]
  name_args[1].nil? ? owner = locate_config_value('github_organizations').first : owner = name_args[1]
  target = name_args[2] unless name_args[2].nil?
  
  if owner.nil? || name.nil? || owner.empty? || name.empty? 
    Chef::Log.error("Please specify a repository name like: name ")
    exit 1
  end 

  # Set params for the rest request
  params = {}
  params[:url] = @github_url + "/api/" + @github_api_version + "/repos/#{owner}/#{name}/forks"
  params[:body] = get_body_json(target) unless target.nil?
  params[:token] = get_github_token()
  #params[:response_code]  = 202
  params[:action]  = "POST"

  # Execute the rest request
  username = ENV['USER']

  connection.request(params)
  if target
    puts "Fork of #{name} is created in #{target}"
  else
    puts "Fork of #{name} is created in #{username}"
  end
end