Files
gitlabhq/lib/gitlab/github_import/client.rb
T
Dmitriy Zaporozhets d3361e6d1b Merge branch 'master' of dev.gitlab.org:gitlab/gitlabhq into ce-to-ee
Conflicts:
	Gemfile.lock
	app/controllers/admin/application_settings_controller.rb
	app/controllers/groups/application_controller.rb
	app/controllers/groups/group_members_controller.rb
	app/controllers/projects/team_members_controller.rb
	app/helpers/application_settings_helper.rb
	app/helpers/projects_helper.rb
	app/helpers/tab_helper.rb
	app/models/application_setting.rb
	app/models/user.rb
	app/views/devise/shared/_signin_box.html.haml
	app/views/groups/projects.html.haml
	app/views/profiles/keys/_key.html.haml
	app/views/projects/team_members/_form.html.haml
	app/views/projects/team_members/index.html.haml
	config/routes.rb
	db/schema.rb
	spec/lib/gitlab/ldap/access_spec.rb
2015-03-16 21:25:00 -07:00

54 lines
1.2 KiB
Ruby

module Gitlab
module GithubImport
class Client
attr_reader :client, :api
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, api_endpoint: github_options[:site])
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
Gitlab.config.omniauth.providers.find{|provider| provider.name == "github"}
end
def github_options
OmniAuth::Strategies::GitHub.default_options[:client_options].dup
end
end
end
end