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
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
782aab13
Commit
782aab13
authored
Apr 19, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pass a options hash to Github::Client
parent
ac1634fa
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
37 additions
and
27 deletions
+37
-27
lib/github/client.rb
lib/github/client.rb
+3
-3
lib/github/collection.rb
lib/github/collection.rb
+7
-1
lib/github/import.rb
lib/github/import.rb
+12
-11
lib/github/representation/base.rb
lib/github/representation/base.rb
+4
-3
lib/github/representation/comment.rb
lib/github/representation/comment.rb
+1
-1
lib/github/representation/issuable.rb
lib/github/representation/issuable.rb
+2
-2
lib/github/representation/pull_request.rb
lib/github/representation/pull_request.rb
+3
-2
lib/github/representation/user.rb
lib/github/representation/user.rb
+1
-1
lib/github/user.rb
lib/github/user.rb
+4
-3
No files found.
lib/github/client.rb
View file @
782aab13
...
@@ -2,9 +2,9 @@ module Github
...
@@ -2,9 +2,9 @@ module Github
class
Client
class
Client
attr_reader
:connection
attr_reader
:connection
def
initialize
(
token
)
def
initialize
(
options
)
@connection
=
Faraday
.
new
(
url:
'https://api.github.com'
)
do
|
faraday
|
@connection
=
Faraday
.
new
(
url:
options
.
fetch
(
:url
)
)
do
|
faraday
|
faraday
.
authorization
'token'
,
token
faraday
.
authorization
'token'
,
options
.
fetch
(
:token
)
faraday
.
adapter
:net_http
faraday
.
adapter
:net_http
end
end
end
end
...
...
lib/github/collection.rb
View file @
782aab13
module
Github
module
Github
class
Collection
class
Collection
attr_reader
:options
def
initialize
(
options
)
@options
=
options
end
def
fetch
(
url
,
query
=
{})
def
fetch
(
url
,
query
=
{})
return
[]
if
url
.
blank?
return
[]
if
url
.
blank?
...
@@ -16,7 +22,7 @@ module Github
...
@@ -16,7 +22,7 @@ module Github
private
private
def
client
def
client
@client
||=
Github
::
Client
.
new
@client
||=
Github
::
Client
.
new
(
options
)
end
end
end
end
end
end
lib/github/import.rb
View file @
782aab13
...
@@ -27,17 +27,18 @@ module Github
...
@@ -27,17 +27,18 @@ module Github
self
.
reset_callbacks
:validate
self
.
reset_callbacks
:validate
end
end
attr_reader
:project
,
:repository
,
:cached_label_ids
,
:cached_user_ids
,
:errors
attr_reader
:project
,
:repository
,
:
options
,
:
cached_label_ids
,
:cached_user_ids
,
:errors
def
initialize
(
project
)
def
initialize
(
project
,
options
)
@project
=
project
@project
=
project
@repository
=
project
.
repository
@repository
=
project
.
repository
@options
=
options
@cached_label_ids
=
{}
@cached_label_ids
=
{}
@cached_user_ids
=
{}
@cached_user_ids
=
{}
@errors
=
[]
@errors
=
[]
end
end
def
execute
(
owner
,
repo
,
token
)
def
execute
(
owner
,
repo
)
# Fetch repository
# Fetch repository
begin
begin
project
.
create_repository
project
.
create_repository
...
@@ -53,7 +54,7 @@ module Github
...
@@ -53,7 +54,7 @@ module Github
url
=
"/repos/
#{
owner
}
/
#{
repo
}
/labels"
url
=
"/repos/
#{
owner
}
/
#{
repo
}
/labels"
loop
do
loop
do
response
=
Github
::
Client
.
new
.
get
(
url
)
response
=
Github
::
Client
.
new
(
options
)
.
get
(
url
)
response
.
body
.
each
do
|
raw
|
response
.
body
.
each
do
|
raw
|
begin
begin
...
@@ -81,7 +82,7 @@ module Github
...
@@ -81,7 +82,7 @@ module Github
url
=
"/repos/
#{
owner
}
/
#{
repo
}
/milestones"
url
=
"/repos/
#{
owner
}
/
#{
repo
}
/milestones"
loop
do
loop
do
response
=
Github
::
Client
.
new
.
get
(
url
,
state: :all
)
response
=
Github
::
Client
.
new
(
options
)
.
get
(
url
,
state: :all
)
response
.
body
.
each
do
|
raw
|
response
.
body
.
each
do
|
raw
|
begin
begin
...
@@ -109,10 +110,10 @@ module Github
...
@@ -109,10 +110,10 @@ module Github
url
=
"/repos/
#{
owner
}
/
#{
repo
}
/pulls"
url
=
"/repos/
#{
owner
}
/
#{
repo
}
/pulls"
loop
do
loop
do
response
=
Github
::
Client
.
new
.
get
(
url
,
state: :all
,
sort: :created
,
direction: :asc
)
response
=
Github
::
Client
.
new
(
options
)
.
get
(
url
,
state: :all
,
sort: :created
,
direction: :asc
)
response
.
body
.
each
do
|
raw
|
response
.
body
.
each
do
|
raw
|
pull_request
=
Github
::
Representation
::
PullRequest
.
new
(
project
,
raw
)
pull_request
=
Github
::
Representation
::
PullRequest
.
new
(
project
,
raw
,
options
)
merge_request
=
MergeRequest
.
find_or_initialize_by
(
iid:
pull_request
.
iid
,
source_project_id:
project
.
id
)
merge_request
=
MergeRequest
.
find_or_initialize_by
(
iid:
pull_request
.
iid
,
source_project_id:
project
.
id
)
next
unless
merge_request
.
new_record?
&&
pull_request
.
valid?
next
unless
merge_request
.
new_record?
&&
pull_request
.
valid?
...
@@ -160,10 +161,10 @@ module Github
...
@@ -160,10 +161,10 @@ module Github
url
=
"/repos/
#{
owner
}
/
#{
repo
}
/issues"
url
=
"/repos/
#{
owner
}
/
#{
repo
}
/issues"
loop
do
loop
do
response
=
Github
::
Client
.
new
.
get
(
url
,
state: :all
,
sort: :created
,
direction: :asc
)
response
=
Github
::
Client
.
new
(
options
)
.
get
(
url
,
state: :all
,
sort: :created
,
direction: :asc
)
response
.
body
.
each
do
|
raw
|
response
.
body
.
each
do
|
raw
|
representation
=
Github
::
Representation
::
Issue
.
new
(
raw
)
representation
=
Github
::
Representation
::
Issue
.
new
(
raw
,
options
)
begin
begin
# Every pull request is an issue, but not every issue
# Every pull request is an issue, but not every issue
...
@@ -215,12 +216,12 @@ module Github
...
@@ -215,12 +216,12 @@ module Github
def
fetch_comments
(
noteable
,
type
,
url
)
def
fetch_comments
(
noteable
,
type
,
url
)
loop
do
loop
do
comments
=
Github
::
Client
.
new
.
get
(
url
)
comments
=
Github
::
Client
.
new
(
options
)
.
get
(
url
)
ActiveRecord
::
Base
.
no_touching
do
ActiveRecord
::
Base
.
no_touching
do
comments
.
body
.
each
do
|
raw
|
comments
.
body
.
each
do
|
raw
|
begin
begin
representation
=
Github
::
Representation
::
Comment
.
new
(
raw
)
representation
=
Github
::
Representation
::
Comment
.
new
(
raw
,
options
)
note
=
Note
.
new
note
=
Note
.
new
note
.
project_id
=
project
.
id
note
.
project_id
=
project
.
id
...
...
lib/github/representation/base.rb
View file @
782aab13
module
Github
module
Github
module
Representation
module
Representation
class
Base
class
Base
def
initialize
(
raw
)
def
initialize
(
raw
,
options
=
{}
)
@raw
=
raw
@raw
=
raw
@options
=
options
end
end
def
url
def
url
...
@@ -19,7 +20,7 @@ module Github
...
@@ -19,7 +20,7 @@ module Github
private
private
attr_reader
:raw
attr_reader
:raw
,
:options
end
end
end
end
end
end
lib/github/representation/comment.rb
View file @
782aab13
...
@@ -6,7 +6,7 @@ module Github
...
@@ -6,7 +6,7 @@ module Github
end
end
def
author
def
author
@author
||=
Github
::
Representation
::
User
.
new
(
raw
[
'user'
])
@author
||=
Github
::
Representation
::
User
.
new
(
raw
[
'user'
]
,
options
)
end
end
def
commit_id
def
commit_id
...
...
lib/github/representation/issuable.rb
View file @
782aab13
...
@@ -20,13 +20,13 @@ module Github
...
@@ -20,13 +20,13 @@ module Github
end
end
def
author
def
author
@author
||=
Github
::
Representation
::
User
.
new
(
raw
[
'user'
])
@author
||=
Github
::
Representation
::
User
.
new
(
raw
[
'user'
]
,
options
)
end
end
def
assignee
def
assignee
return
unless
assigned?
return
unless
assigned?
@assignee
||=
Github
::
Representation
::
User
.
new
(
raw
[
'assignee'
])
@assignee
||=
Github
::
Representation
::
User
.
new
(
raw
[
'assignee'
]
,
options
)
end
end
def
assigned?
def
assigned?
...
...
lib/github/representation/pull_request.rb
View file @
782aab13
...
@@ -6,9 +6,10 @@ module Github
...
@@ -6,9 +6,10 @@ module Github
delegate
:user
,
:repo
,
:ref
,
:sha
,
to: :source_branch
,
prefix:
true
delegate
:user
,
:repo
,
:ref
,
:sha
,
to: :source_branch
,
prefix:
true
delegate
:user
,
:exists?
,
:repo
,
:ref
,
:sha
,
:short_sha
,
to: :target_branch
,
prefix:
true
delegate
:user
,
:exists?
,
:repo
,
:ref
,
:sha
,
:short_sha
,
to: :target_branch
,
prefix:
true
def
initialize
(
project
,
raw
)
def
initialize
(
project
,
raw
,
options
)
@project
=
project
@project
=
project
@raw
=
raw
@raw
=
raw
@options
=
options
end
end
def
source_project
def
source_project
...
...
lib/github/representation/user.rb
View file @
782aab13
...
@@ -8,7 +8,7 @@ module Github
...
@@ -8,7 +8,7 @@ module Github
def
email
def
email
return
@email
if
defined?
(
@email
)
return
@email
if
defined?
(
@email
)
@email
=
Github
::
User
.
new
(
username
).
get
.
fetch
(
'email'
,
nil
)
@email
=
Github
::
User
.
new
(
username
,
options
).
get
.
fetch
(
'email'
,
nil
)
end
end
def
username
def
username
...
...
lib/github/user.rb
View file @
782aab13
module
Github
module
Github
class
User
class
User
attr_reader
:username
attr_reader
:username
,
:options
def
initialize
(
username
)
def
initialize
(
username
,
options
)
@username
=
username
@username
=
username
@options
=
options
end
end
def
get
def
get
...
@@ -13,7 +14,7 @@ module Github
...
@@ -13,7 +14,7 @@ module Github
private
private
def
client
def
client
@client
||=
Github
::
Client
.
new
@client
||=
Github
::
Client
.
new
(
options
)
end
end
def
user_url
def
user_url
...
...
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