Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
1ac20698
Commit
1ac20698
authored
Feb 05, 2015
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gitlab.com importer: refactorig
parent
2d5765bd
Changes
14
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
85 additions
and
140 deletions
+85
-140
app/assets/javascripts/importer_status.js.coffee
app/assets/javascripts/importer_status.js.coffee
+31
-0
app/controllers/import/base_controller.rb
app/controllers/import/base_controller.rb
+21
-0
app/controllers/import/github_controller.rb
app/controllers/import/github_controller.rb
+5
-17
app/controllers/import/gitlab_controller.rb
app/controllers/import/gitlab_controller.rb
+4
-16
app/views/import/base/create.js.haml
app/views/import/base/create.js.haml
+0
-0
app/views/import/github/status.html.haml
app/views/import/github/status.html.haml
+2
-26
app/views/import/gitlab/create.js.haml
app/views/import/gitlab/create.js.haml
+0
-18
app/views/import/gitlab/status.html.haml
app/views/import/gitlab/status.html.haml
+2
-26
app/views/projects/_github_import_modal.html.haml
app/views/projects/_github_import_modal.html.haml
+1
-14
app/views/projects/_gitlab_import_modal.html.haml
app/views/projects/_gitlab_import_modal.html.haml
+1
-14
app/views/projects/new.html.haml
app/views/projects/new.html.haml
+8
-0
app/workers/repository_import_worker.rb
app/workers/repository_import_worker.rb
+7
-7
lib/gitlab/github_import/importer.rb
lib/gitlab/github_import/importer.rb
+2
-1
lib/gitlab/gitlab_import/importer.rb
lib/gitlab/gitlab_import/importer.rb
+1
-1
No files found.
app/assets/javascripts/importer_status.js.coffee
0 → 100644
View file @
1ac20698
class
@
ImporterStatus
constructor
:
(
@
jobs_url
,
@
import_url
)
->
this
.
initStatusPage
()
this
.
setAutoUpdate
()
initStatusPage
:
->
$
(
".btn-add-to-import"
).
click
(
event
)
=>
new_namespace
=
null
tr
=
$
(
event
.
currentTarget
).
closest
(
"tr"
)
id
=
tr
.
attr
(
"id"
).
replace
(
"repo_"
,
""
)
if
tr
.
find
(
".import-target input"
).
length
>
0
new_namespace
=
tr
.
find
(
".import-target input"
).
prop
(
"value"
)
tr
.
find
(
".import-target"
).
empty
().
append
(
new_namespace
+
"/"
+
tr
.
find
(
".import-target"
).
data
(
"project_name"
))
$
.
post
@
import_url
,
{
repo_id
:
id
,
new_namespace
:
new_namespace
},
dataType
:
'script'
setAutoUpdate
:
->
setInterval
(
=>
$
.
get
@
jobs_url
,
(
data
)
=>
$
.
each
data
,
(
i
,
job
)
=>
job_item
=
$
(
"#project_"
+
job
.
id
)
status_field
=
job_item
.
find
(
".job-status"
)
if
job
.
import_status
==
'finished'
job_item
.
removeClass
(
"active"
).
addClass
(
"success"
)
status_field
.
html
(
'<span class="cgreen"><i class="fa fa-check"></i> done</span>'
)
else
if
job
.
import_status
==
'started'
status_field
.
html
(
"<i class='fa fa-spinner fa-spin'></i> started"
)
else
status_field
.
html
(
job
.
import_status
)
),
4000
\ No newline at end of file
app/controllers/import/base_controller.rb
0 → 100644
View file @
1ac20698
class
Import::BaseController
<
ApplicationController
private
def
get_or_create_namespace
existing_namespace
=
Namespace
.
find_by
(
"path = ? OR name = ?"
,
@target_namespace
,
@target_namespace
)
if
existing_namespace
if
existing_namespace
.
owner
==
current_user
namespace
=
existing_namespace
else
@already_been_taken
=
true
return
false
end
else
namespace
=
Group
.
create
(
name:
@target_namespace
,
path:
@target_namespace
,
owner:
current_user
)
namespace
.
add_owner
(
current_user
)
namespace
end
end
end
app/controllers/import/github_controller.rb
View file @
1ac20698
class
Import::GithubController
<
Application
Controller
class
Import::GithubController
<
Import
::
Base
Controller
before_filter
:github_auth
,
except: :callback
rescue_from
Octokit
::
Unauthorized
,
with: :github_unauthorized
...
...
@@ -30,22 +30,10 @@ class Import::GithubController < ApplicationController
def
create
@repo_id
=
params
[
:repo_id
].
to_i
repo
=
octo_client
.
repo
(
@repo_id
)
target_namespace
=
params
[
:new_namespace
].
presence
||
repo
.
owner
.
login
existing_namespace
=
Namespace
.
find_by
(
"path = ? OR name = ?"
,
target_namespace
,
target_namespace
)
if
existing_namespace
if
existing_namespace
.
owner
==
current_user
namespace
=
existing_namespace
else
@already_been_taken
=
true
@target_namespace
=
target_namespace
@target_namespace
=
params
[
:new_namespace
].
presence
||
repo
.
owner
.
login
@project_name
=
repo
.
name
render
and
return
end
else
namespace
=
Group
.
create
(
name:
target_namespace
,
path:
target_namespace
,
owner:
current_user
)
namespace
.
add_owner
(
current_user
)
end
namespace
=
get_or_create_namespace
||
(
render
and
return
)
@project
=
Gitlab
::
GithubImport
::
ProjectCreator
.
new
(
repo
,
namespace
,
current_user
).
execute
end
...
...
app/controllers/import/gitlab_controller.rb
View file @
1ac20698
class
Import::GitlabController
<
Application
Controller
class
Import::GitlabController
<
Import
::
Base
Controller
before_filter
:gitlab_auth
,
except: :callback
rescue_from
OAuth2
::
Error
,
with: :gitlab_unauthorized
...
...
@@ -27,22 +27,10 @@ class Import::GitlabController < ApplicationController
def
create
@repo_id
=
params
[
:repo_id
].
to_i
repo
=
client
.
project
(
@repo_id
)
target_namespace
=
params
[
:new_namespace
].
presence
||
repo
[
"namespace"
][
"path"
]
existing_namespace
=
Namespace
.
find_by
(
"path = ? OR name = ?"
,
target_namespace
,
target_namespace
)
@
target_namespace
=
params
[
:new_namespace
].
presence
||
repo
[
"namespace"
][
"path"
]
@project_name
=
repo
[
"name"
]
if
existing_namespace
if
existing_namespace
.
owner
==
current_user
namespace
=
existing_namespace
else
@already_been_taken
=
true
@target_namespace
=
target_namespace
@project_name
=
repo
[
"path"
]
render
and
return
end
else
namespace
=
Group
.
create
(
name:
target_namespace
,
path:
target_namespace
,
owner:
current_user
)
namespace
.
add_owner
(
current_user
)
end
namespace
=
get_or_create_namespace
||
(
render
and
return
)
@project
=
Gitlab
::
GitlabImport
::
ProjectCreator
.
new
(
repo
,
namespace
,
current_user
).
execute
end
...
...
app/views/import/
github
/create.js.haml
→
app/views/import/
base
/create.js.haml
View file @
1ac20698
File moved
app/views/import/github/status.html.haml
View file @
1ac20698
...
...
@@ -34,30 +34,6 @@
%td
.import-actions.job-status
=
button_tag
"Add"
,
class:
"btn btn-add-to-import"
:coffeescript
$(".btn-add-to-import").click () ->
new_namespace = null
tr = $(this).closest("tr")
id = tr.attr("id").replace("repo_", "")
if tr.find(".import-target input").length > 0
new_namespace = tr.find(".import-target input").prop("value")
tr.find(".import-target").empty().append(new_namespace + "/" + tr.find(".import-target").data("project_name"))
$.post "
#{
import_github_url
}
", {repo_id: id, new_namespace: new_namespace}, dataType: 'script'
setInterval (->
$.get "
#{
jobs_import_github_path
}
", (data)->
$.each data, (i, job) ->
job_item = $("#project_" + job.id)
status_field = job_item.find(".job-status")
if job.import_status == 'finished'
job_item.removeClass("active").addClass("success")
status_field.html('<span class="cgreen"><i class="fa fa-check"></i> done</span>')
else if job.import_status == 'started'
status_field.html("<i class='fa fa-spinner fa-spin'></i> started")
else
status_field.html(job.import_status)
), 4000
$ ->
new ImporterStatus("
#{
jobs_import_github_path
}
", "
#{
import_github_path
}
")
app/views/import/gitlab/create.js.haml
deleted
100644 → 0
View file @
2d5765bd
-
if
@already_been_taken
:plain
target_field = $("tr#repo_
#{
@repo_id
}
.import-target")
origin_target = target_field.text()
project_name = "
#{
@project_name
}
"
origin_namespace = "
#{
@target_namespace
}
"
target_field.empty()
target_field.append("<p class='alert alert-danger'>This namespace already been taken! Please choose another one</p>")
target_field.append("<input type='text' name='target_namespace' />")
target_field.append("/" + project_name)
target_field.data("project_name", project_name)
target_field.find('input').prop("value", origin_namespace)
-
else
:plain
job = $("tr#repo_
#{
@repo_id
}
")
job.attr("id", "project_
#{
@project
.
id
}
")
$("table.import-jobs tbody").prepend(job)
job.addClass("active").find(".import-actions").html("<i class='fa fa-spinner fa-spin'></i> started")
app/views/import/gitlab/status.html.haml
View file @
1ac20698
...
...
@@ -34,30 +34,6 @@
%td
.import-actions.job-status
=
button_tag
"Add"
,
class:
"btn btn-add-to-import"
:coffeescript
$(".btn-add-to-import").click () ->
new_namespace = null
tr = $(this).closest("tr")
id = tr.attr("id").replace("repo_", "")
if tr.find(".import-target input").length > 0
new_namespace = tr.find(".import-target input").prop("value")
tr.find(".import-target").empty().append(new_namespace + "/" + tr.find(".import-target").data("project_name"))
$.post "
#{
import_gitlab_url
}
", {repo_id: id, new_namespace: new_namespace}, dataType: 'script'
setInterval (->
$.get "
#{
jobs_import_gitlab_path
}
", (data)->
$.each data, (i, job) ->
job_item = $("#project_" + job.id)
status_field = job_item.find(".job-status")
if job.import_status == 'finished'
job_item.removeClass("active").addClass("success")
status_field.html('<span class="cgreen"><i class="fa fa-check"></i> done</span>')
else if job.import_status == 'started'
status_field.html("<i class='fa fa-spinner fa-spin'></i> started")
else
status_field.html(job.import_status)
), 4000
$ ->
new ImporterStatus("
#{
jobs_import_gitlab_path
}
", "
#{
import_gitlab_url
}
")
app/views/projects/_github_import_modal.html.haml
View file @
1ac20698
...
...
@@ -7,16 +7,3 @@
.modal-body
You need to setup integration with GitHub first.
=
link_to
'How to setup integration with GitHub'
,
'https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/integration/github.md'
\ No newline at end of file
:javascript
$
(
function
(){
var
import_modal
=
$
(
'
#github_import_modal
'
).
modal
({
modal
:
true
,
show
:
false
});
$
(
'
.how_to_import_link
'
).
bind
(
"
click
"
,
function
(
e
){
e
.
preventDefault
();
import_modal
.
show
();
});
$
(
'
.modal-header .close
'
).
bind
(
"
click
"
,
function
(){
import_modal
.
hide
();
})
})
app/views/projects/_gitlab_import_modal.html.haml
View file @
1ac20698
...
...
@@ -7,16 +7,3 @@
.modal-body
You need to setup integration with GitLab first.
=
link_to
'How to setup integration with GitLab'
,
'https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/integration/gitlab.md'
\ No newline at end of file
:javascript
$
(
function
(){
var
import_modal
=
$
(
'
#gitlab_import_modal
'
).
modal
({
modal
:
true
,
show
:
false
});
$
(
'
.how_to_import_link
'
).
bind
(
"
click
"
,
function
(
e
){
e
.
preventDefault
();
import_modal
.
show
();
});
$
(
'
.modal-header .close
'
).
bind
(
"
click
"
,
function
(){
import_modal
.
hide
();
})
})
app/views/projects/new.html.haml
View file @
1ac20698
...
...
@@ -92,3 +92,11 @@
%i
.fa.fa-spinner.fa-spin
Creating project
&
repository.
%p
Please wait a moment, this page will automatically refresh when ready.
:coffeescript
$ ->
$('.how_to_import_link').bind 'click', (e) ->
e.preventDefault()
import_modal = $(this).parent().find(".modal").show()
$('.modal-header .close').bind 'click', ->
$(".modal").hide()
\ No newline at end of file
app/workers/repository_import_worker.rb
View file @
1ac20698
...
...
@@ -10,12 +10,12 @@ class RepositoryImportWorker
project
.
path_with_namespace
,
project
.
import_url
)
if
project
.
import_type
==
'github'
result_of_data_import
=
Gitlab
::
GithubImport
::
Importer
.
new
(
project
).
execute
result_of_data_import
=
if
project
.
import_type
==
'github'
Gitlab
::
GithubImport
::
Importer
.
new
(
project
).
execute
elsif
project
.
import_type
==
'gitlab'
result_of_data_import
=
Gitlab
::
GitlabImport
::
Importer
.
new
(
project
).
execute
Gitlab
::
GitlabImport
::
Importer
.
new
(
project
).
execute
else
result_of_data_import
=
true
true
end
if
result
&&
result_of_data_import
...
...
lib/gitlab/github_import/importer.rb
View file @
1ac20698
...
...
@@ -43,7 +43,8 @@ module Gitlab
end
def
gl_user_id
(
project
,
github_id
)
user
=
User
.
joins
(
:identities
).
find_by
(
"identities.extern_uid = ?"
,
github_id
.
to_s
)
user
=
User
.
joins
(
:identities
).
find_by
(
"identities.extern_uid = ? AND identities.provider = 'github'"
,
github_id
.
to_s
)
(
user
&&
user
.
id
)
||
project
.
creator_id
end
end
...
...
lib/gitlab/gitlab_import/importer.rb
View file @
1ac20698
...
...
@@ -42,7 +42,7 @@ module Gitlab
private
def
gl_user_id
(
project
,
gitlab_id
)
user
=
User
.
joins
(
:identities
).
find_by
(
"identities.extern_uid = ?"
,
gitlab_id
.
to_s
)
user
=
User
.
joins
(
:identities
).
find_by
(
"identities.extern_uid = ?
AND identities.provider = 'gitlab'
"
,
gitlab_id
.
to_s
)
(
user
&&
user
.
id
)
||
project
.
creator_id
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment