# require 'json' ##### Set parameters argc = ARGV.size script_exec_name = $0 user = ARGV[0] org = ARGV[1] reponame = ARGV[2] clone_dir = ARGV[3] script_dir = File.dirname(File.expand_path(script_exec_name)) script_name = File.basename(script_exec_name) ext_name = File.extname(File.basename(script_exec_name, ".rb")) mode = ext_name[1, ext_name.size - 1] description = "Repository_for_#{reponame}" ##### if (mode == "gitbucket") then target = "GitBucket" template_dir = ".gitbucket" protocol = "http" host_name = "192.168.100.70:8086/gitbucket" git_location = "git/" repo_hash = { "\"name\"" => "\"#{reponame}\"", "\"fullname\"" => "\"#{reponame}\"", "\"description\"" => "\"#{description}\"", "\"private\"" => false } else target = "GitHub" template_dir = ".github" protocol = "https" host_name = "github.com" git_location = "" repo_hash = { "\"name\"" => "\"#{reponame}\"", "\"description\"" => "\"#{description}\"", "\"homepage\"" => "\"\"", "\"private\"" => false, "\"has_issues\"" => true, "\"has_projects\"" => true, "\"has_wiki\"" => true } end ##### repo_param = JSON.dump(repo_hash) api_end_point = "#{protocol}://#{host_name}/api/v3" git_base_url = "#{protocol}://#{user}@#{host_name}" ##### if (argc != 4) then puts "Create empty repository on #{target}" puts "Usage : #{script_exec_name} <account name> <organization> <repository name> <clone directory>" exit 1 end ##### cur_dir=`pwd` if File.exist?(reponame) then system("cd #{cur_dir}") puts "Error : Exist #[clone_dir]" exit 1 end ##### Organization setting if ( org == "-" ) or ( org == user ) then org = user access_url = "#{api_end_point}/user/repos" else access_url = "#{api_end_point}/orgs/#{org}/repos" end git_url = "#{git_base_url}/#{git_location}#{org}/#{reponame}.git" ##### #str="curl -u #{user} -i #{access_url} -d \"#{repo_param}\" --trace-ascii trace.curl.log" str="curl -u #{user} -i #{access_url} -d \"#{repo_param}\"" system(str) #puts "Debug : #{repo_param}" ##### puts "URI = #{git_url}" puts "account = #{user}" puts "orgnization = #{org}" puts "repo = #{reponame}" ##### str="cd #{clone_dir} && mkdir #{reponame} && cd #{reponame} && cp -p -R #{script_dir}/../.template ./#{template_dir}/ && cp -p -R #{script_dir}/../.gitattributes ./ && cp -p -R #{script_dir}/../.gitignore ./ && echo \"#{reponame}\n===============\n\" > ./README.md && git init && git add #{template_dir}/ISSUE_TEMPLATE.md #{template_dir}/PULL_REQUEST_TEMPLATE.md .gitattributes .gitignore README.md && git commit -m \"First commit\" && git remote add origin #{git_url} && git push -u origin master && git checkout -b develop && git push -u origin develop" system(str) system("cd #{cur_dir}")