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
acc312fc
Commit
acc312fc
authored
Feb 20, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of gitlab.com:gitlab-org/gitlab-ce
parents
2617f8d1
f5888bd2
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
289 additions
and
0 deletions
+289
-0
app/controllers/import/gitorious_controller.rb
app/controllers/import/gitorious_controller.rb
+43
-0
app/views/import/gitorious/status.html.haml
app/views/import/gitorious/status.html.haml
+41
-0
app/views/projects/new.html.haml
app/views/projects/new.html.haml
+7
-0
config/routes.rb
config/routes.rb
+6
-0
lib/gitlab/gitorious_import/client.rb
lib/gitlab/gitorious_import/client.rb
+63
-0
lib/gitlab/gitorious_import/project_creator.rb
lib/gitlab/gitorious_import/project_creator.rb
+39
-0
spec/controllers/import/gitorious_controller_spec.rb
spec/controllers/import/gitorious_controller_spec.rb
+67
-0
spec/lib/gitlab/gitorious_import/project_creator.rb
spec/lib/gitlab/gitorious_import/project_creator.rb
+23
-0
No files found.
app/controllers/import/gitorious_controller.rb
0 → 100644
View file @
acc312fc
class
Import::GitoriousController
<
Import
::
BaseController
def
new
redirect_to
client
.
authorize_url
(
callback_import_gitorious_url
)
end
def
callback
session
[
:gitorious_repos
]
=
params
[
:repos
]
redirect_to
status_import_gitorious_url
end
def
status
@repos
=
client
.
repos
@already_added_projects
=
current_user
.
created_projects
.
where
(
import_type:
"gitorious"
)
already_added_projects_names
=
@already_added_projects
.
pluck
(
:import_source
)
@repos
.
to_a
.
reject!
{
|
repo
|
already_added_projects_names
.
include?
repo
.
full_name
}
end
def
jobs
jobs
=
current_user
.
created_projects
.
where
(
import_type:
"gitorious"
).
to_json
(
only:
[
:id
,
:import_status
])
render
json:
jobs
end
def
create
@repo_id
=
params
[
:repo_id
]
repo
=
client
.
repo
(
@repo_id
)
@target_namespace
=
params
[
:new_namespace
].
presence
||
repo
.
namespace
@project_name
=
repo
.
name
namespace
=
get_or_create_namespace
||
(
render
and
return
)
@project
=
Gitlab
::
GitoriousImport
::
ProjectCreator
.
new
(
repo
,
namespace
,
current_user
).
execute
end
private
def
client
@client
||=
Gitlab
::
GitoriousImport
::
Client
.
new
(
session
[
:gitorious_repos
])
end
end
app/views/import/gitorious/status.html.haml
0 → 100644
View file @
acc312fc
%h3
.page-title
%i
.fa.fa-gitorious
Import repositories from Gitorious.org
%p
.light
Select projects you want to import.
%hr
%p
=
button_tag
'Import all projects'
,
class:
"btn btn-success js-import-all"
%table
.table.import-jobs
%thead
%tr
%th
From Gitorious
%th
To GitLab
%th
Status
%tbody
-
@already_added_projects
.
each
do
|
project
|
%tr
{
id:
"project_#{project.id}"
,
class:
"#{project_status_css_class(project.import_status)}"
}
%td
=
project
.
import_source
%td
%strong
=
link_to
project
.
path_with_namespace
,
project
%td
.job-status
-
if
project
.
import_status
==
'finished'
%span
.cgreen
%i
.fa.fa-check
done
-
else
=
project
.
human_import_status_name
-
@repos
.
each
do
|
repo
|
%tr
{
id:
"repo_#{repo.id}"
}
%td
=
repo
.
full_name
%td
.import-target
=
repo
.
full_name
%td
.import-actions.job-status
=
button_tag
"Import"
,
class:
"btn js-add-to-import"
:coffeescript
$ ->
new ImporterStatus("
#{
jobs_import_gitorious_path
}
", "
#{
import_gitorious_path
}
")
app/views/projects/new.html.haml
View file @
acc312fc
...
@@ -66,6 +66,13 @@
...
@@ -66,6 +66,13 @@
Import projects from GitLab.com
Import projects from GitLab.com
=
render
'gitlab_import_modal'
=
render
'gitlab_import_modal'
.project-import.form-group
.col-sm-2
.col-sm-10
=
link_to
new_import_gitorious_path
do
%i
.fa.fa-heart
Import projects from Gitorious.org
%hr
.prepend-botton-10
%hr
.prepend-botton-10
.form-group
.form-group
...
...
config/routes.rb
View file @
acc312fc
...
@@ -67,6 +67,12 @@ Gitlab::Application.routes.draw do
...
@@ -67,6 +67,12 @@ Gitlab::Application.routes.draw do
get
:callback
get
:callback
get
:jobs
get
:jobs
end
end
resource
:gitorious
,
only:
[
:create
,
:new
],
controller: :gitorious
do
get
:status
get
:callback
get
:jobs
end
end
end
...
...
lib/gitlab/gitorious_import/client.rb
0 → 100644
View file @
acc312fc
module
Gitlab
module
GitoriousImport
GITORIOUS_HOST
=
"https://gitorious.org"
class
Client
attr_reader
:repo_list
def
initialize
(
repo_list
)
@repo_list
=
repo_list
end
def
authorize_url
(
redirect_uri
)
"
#{
GITORIOUS_HOST
}
/gitlab-import?callback_url=
#{
redirect_uri
}
"
end
def
repos
@repos
||=
repo_names
.
map
{
|
full_name
|
Repository
.
new
(
full_name
)
}
end
def
repo
(
id
)
repos
.
find
{
|
repo
|
repo
.
id
==
id
}
end
private
def
repo_names
repo_list
.
to_s
.
split
(
','
).
map
(
&
:strip
).
reject
(
&
:blank?
)
end
end
Repository
=
Struct
.
new
(
:full_name
)
do
def
id
Digest
::
SHA1
.
hexdigest
(
full_name
)
end
def
namespace
segments
.
first
end
def
path
segments
.
last
end
def
name
path
.
titleize
end
def
description
""
end
def
import_url
"
#{
GITORIOUS_HOST
}
/
#{
full_name
}
.git"
end
private
def
segments
full_name
.
split
(
'/'
)
end
end
end
end
lib/gitlab/gitorious_import/project_creator.rb
0 → 100644
View file @
acc312fc
module
Gitlab
module
GitoriousImport
class
ProjectCreator
attr_reader
:repo
,
:namespace
,
:current_user
def
initialize
(
repo
,
namespace
,
current_user
)
@repo
=
repo
@namespace
=
namespace
@current_user
=
current_user
end
def
execute
@project
=
Project
.
new
(
name:
repo
.
name
,
path:
repo
.
path
,
description:
repo
.
description
,
namespace:
namespace
,
creator:
current_user
,
visibility_level:
Gitlab
::
VisibilityLevel
::
PUBLIC
,
import_type:
"gitorious"
,
import_source:
repo
.
full_name
,
import_url:
repo
.
import_url
)
if
@project
.
save!
@project
.
reload
if
@project
.
import_failed?
@project
.
import_retry
else
@project
.
import_start
end
end
@project
end
end
end
end
spec/controllers/import/gitorious_controller_spec.rb
0 → 100644
View file @
acc312fc
require
'spec_helper'
describe
Import
::
GitoriousController
do
let
(
:user
)
{
create
(
:user
)
}
before
do
sign_in
(
user
)
end
describe
"GET new"
do
it
"redirects to import endpoint on gitorious.org"
do
get
:new
expect
(
controller
).
to
redirect_to
(
"https://gitorious.org/gitlab-import?callback_url=http://test.host/import/gitorious/callback"
)
end
end
describe
"GET callback"
do
it
"stores repo list in session"
do
get
:callback
,
repos:
'foo/bar,baz/qux'
expect
(
session
[
:gitorious_repos
]).
to
eq
(
'foo/bar,baz/qux'
)
end
end
describe
"GET status"
do
before
do
@repo
=
OpenStruct
.
new
(
full_name:
'asd/vim'
)
end
it
"assigns variables"
do
@project
=
create
(
:project
,
import_type:
'gitorious'
,
creator_id:
user
.
id
)
controller
.
stub_chain
(
:client
,
:repos
).
and_return
([
@repo
])
get
:status
expect
(
assigns
(
:already_added_projects
)).
to
eq
([
@project
])
expect
(
assigns
(
:repos
)).
to
eq
([
@repo
])
end
it
"does not show already added project"
do
@project
=
create
(
:project
,
import_type:
'gitorious'
,
creator_id:
user
.
id
,
import_source:
'asd/vim'
)
controller
.
stub_chain
(
:client
,
:repos
).
and_return
([
@repo
])
get
:status
expect
(
assigns
(
:already_added_projects
)).
to
eq
([
@project
])
expect
(
assigns
(
:repos
)).
to
eq
([])
end
end
describe
"POST create"
do
before
do
@repo
=
Gitlab
::
GitoriousImport
::
Repository
.
new
(
'asd/vim'
)
end
it
"takes already existing namespace"
do
namespace
=
create
(
:namespace
,
name:
"asd"
,
owner:
user
)
expect
(
Gitlab
::
GitoriousImport
::
ProjectCreator
).
to
receive
(
:new
).
with
(
@repo
,
namespace
,
user
).
and_return
(
double
(
execute:
true
))
controller
.
stub_chain
(
:client
,
:repo
).
and_return
(
@repo
)
post
:create
,
format: :js
end
end
end
spec/lib/gitlab/gitorious_import/project_creator.rb
0 → 100644
View file @
acc312fc
require
'spec_helper'
describe
Gitlab
::
GitoriousImport
::
ProjectCreator
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:repo
)
{
Gitlab
::
GitoriousImport
::
Repository
.
new
(
'foo/bar-baz-qux'
)
}
let
(
:namespace
){
create
(
:namespace
)
}
it
'creates project'
do
allow_any_instance_of
(
Project
).
to
receive
(
:add_import_job
)
project_creator
=
Gitlab
::
GitoriousImport
::
ProjectCreator
.
new
(
repo
,
namespace
,
user
)
project_creator
.
execute
project
=
Project
.
last
expect
(
project
.
name
).
to
eq
(
"Bar Baz Qux"
)
expect
(
project
.
path
).
to
eq
(
"bar-baz-qux"
)
expect
(
project
.
namespace
).
to
eq
(
namespace
)
expect
(
project
.
visibility_level
).
to
eq
(
Gitlab
::
VisibilityLevel
::
PUBLIC
)
expect
(
project
.
import_type
).
to
eq
(
"gitorious"
)
expect
(
project
.
import_source
).
to
eq
(
"foo/bar-baz-qux"
)
expect
(
project
.
import_url
).
to
eq
(
"https://gitorious.org/foo/bar-baz-qux.git"
)
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