diff --git a/lib/admin_routes.rb b/lib/admin_routes.rb index a4339bd8..868f4ba2 100644 --- a/lib/admin_routes.rb +++ b/lib/admin_routes.rb @@ -101,7 +101,7 @@ class BarkeepServer < Sinatra::Base post "/admin/repos/create_new_repo" do halt 400, "'url' is required." if (params[:url] || "").strip.empty? begin - add_repo params[:url] + add_repo params[:url], params[:name] rescue RuntimeError => e halt 400, e.message end diff --git a/lib/api.rb b/lib/api.rb index 4abca9fe..ae729850 100644 --- a/lib/api.rb +++ b/lib/api.rb @@ -7,9 +7,13 @@ require "resque_jobs/clone_new_repo" module Api - def add_repo(url) + def add_repo(url,name) raise "This is not a valid URL." unless Addressable::URI.parse(url) - repo_name = File.basename(url, ".*") + if name != '' + repo_name = name + else + repo_name = File.basename(url, ".*") + end repo_path = File.join(REPOS_ROOT, repo_name) raise "There is already a folder named \"#{repo_name}\" in #{REPOS_ROOT}." if File.exists?(repo_path) Resque.enqueue(CloneNewRepo, repo_name, url) diff --git a/lib/api_routes.rb b/lib/api_routes.rb index 1d21ebbf..4191ea88 100644 --- a/lib/api_routes.rb +++ b/lib/api_routes.rb @@ -32,7 +32,7 @@ def api_error(status, message) post "/api/add_repo" do ensure_required_params :url begin - add_repo params[:url] + add_repo params[:url], params[:name] rescue RuntimeError => e api_error 400, e.message end diff --git a/public/coffee/repos.coffee b/public/coffee/repos.coffee index bbd71ec5..3f8211be 100644 --- a/public/coffee/repos.coffee +++ b/public/coffee/repos.coffee @@ -2,10 +2,11 @@ window.Repos = init: -> $("button#clone").click => repoUrl = $("#newRepoUrl").val() + repoName = $("#newRepoName").val() $.ajax type: "post" url: "/admin/repos/create_new_repo" - data: { url: repoUrl } + data: { url: repoUrl, name: repoName } dataType: "json" success: => @showConfirmationMessage("#{repoUrl} has been scheduled to be cloned.") error: (response) => @showConfirmationMessage(response.responseText) diff --git a/views/admin/repos.erb b/views/admin/repos.erb index e50235a2..9fa3e95c 100644 --- a/views/admin/repos.erb +++ b/views/admin/repos.erb @@ -15,9 +15,12 @@
This repo will be cloned into <%= REPOS_ROOT %>