Commit 8bf8c70c4bdd14502c6f3ae314207b99aa2c9f49
1 parent
ab0cfc00
Exists in
master
and in
4 other branches
Import repo feature
Showing
5 changed files
with
40 additions
and
5 deletions
Show diff stats
app/assets/javascripts/main.js.coffee
... | ... | @@ -36,6 +36,10 @@ $ -> |
36 | 36 | # Click a .one_click_select field, select the contents |
37 | 37 | $(".one_click_select").on 'click', -> $(@).select() |
38 | 38 | |
39 | + # Click a .appear-link, appear-data fadeout | |
40 | + $(".appear-link").on 'click', -> | |
41 | + $('.appear-data').fadeIn() | |
42 | + | |
39 | 43 | # Initialize chosen selects |
40 | 44 | $('select.chosen').chosen() |
41 | 45 | ... | ... |
app/assets/stylesheets/common.scss
app/contexts/projects/create_context.rb
... | ... | @@ -34,13 +34,23 @@ module Projects |
34 | 34 | |
35 | 35 | @project.creator = current_user |
36 | 36 | |
37 | + # Import project from cloneable resource | |
38 | + if @project.valid? && @project.import_url.present? | |
39 | + shell = Gitlab::Shell.new | |
40 | + if shell.import_repository(@project.path_with_namespace, @project.import_url) | |
41 | + true | |
42 | + else | |
43 | + @project.errors.add(:import_url, 'cannot clone repo') | |
44 | + end | |
45 | + end | |
46 | + | |
37 | 47 | if @project.save |
38 | 48 | @project.users_projects.create(project_access: UsersProject::MASTER, user: current_user) |
39 | 49 | end |
40 | 50 | |
41 | 51 | @project |
42 | - rescue => ex | |
43 | - @project.errors.add(:base, "Can't save project. Please try again later") | |
52 | + #rescue => ex | |
53 | + #@project.errors.add(:base, "Can't save project. Please try again later") | |
44 | 54 | @project |
45 | 55 | end |
46 | 56 | ... | ... |
app/models/project.rb
... | ... | @@ -25,12 +25,13 @@ class Project < ActiveRecord::Base |
25 | 25 | |
26 | 26 | class TransferError < StandardError; end |
27 | 27 | |
28 | - attr_accessible :name, :path, :description, :default_branch, :issues_enabled, | |
29 | - :wall_enabled, :merge_requests_enabled, :wiki_enabled, :public, as: [:default, :admin] | |
28 | + attr_accessible :name, :path, :description, :default_branch, | |
29 | + :issues_enabled, :wall_enabled, :merge_requests_enabled, | |
30 | + :wiki_enabled, :public, :import_url, as: [:default, :admin] | |
30 | 31 | |
31 | 32 | attr_accessible :namespace_id, :creator_id, as: :admin |
32 | 33 | |
33 | - attr_accessor :error_code | |
34 | + attr_accessor :import_url | |
34 | 35 | |
35 | 36 | # Relations |
36 | 37 | belongs_to :creator, foreign_key: "creator_id", class_name: "User" |
... | ... | @@ -75,6 +76,8 @@ class Project < ActiveRecord::Base |
75 | 76 | validates_uniqueness_of :name, scope: :namespace_id |
76 | 77 | validates_uniqueness_of :path, scope: :namespace_id |
77 | 78 | |
79 | + validates :import_url, format: { with: URI::regexp(%w(http https)), message: "should be a valid url" } | |
80 | + | |
78 | 81 | validate :check_limit, :repo_name |
79 | 82 | |
80 | 83 | # Scopes | ... | ... |
app/views/projects/_new_form.html.haml
... | ... | @@ -16,6 +16,20 @@ |
16 | 16 | .input |
17 | 17 | = f.select :namespace_id, namespaces_options(params[:namespace_id] || :current_user), {}, {class: 'chosen'} |
18 | 18 | |
19 | + | |
20 | + .clearfix | |
21 | + .input | |
22 | + = link_to "#", class: 'appear-link' do | |
23 | + %i.icon-upload-alt | |
24 | + %span Import existing repository? | |
25 | + .clearfix.appear-data | |
26 | + = f.label :import_url do | |
27 | + %span Import existing repo | |
28 | + .input | |
29 | + = f.text_field :import_url, class: 'xlarge' | |
30 | + .light | |
31 | + URL should be clonable | |
32 | + | |
19 | 33 | %p.padded |
20 | 34 | New projects are private by default. You choose who can see the project and commit to repository. |
21 | 35 | %hr | ... | ... |