Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add name field to Add new repo tool #488

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/admin_routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions lib/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/api_routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion public/coffee/repos.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion views/admin/repos.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
<h2>Add new repo</h2>
<div id="cloneForm">
<label for="newRepoUrl">Repo url</label><br/>
<input type="text" id="newRepoUrl" />
<input type="text" id="newRepoUrl" /><br>
<label for="newRepoName">Repo Name</label><br/>
<input type="text" id="newRepoName" />
<button id="clone" class="standard">Add repo</button><br/>
<span class="note">e.g. http://github.com/ooyala/barkeep.git</span><br/>
<span class="note">Repo name should be letters and number - no spaces or punctuation </span><br>
<p class="note">This repo will be cloned into <code><%= REPOS_ROOT %></code></p>
</div>

Expand Down