summaryrefslogtreecommitdiff
path: root/lib/github
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2017-04-19 20:04:58 -0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2017-04-24 16:17:52 -0300
commit782aab1319bdcfbe1634d4b33444e8ce5b57d394 (patch)
tree1995c7eae0095c423e0f2795ebb2389bc7992f0d /lib/github
parentac1634fac9ef2891ef98d499fe6391d315b98b30 (diff)
downloadgitlab-ce-782aab1319bdcfbe1634d4b33444e8ce5b57d394.tar.gz
Pass a options hash to Github::Client
Diffstat (limited to 'lib/github')
-rw-r--r--lib/github/client.rb6
-rw-r--r--lib/github/collection.rb8
-rw-r--r--lib/github/import.rb23
-rw-r--r--lib/github/representation/base.rb7
-rw-r--r--lib/github/representation/comment.rb2
-rw-r--r--lib/github/representation/issuable.rb4
-rw-r--r--lib/github/representation/pull_request.rb5
-rw-r--r--lib/github/representation/user.rb2
-rw-r--r--lib/github/user.rb7
9 files changed, 37 insertions, 27 deletions
diff --git a/lib/github/client.rb b/lib/github/client.rb
index 1450a8d3cc0..95536cae57f 100644
--- a/lib/github/client.rb
+++ b/lib/github/client.rb
@@ -2,9 +2,9 @@ module Github
class Client
attr_reader :connection
- def initialize(token)
- @connection = Faraday.new(url: 'https://api.github.com') do |faraday|
- faraday.authorization 'token', token
+ def initialize(options)
+ @connection = Faraday.new(url: options.fetch(:url)) do |faraday|
+ faraday.authorization 'token', options.fetch(:token)
faraday.adapter :net_http
end
end
diff --git a/lib/github/collection.rb b/lib/github/collection.rb
index 1b0c00928c5..12d6703476b 100644
--- a/lib/github/collection.rb
+++ b/lib/github/collection.rb
@@ -1,5 +1,11 @@
module Github
class Collection
+ attr_reader :options
+
+ def initialize(options)
+ @options = options
+ end
+
def fetch(url, query = {})
return [] if url.blank?
@@ -16,7 +22,7 @@ module Github
private
def client
- @client ||= Github::Client.new
+ @client ||= Github::Client.new(options)
end
end
end
diff --git a/lib/github/import.rb b/lib/github/import.rb
index 333bfa0fe05..17244d8aea1 100644
--- a/lib/github/import.rb
+++ b/lib/github/import.rb
@@ -27,17 +27,18 @@ module Github
self.reset_callbacks :validate
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
@repository = project.repository
+ @options = options
@cached_label_ids = {}
@cached_user_ids = {}
@errors = []
end
- def execute(owner, repo, token)
+ def execute(owner, repo)
# Fetch repository
begin
project.create_repository
@@ -53,7 +54,7 @@ module Github
url = "/repos/#{owner}/#{repo}/labels"
loop do
- response = Github::Client.new.get(url)
+ response = Github::Client.new(options).get(url)
response.body.each do |raw|
begin
@@ -81,7 +82,7 @@ module Github
url = "/repos/#{owner}/#{repo}/milestones"
loop do
- response = Github::Client.new.get(url, state: :all)
+ response = Github::Client.new(options).get(url, state: :all)
response.body.each do |raw|
begin
@@ -109,10 +110,10 @@ module Github
url = "/repos/#{owner}/#{repo}/pulls"
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|
- 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)
next unless merge_request.new_record? && pull_request.valid?
@@ -160,10 +161,10 @@ module Github
url = "/repos/#{owner}/#{repo}/issues"
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|
- representation = Github::Representation::Issue.new(raw)
+ representation = Github::Representation::Issue.new(raw, options)
begin
# Every pull request is an issue, but not every issue
@@ -215,12 +216,12 @@ module Github
def fetch_comments(noteable, type, url)
loop do
- comments = Github::Client.new.get(url)
+ comments = Github::Client.new(options).get(url)
ActiveRecord::Base.no_touching do
comments.body.each do |raw|
begin
- representation = Github::Representation::Comment.new(raw)
+ representation = Github::Representation::Comment.new(raw, options)
note = Note.new
note.project_id = project.id
diff --git a/lib/github/representation/base.rb b/lib/github/representation/base.rb
index 5ea294ed49c..385e62ae99d 100644
--- a/lib/github/representation/base.rb
+++ b/lib/github/representation/base.rb
@@ -1,8 +1,9 @@
module Github
module Representation
class Base
- def initialize(raw)
- @raw = raw
+ def initialize(raw, options = {})
+ @raw = raw
+ @options = options
end
def url
@@ -19,7 +20,7 @@ module Github
private
- attr_reader :raw
+ attr_reader :raw, :options
end
end
end
diff --git a/lib/github/representation/comment.rb b/lib/github/representation/comment.rb
index 02bcd9eaa0e..22cb98b0eff 100644
--- a/lib/github/representation/comment.rb
+++ b/lib/github/representation/comment.rb
@@ -6,7 +6,7 @@ module Github
end
def author
- @author ||= Github::Representation::User.new(raw['user'])
+ @author ||= Github::Representation::User.new(raw['user'], options)
end
def commit_id
diff --git a/lib/github/representation/issuable.rb b/lib/github/representation/issuable.rb
index a55976f9019..9713b82615d 100644
--- a/lib/github/representation/issuable.rb
+++ b/lib/github/representation/issuable.rb
@@ -20,13 +20,13 @@ module Github
end
def author
- @author ||= Github::Representation::User.new(raw['user'])
+ @author ||= Github::Representation::User.new(raw['user'], options)
end
def assignee
return unless assigned?
- @assignee ||= Github::Representation::User.new(raw['assignee'])
+ @assignee ||= Github::Representation::User.new(raw['assignee'], options)
end
def assigned?
diff --git a/lib/github/representation/pull_request.rb b/lib/github/representation/pull_request.rb
index 0596b0425a2..4119ca400c6 100644
--- a/lib/github/representation/pull_request.rb
+++ b/lib/github/representation/pull_request.rb
@@ -6,9 +6,10 @@ module Github
delegate :user, :repo, :ref, :sha, to: :source_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
- @raw = raw
+ @raw = raw
+ @options = options
end
def source_project
diff --git a/lib/github/representation/user.rb b/lib/github/representation/user.rb
index 70a0ce000ae..79758555319 100644
--- a/lib/github/representation/user.rb
+++ b/lib/github/representation/user.rb
@@ -8,7 +8,7 @@ module Github
def 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
def username
diff --git a/lib/github/user.rb b/lib/github/user.rb
index 19fe6230820..f88a29e590b 100644
--- a/lib/github/user.rb
+++ b/lib/github/user.rb
@@ -1,9 +1,10 @@
module Github
class User
- attr_reader :username
+ attr_reader :username, :options
- def initialize(username)
+ def initialize(username, options)
@username = username
+ @options = options
end
def get
@@ -13,7 +14,7 @@ module Github
private
def client
- @client ||= Github::Client.new
+ @client ||= Github::Client.new(options)
end
def user_url