2015-04-26 12:48:37 +05:30
|
|
|
module Gitlab
|
|
|
|
module GithubImport
|
|
|
|
class Client
|
|
|
|
attr_reader :client, :api
|
|
|
|
|
|
|
|
def initialize(access_token)
|
|
|
|
@client = ::OAuth2::Client.new(
|
|
|
|
config.app_id,
|
|
|
|
config.app_secret,
|
2016-06-02 11:05:42 +05:30
|
|
|
github_options.merge(ssl: { verify: config['verify_ssl'] })
|
2015-04-26 12:48:37 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
if access_token
|
|
|
|
::Octokit.auto_paginate = true
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
@api = ::Octokit::Client.new(
|
|
|
|
access_token: access_token,
|
|
|
|
api_endpoint: github_options[:site],
|
|
|
|
connection_options: {
|
|
|
|
ssl: { verify: config['verify_ssl'] }
|
|
|
|
}
|
|
|
|
)
|
2015-04-26 12:48:37 +05:30
|
|
|
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
|
|
|
|
|
|
|
|
def config
|
2016-06-02 11:05:42 +05:30
|
|
|
Gitlab.config.omniauth.providers.find { |provider| provider.name == "github" }
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def github_options
|
2016-06-02 11:05:42 +05:30
|
|
|
config["args"]["client_options"].deep_symbolize_keys
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|