BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
b3c90dd5
Commit
b3c90dd5
authored
Feb 05, 2015
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
GitHub importer refactoring
parent
85c2cb2a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
31 deletions
+45
-31
github_controller.rb
app/controllers/import/github_controller.rb
+7
-15
client.rb
lib/gitlab/github_import/client.rb
+30
-2
importer.rb
lib/gitlab/github_import/importer.rb
+2
-8
github_controller_spec.rb
spec/controllers/import/github_controller_spec.rb
+6
-6
No files found.
app/controllers/import/github_controller.rb
View file @
b3c90dd5
...
...
@@ -4,16 +4,16 @@ class Import::GithubController < Import::BaseController
rescue_from
Octokit
::
Unauthorized
,
with: :github_unauthorized
def
callback
token
=
client
.
auth_code
.
get_token
(
params
[
:code
]).
token
token
=
client
.
get_token
(
params
[
:code
])
current_user
.
github_access_token
=
token
current_user
.
save
redirect_to
status_import_github_url
end
def
status
@repos
=
octo_
client
.
repos
octo_
client
.
orgs
.
each
do
|
org
|
@repos
+=
octo_
client
.
repos
(
org
.
login
)
@repos
=
client
.
repos
client
.
orgs
.
each
do
|
org
|
@repos
+=
client
.
repos
(
org
.
login
)
end
@already_added_projects
=
current_user
.
created_projects
.
where
(
import_type:
"github"
)
...
...
@@ -29,7 +29,7 @@ class Import::GithubController < Import::BaseController
def
create
@repo_id
=
params
[
:repo_id
].
to_i
repo
=
octo_
client
.
repo
(
@repo_id
)
repo
=
client
.
repo
(
@repo_id
)
@target_namespace
=
params
[
:new_namespace
].
presence
||
repo
.
owner
.
login
@project_name
=
repo
.
name
...
...
@@ -41,12 +41,7 @@ class Import::GithubController < Import::BaseController
private
def
client
@client
||=
Gitlab
::
GithubImport
::
Client
.
new
.
client
end
def
octo_client
Octokit
.
auto_paginate
=
true
@octo_client
||=
Octokit
::
Client
.
new
(
access_token:
current_user
.
github_access_token
)
@client
||=
Gitlab
::
GithubImport
::
Client
.
new
(
current_user
.
github_access_token
)
end
def
github_auth
...
...
@@ -56,10 +51,7 @@ class Import::GithubController < Import::BaseController
end
def
go_to_github_for_permissions
redirect_to
client
.
auth_code
.
authorize_url
({
redirect_uri:
callback_import_github_url
,
scope:
"repo, user, user:email"
})
redirect_to
client
.
authorize_url
(
callback_import_github_url
)
end
def
github_unauthorized
...
...
lib/gitlab/github_import/client.rb
View file @
b3c90dd5
module
Gitlab
module
GithubImport
class
Client
attr_reader
:client
attr_reader
:client
,
:api
def
initialize
def
initialize
(
access_token
)
@client
=
::
OAuth2
::
Client
.
new
(
config
.
app_id
,
config
.
app_secret
,
github_options
)
if
access_token
::
Octokit
.
auto_paginate
=
true
@api
=
::
Octokit
::
Client
.
new
(
access_token:
access_token
)
end
end
def
authorize_url
(
redirect_uri
)
client
.
auth_code
.
authorize_url
({
redirect_uri:
redirect_uri
,
scope:
"repo, user, user:email"
})
end
def
get_token
(
code
)
client
.
auth_code
.
get_token
(
code
).
token
end
def
method_missing
(
method
,
*
args
,
&
block
)
if
api
.
respond_to?
(
method
)
api
.
send
(
method
,
*
args
,
&
block
)
else
super
(
method
,
*
args
,
&
block
)
end
end
def
respond_to?
(
method
)
api
.
respond_to?
(
method
)
||
super
end
private
...
...
lib/gitlab/github_import/importer.rb
View file @
b3c90dd5
module
Gitlab
module
GithubImport
class
Importer
attr_reader
:project
attr_reader
:project
,
:client
def
initialize
(
project
)
@project
=
project
@client
=
Client
.
new
(
project
.
creator
.
github_access_token
)
@formatter
=
Gitlab
::
ImportFormatter
.
new
end
def
execute
client
=
octo_client
(
project
.
creator
.
github_access_token
)
#Issues && Comments
client
.
list_issues
(
project
.
import_source
,
state: :all
).
each
do
|
issue
|
if
issue
.
pull_request
.
nil?
...
...
@@ -37,11 +36,6 @@ module Gitlab
private
def
octo_client
(
access_token
)
::
Octokit
.
auto_paginate
=
true
::
Octokit
::
Client
.
new
(
access_token:
access_token
)
end
def
gl_user_id
(
project
,
github_id
)
user
=
User
.
joins
(
:identities
).
find_by
(
"identities.extern_uid = ? AND identities.provider = 'github'"
,
github_id
.
to_s
)
...
...
spec/controllers/import/github_controller_spec.rb
View file @
b3c90dd5
...
...
@@ -10,7 +10,7 @@ describe Import::GithubController do
describe
"GET callback"
do
it
"updates access token"
do
token
=
"asdasd12345"
Gitlab
::
GithubImport
::
Client
.
any_instance
.
stub
_chain
(
:client
,
:auth_code
,
:get_token
,
:
token
).
and_return
(
token
)
Gitlab
::
GithubImport
::
Client
.
any_instance
.
stub
(
:get_
token
).
and_return
(
token
)
Gitlab
.
config
.
omniauth
.
providers
<<
OpenStruct
.
new
(
app_id:
"asd123"
,
app_secret:
"asd123"
,
name:
"github"
)
get
:callback
...
...
@@ -27,8 +27,8 @@ describe Import::GithubController do
it
"assigns variables"
do
@project
=
create
(
:project
,
import_type:
'github'
,
creator_id:
user
.
id
)
controller
.
stub_chain
(
:
octo_
client
,
:repos
).
and_return
([
@repo
])
controller
.
stub_chain
(
:
octo_
client
,
:orgs
).
and_return
([])
controller
.
stub_chain
(
:client
,
:repos
).
and_return
([
@repo
])
controller
.
stub_chain
(
:client
,
:orgs
).
and_return
([])
get
:status
...
...
@@ -38,8 +38,8 @@ describe Import::GithubController do
it
"does not show already added project"
do
@project
=
create
(
:project
,
import_type:
'github'
,
creator_id:
user
.
id
,
import_source:
'asd/vim'
)
controller
.
stub_chain
(
:
octo_
client
,
:repos
).
and_return
([
@repo
])
controller
.
stub_chain
(
:
octo_
client
,
:orgs
).
and_return
([])
controller
.
stub_chain
(
:client
,
:repos
).
and_return
([
@repo
])
controller
.
stub_chain
(
:client
,
:orgs
).
and_return
([])
get
:status
...
...
@@ -57,7 +57,7 @@ describe Import::GithubController do
namespace
=
create
(
:namespace
,
name:
"john"
,
owner:
user
)
Gitlab
::
GithubImport
::
ProjectCreator
.
should_receive
(
:new
).
with
(
@repo
,
namespace
,
user
).
and_return
(
double
(
execute:
true
))
controller
.
stub_chain
(
:
octo_
client
,
:repo
).
and_return
(
@repo
)
controller
.
stub_chain
(
:client
,
:repo
).
and_return
(
@repo
)
post
:create
,
format: :js
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