Import repo feature

This commit is contained in:
Dmitriy Zaporozhets 2013-02-11 23:00:12 +02:00
parent ab0cfc0036
commit 8bf8c70c4b
5 changed files with 40 additions and 5 deletions

View file

@ -36,6 +36,10 @@ $ ->
# Click a .one_click_select field, select the contents # Click a .one_click_select field, select the contents
$(".one_click_select").on 'click', -> $(@).select() $(".one_click_select").on 'click', -> $(@).select()
# Click a .appear-link, appear-data fadeout
$(".appear-link").on 'click', ->
$('.appear-data').fadeIn()
# Initialize chosen selects # Initialize chosen selects
$('select.chosen').chosen() $('select.chosen').chosen()

View file

@ -564,3 +564,7 @@ img.emoji {
vertical-align: middle; vertical-align: middle;
width: 20px; width: 20px;
} }
.appear-data {
display: none;
}

View file

@ -34,13 +34,23 @@ module Projects
@project.creator = current_user @project.creator = current_user
# Import project from cloneable resource
if @project.valid? && @project.import_url.present?
shell = Gitlab::Shell.new
if shell.import_repository(@project.path_with_namespace, @project.import_url)
true
else
@project.errors.add(:import_url, 'cannot clone repo')
end
end
if @project.save if @project.save
@project.users_projects.create(project_access: UsersProject::MASTER, user: current_user) @project.users_projects.create(project_access: UsersProject::MASTER, user: current_user)
end end
@project @project
rescue => ex #rescue => ex
@project.errors.add(:base, "Can't save project. Please try again later") #@project.errors.add(:base, "Can't save project. Please try again later")
@project @project
end end

View file

@ -25,12 +25,13 @@ class Project < ActiveRecord::Base
class TransferError < StandardError; end class TransferError < StandardError; end
attr_accessible :name, :path, :description, :default_branch, :issues_enabled, attr_accessible :name, :path, :description, :default_branch,
:wall_enabled, :merge_requests_enabled, :wiki_enabled, :public, as: [:default, :admin] :issues_enabled, :wall_enabled, :merge_requests_enabled,
:wiki_enabled, :public, :import_url, as: [:default, :admin]
attr_accessible :namespace_id, :creator_id, as: :admin attr_accessible :namespace_id, :creator_id, as: :admin
attr_accessor :error_code attr_accessor :import_url
# Relations # Relations
belongs_to :creator, foreign_key: "creator_id", class_name: "User" belongs_to :creator, foreign_key: "creator_id", class_name: "User"
@ -75,6 +76,8 @@ class Project < ActiveRecord::Base
validates_uniqueness_of :name, scope: :namespace_id validates_uniqueness_of :name, scope: :namespace_id
validates_uniqueness_of :path, scope: :namespace_id validates_uniqueness_of :path, scope: :namespace_id
validates :import_url, format: { with: URI::regexp(%w(http https)), message: "should be a valid url" }
validate :check_limit, :repo_name validate :check_limit, :repo_name
# Scopes # Scopes

View file

@ -16,6 +16,20 @@
.input .input
= f.select :namespace_id, namespaces_options(params[:namespace_id] || :current_user), {}, {class: 'chosen'} = f.select :namespace_id, namespaces_options(params[:namespace_id] || :current_user), {}, {class: 'chosen'}
.clearfix
.input
= link_to "#", class: 'appear-link' do
%i.icon-upload-alt
%span Import existing repository?
.clearfix.appear-data
= f.label :import_url do
%span Import existing repo
.input
= f.text_field :import_url, class: 'xlarge'
.light
URL should be clonable
%p.padded %p.padded
New projects are private by default. You choose who can see the project and commit to repository. New projects are private by default. You choose who can see the project and commit to repository.
%hr %hr