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
33349dd5
Commit
33349dd5
authored
Feb 02, 2015
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
GitLab.com integration: refactoring
parent
713bc152
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
52 additions
and
32 deletions
+52
-32
app/controllers/import/github_controller.rb
app/controllers/import/github_controller.rb
+3
-3
app/controllers/import/gitlab_controller.rb
app/controllers/import/gitlab_controller.rb
+4
-4
app/views/import/github/create.js.haml
app/views/import/github/create.js.haml
+0
-0
app/views/import/github/status.html.haml
app/views/import/github/status.html.haml
+2
-2
app/views/import/gitlab/create.js.haml
app/views/import/gitlab/create.js.haml
+0
-0
app/views/import/gitlab/status.html.haml
app/views/import/gitlab/status.html.haml
+2
-2
app/views/projects/new.html.haml
app/views/projects/new.html.haml
+2
-2
config/routes.rb
config/routes.rb
+4
-4
doc/integration/gitlab.md
doc/integration/gitlab.md
+1
-1
lib/gitlab/github_import/client.rb
lib/gitlab/github_import/client.rb
+1
-1
lib/gitlab/github_import/importer.rb
lib/gitlab/github_import/importer.rb
+6
-3
lib/gitlab/gitlab_import/client.rb
lib/gitlab/gitlab_import/client.rb
+2
-2
lib/gitlab/gitlab_import/importer.rb
lib/gitlab/gitlab_import/importer.rb
+6
-4
lib/gitlab/import_formatter.rb
lib/gitlab/import_formatter.rb
+15
-0
spec/controllers/import/github_controller_spec.rb
spec/controllers/import/github_controller_spec.rb
+2
-2
spec/controllers/import/gitlab_controller_spec.rb
spec/controllers/import/gitlab_controller_spec.rb
+2
-2
No files found.
app/controllers/import
ers/githubs
_controller.rb
→
app/controllers/import
/github
_controller.rb
View file @
33349dd5
class
Import
ers::Githubs
Controller
<
ApplicationController
class
Import
::Github
Controller
<
ApplicationController
before_filter
:github_auth
,
except: :callback
rescue_from
Octokit
::
Unauthorized
,
with: :github_unauthorized
...
...
@@ -7,7 +7,7 @@ class Importers::GithubsController < ApplicationController
token
=
client
.
auth_code
.
get_token
(
params
[
:code
]).
token
current_user
.
github_access_token
=
token
current_user
.
save
redirect_to
status_import
ers
_github_url
redirect_to
status_import_github_url
end
def
status
...
...
@@ -69,7 +69,7 @@ class Importers::GithubsController < ApplicationController
def
go_to_github_for_permissions
redirect_to
client
.
auth_code
.
authorize_url
({
redirect_uri:
callback_import
ers
_github_url
,
redirect_uri:
callback_import_github_url
,
scope:
"repo, user, user:email"
})
end
...
...
app/controllers/import
ers/gitlabs
_controller.rb
→
app/controllers/import
/gitlab
_controller.rb
View file @
33349dd5
class
Import
ers::Gitlabs
Controller
<
ApplicationController
class
Import
::Gitlab
Controller
<
ApplicationController
before_filter
:gitlab_auth
,
except: :callback
rescue_from
OAuth2
::
Error
,
with: :gitlab_unauthorized
def
callback
token
=
client
.
get_token
(
params
[
:code
],
callback_import
ers
_gitlab_url
)
token
=
client
.
get_token
(
params
[
:code
],
callback_import_gitlab_url
)
current_user
.
gitlab_access_token
=
token
current_user
.
save
redirect_to
status_import
ers
_gitlab_url
redirect_to
status_import_gitlab_url
end
def
status
...
...
@@ -60,7 +60,7 @@ class Importers::GitlabsController < ApplicationController
end
def
go_to_gitlab_for_permissions
redirect_to
client
.
authorize_url
(
callback_import
ers
_gitlab_url
)
redirect_to
client
.
authorize_url
(
callback_import_gitlab_url
)
end
def
gitlab_unauthorized
...
...
app/views/import
ers/githubs
/create.js.haml
→
app/views/import
/github
/create.js.haml
View file @
33349dd5
File moved
app/views/import
ers/githubs
/status.html.haml
→
app/views/import
/github
/status.html.haml
View file @
33349dd5
...
...
@@ -43,11 +43,11 @@
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
ers
_github_url
}
", {repo_id: id, new_namespace: new_namespace}, dataType: 'script'
$.post "
#{
import_github_url
}
", {repo_id: id, new_namespace: new_namespace}, dataType: 'script'
setInterval (->
$.get "
#{
jobs_import
ers
_github_path
}
", (data)->
$.get "
#{
jobs_import_github_path
}
", (data)->
$.each data, (i, job) ->
job_item = $("#project_" + job.id)
status_field = job_item.find(".job-status")
...
...
app/views/import
ers/gitlabs
/create.js.haml
→
app/views/import
/gitlab
/create.js.haml
View file @
33349dd5
File moved
app/views/import
ers/gitlabs
/status.html.haml
→
app/views/import
/gitlab
/status.html.haml
View file @
33349dd5
...
...
@@ -43,11 +43,11 @@
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
ers
_gitlab_url
}
", {repo_id: id, new_namespace: new_namespace}, dataType: 'script'
$.post "
#{
import_gitlab_url
}
", {repo_id: id, new_namespace: new_namespace}, dataType: 'script'
setInterval (->
$.get "
#{
jobs_import
ers
_gitlab_path
}
", (data)->
$.get "
#{
jobs_import_gitlab_path
}
", (data)->
$.each data, (i, job) ->
job_item = $("#project_" + job.id)
status_field = job_item.find(".job-status")
...
...
app/views/projects/new.html.haml
View file @
33349dd5
...
...
@@ -44,7 +44,7 @@
.col-sm-2
.col-sm-10
-
if
github_import_enabled?
=
link_to
status_import
ers
_github_path
do
=
link_to
status_import_github_path
do
%i
.fa.fa-github
Import projects from GitHub
-
else
...
...
@@ -57,7 +57,7 @@
.col-sm-2
.col-sm-10
-
if
gitlab_import_enabled?
=
link_to
status_import
ers
_gitlab_path
do
=
link_to
status_import_gitlab_path
do
%i
.fa.fa-heart
Import projects from GitLab.com
-
else
...
...
config/routes.rb
View file @
33349dd5
...
...
@@ -53,16 +53,16 @@ Gitlab::Application.routes.draw do
#
# Import
ers
# Import
#
namespace
:import
ers
do
resource
:github
,
only:
[
:create
,
:new
]
do
namespace
:import
do
resource
:github
,
only:
[
:create
,
:new
]
,
controller: :github
do
get
:status
get
:callback
get
:jobs
end
resource
:gitlab
,
only:
[
:create
,
:new
]
do
resource
:gitlab
,
only:
[
:create
,
:new
]
,
controller: :gitlab
do
get
:status
get
:callback
get
:jobs
...
...
doc/integration/gitlab.md
View file @
33349dd5
...
...
@@ -15,7 +15,7 @@ To enable the GitLab OmniAuth provider you must register your application with G
-
Redirect URI:
```
http://gitlab.example.com/import
ers
/gitlab/callback
http://gitlab.example.com/import/gitlab/callback
http://gitlab.example.com/users/auth/gitlab/callback
```
...
...
lib/gitlab/github_import/client.rb
View file @
33349dd5
...
...
@@ -14,7 +14,7 @@ module Gitlab
private
def
config
Gitlab
.
config
.
omniauth
.
providers
.
select
{
|
provider
|
provider
.
name
==
"github"
}.
first
Gitlab
.
config
.
omniauth
.
providers
.
find
{
|
provider
|
provider
.
name
==
"github"
}
end
def
github_options
...
...
lib/gitlab/github_import/importer.rb
View file @
33349dd5
...
...
@@ -5,6 +5,7 @@ module Gitlab
def
initialize
(
project
)
@project
=
project
@formatter
=
Gitlab
::
ImportFormatter
.
new
end
def
execute
...
...
@@ -13,12 +14,14 @@ module Gitlab
#Issues && Comments
client
.
list_issues
(
project
.
import_source
,
state: :all
).
each
do
|
issue
|
if
issue
.
pull_request
.
nil?
body
=
"*Created by:
#{
issue
.
user
.
login
}
*
\n\n
#{
issue
.
body
}
"
body
=
@formatter
.
author_line
(
issue
.
user
.
login
,
issue
.
body
)
if
issue
.
comments
>
0
body
+=
"
\n\n\n
**Imported comments:**
\n
"
body
+=
@formatter
.
comments_header
client
.
issue_comments
(
project
.
import_source
,
issue
.
number
).
each
do
|
c
|
body
+=
"
\n\n
*By
#{
c
.
user
.
login
}
on
#{
c
.
created_at
}
*
\n\n
#{
c
.
body
}
"
body
+=
@formatter
.
comment_to_md
(
c
.
user
.
login
,
c
.
created_at
,
c
.
body
)
end
end
...
...
lib/gitlab/gitlab_import/client.rb
View file @
33349dd5
...
...
@@ -13,7 +13,7 @@ module Gitlab
)
if
access_token
@api
=
OAuth2
::
AccessToken
.
from_hash
(
@client
,
:access_token
=>
access_token
)
@api
=
OAuth2
::
AccessToken
.
from_hash
(
@client
,
access_token:
access_token
)
end
end
...
...
@@ -67,7 +67,7 @@ module Gitlab
end
def
config
Gitlab
.
config
.
omniauth
.
providers
.
select
{
|
provider
|
provider
.
name
==
"gitlab"
}.
first
Gitlab
.
config
.
omniauth
.
providers
.
find
{
|
provider
|
provider
.
name
==
"gitlab"
}
end
def
github_options
...
...
lib/gitlab/gitlab_import/importer.rb
View file @
33349dd5
...
...
@@ -6,6 +6,7 @@ module Gitlab
def
initialize
(
project
)
@project
=
project
@client
=
Client
.
new
(
project
.
creator
.
gitlab_access_token
)
@formatter
=
Gitlab
::
ImportFormatter
.
new
end
def
execute
...
...
@@ -15,15 +16,16 @@ module Gitlab
issues
=
client
.
issues
(
project_identifier
)
issues
.
each
do
|
issue
|
body
=
"*Created by:
#{
issue
[
"author"
][
"name"
]
}
*
\n\n
#{
issue
[
"description"
]
}
"
body
=
@formatter
.
author_line
(
issue
[
"author"
][
"name"
],
issue
[
"description"
])
comments
=
client
.
issue_comments
(
project_identifier
,
issue
[
"id"
])
if
comments
.
any?
body
+=
"
\n\n\n
**Imported comments:**
\n
"
body
+=
@formatter
.
comments_header
end
comments
.
each
do
|
comment
|
body
+=
"
\n\n
*By
#{
comment
[
"author"
][
"name"
]
}
on
#{
comment
[
"created_at"
]
}
*
\n\n
#{
comment
[
"body"
]
}
"
body
+=
@formatter
.
comment_to_md
(
comment
[
"author"
][
"name"
],
comment
[
"created_at"
],
comment
[
"body"
])
end
project
.
issues
.
create!
(
...
...
lib/gitlab/import_formatter.rb
0 → 100644
View file @
33349dd5
module
Gitlab
class
ImportFormatter
def
comment_to_md
(
author
,
date
,
body
)
"
\n\n
*By
#{
author
}
on
#{
date
}
*
\n\n
#{
body
}
"
end
def
comments_header
"
\n\n\n
**Imported comments:**
\n
"
end
def
author_line
(
author
,
body
)
"*Created by:
#{
author
}
*
\n\n
#{
body
}
"
end
end
end
\ No newline at end of file
spec/controllers/import
ers/githubs
_controller_spec.rb
→
spec/controllers/import
/github
_controller_spec.rb
View file @
33349dd5
require
'spec_helper'
describe
Import
ers
::
Githubs
Controller
do
describe
Import
::
Github
Controller
do
let
(
:user
)
{
create
(
:user
,
github_access_token:
'asd123'
)
}
before
do
...
...
@@ -16,7 +16,7 @@ describe Importers::GithubsController do
get
:callback
user
.
reload
.
github_access_token
.
should
==
token
controller
.
should
redirect_to
(
status_import
ers
_github_url
)
controller
.
should
redirect_to
(
status_import_github_url
)
end
end
...
...
spec/controllers/import
ers/gitlabs
_controller_spec.rb
→
spec/controllers/import
/gitlab
_controller_spec.rb
View file @
33349dd5
require
'spec_helper'
describe
Import
ers
::
Gitlabs
Controller
do
describe
Import
::
Gitlab
Controller
do
let
(
:user
)
{
create
(
:user
,
gitlab_access_token:
'asd123'
)
}
before
do
...
...
@@ -16,7 +16,7 @@ describe Importers::GitlabsController do
get
:callback
user
.
reload
.
gitlab_access_token
.
should
==
token
controller
.
should
redirect_to
(
status_import
ers
_gitlab_url
)
controller
.
should
redirect_to
(
status_import_gitlab_url
)
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