diff --git a/script/create_repo.ghe.rb b/script/create_repo.ghe.rb new file mode 100644 index 0000000..8a1c9a7 --- /dev/null +++ b/script/create_repo.ghe.rb @@ -0,0 +1,93 @@ +# +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} " + 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}") diff --git a/script/create_repo.git.rb b/script/create_repo.git.rb new file mode 100644 index 0000000..8a1c9a7 --- /dev/null +++ b/script/create_repo.git.rb @@ -0,0 +1,93 @@ +# +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} " + 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}") diff --git a/script/create_repo.gitbucket.rb b/script/create_repo.gitbucket.rb new file mode 100644 index 0000000..8a1c9a7 --- /dev/null +++ b/script/create_repo.gitbucket.rb @@ -0,0 +1,93 @@ +# +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} " + 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}") diff --git a/script/create_repo.rb b/script/create_repo.rb index 5e9cbe4..8a1c9a7 100644 --- a/script/create_repo.rb +++ b/script/create_repo.rb @@ -47,7 +47,7 @@ ##### repo_param = JSON.dump(repo_hash) api_end_point = "#{protocol}://#{host_name}/api/v3" -git_base_url = "#{protocol}://#{host_name}" +git_base_url = "#{protocol}://#{user}@#{host_name}" ##### if (argc != 4) then @@ -56,6 +56,14 @@ 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 @@ -66,18 +74,11 @@ 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}\" --trace-ascii trace.curl.log" +str="curl -u #{user} -i #{access_url} -d \"#{repo_param}\"" system(str) -puts "Debug : #{repo_param}" - -##### -cur_dir=`pwd` -if File.exist?(reponame) then - system("cd #{cur_dir}") - puts "Error : Exist #[clone_dir]" - exit 1 -end +#puts "Debug : #{repo_param}" ##### puts "URI = #{git_url}"