diff --git a/app/assets/javascripts/main.js.coffee b/app/assets/javascripts/main.js.coffee index f6c398c0acf17f78f3d685556220ddaceee8e983..5aaea50cf219592dd4880a1a5a8f1636881629b6 100644 --- a/app/assets/javascripts/main.js.coffee +++ b/app/assets/javascripts/main.js.coffee @@ -36,6 +36,10 @@ $ -> # Click a .one_click_select field, select the contents $(".one_click_select").on 'click', -> $(@).select() + # Click a .appear-link, appear-data fadeout + $(".appear-link").on 'click', -> + $('.appear-data').fadeIn() + # Initialize chosen selects $('select.chosen').chosen() diff --git a/app/assets/stylesheets/common.scss b/app/assets/stylesheets/common.scss index c9a11d0a1acf5efce28dc524998701cd7324218c..7ac8c2dd91c35f86f5deb50cfe08e7595f2ba869 100644 --- a/app/assets/stylesheets/common.scss +++ b/app/assets/stylesheets/common.scss @@ -564,3 +564,7 @@ img.emoji { vertical-align: middle; width: 20px; } + +.appear-data { + display: none; +} diff --git a/app/contexts/projects/create_context.rb b/app/contexts/projects/create_context.rb index 915bd8be8b00626de649a32f49f3d96e3936c685..8e1da539a6c1d3efe9e3408b5fb08ab907e87365 100644 --- a/app/contexts/projects/create_context.rb +++ b/app/contexts/projects/create_context.rb @@ -34,13 +34,23 @@ module Projects @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 @project.users_projects.create(project_access: UsersProject::MASTER, user: current_user) end @project - rescue => ex - @project.errors.add(:base, "Can't save project. Please try again later") + #rescue => ex + #@project.errors.add(:base, "Can't save project. Please try again later") @project end diff --git a/app/models/project.rb b/app/models/project.rb index fee45f577355e3aedf904d853fcc3cdfa646c71e..16f189fd71f45d4d82ffda95a546e143029a592b 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -25,12 +25,13 @@ class Project < ActiveRecord::Base class TransferError < StandardError; end - attr_accessible :name, :path, :description, :default_branch, :issues_enabled, - :wall_enabled, :merge_requests_enabled, :wiki_enabled, :public, as: [:default, :admin] + attr_accessible :name, :path, :description, :default_branch, + :issues_enabled, :wall_enabled, :merge_requests_enabled, + :wiki_enabled, :public, :import_url, as: [:default, :admin] attr_accessible :namespace_id, :creator_id, as: :admin - attr_accessor :error_code + attr_accessor :import_url # Relations 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 :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 # Scopes diff --git a/app/views/projects/_new_form.html.haml b/app/views/projects/_new_form.html.haml index 185164955fcd3271882bfec0b16501e48d60bd4c..d05838ae50df3c5cc6fd51c32c7b0c988c1c2f9f 100644 --- a/app/views/projects/_new_form.html.haml +++ b/app/views/projects/_new_form.html.haml @@ -16,6 +16,20 @@ .input = 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 New projects are private by default. You choose who can see the project and commit to repository. %hr