Commit a56496f1 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'ghe_importer' into 'master'

GHE importer

See merge request !306
parents 1bf48360 88bf3c0f
...@@ -258,8 +258,12 @@ production: &base ...@@ -258,8 +258,12 @@ production: &base
# args: { access_type: 'offline', approval_prompt: '' } } # args: { access_type: 'offline', approval_prompt: '' } }
# - { name: 'twitter', app_id: 'YOUR APP ID', # - { name: 'twitter', app_id: 'YOUR APP ID',
# app_secret: 'YOUR APP SECRET'} # app_secret: 'YOUR APP SECRET'}
# - { name: 'gitlab', app_id: 'YOUR APP ID',
# app_secret: 'YOUR APP SECRET',
# args: { scope: 'api' } }
# - { name: 'github', app_id: 'YOUR APP ID', # - { name: 'github', app_id: 'YOUR APP ID',
# app_secret: 'YOUR APP SECRET', # app_secret: 'YOUR APP SECRET',
# url: "https://github.com/",
# args: { scope: 'user:email' } } # args: { scope: 'user:email' } }
......
...@@ -91,6 +91,26 @@ Settings['omniauth'] ||= Settingslogic.new({}) ...@@ -91,6 +91,26 @@ Settings['omniauth'] ||= Settingslogic.new({})
Settings.omniauth['enabled'] = false if Settings.omniauth['enabled'].nil? Settings.omniauth['enabled'] = false if Settings.omniauth['enabled'].nil?
Settings.omniauth['providers'] ||= [] Settings.omniauth['providers'] ||= []
# Fill out omniauth-gitlab settings. It is needed for easy set up GHE or GH by just specifying url.
github_settings = Settings.omniauth['providers'].find{|provider| provider["name"] == "github"}
if github_settings
if github_settings["url"].include?("https://github.com")
github_settings["args"]["client_options"] = {
"site" => 'https://api.github.com/',
"authorize_url" => 'https://github.com/login/oauth/authorize',
"token_url" => 'https://github.com/login/oauth/access_token'
}
else
github_settings["args"]["client_options"] = {
"site" => File.join(github_settings["url"], "api/v3"),
"authorize_url" => File.join(github_settings["url"], "login/oauth/authorize"),
"token_url" => File.join(github_settings["url"], "login/oauth/access_token")
}
end
end
Settings['issues_tracker'] ||= {} Settings['issues_tracker'] ||= {}
# #
......
...@@ -34,9 +34,22 @@ To enable the GitHub OmniAuth provider you must register your application with G ...@@ -34,9 +34,22 @@ To enable the GitHub OmniAuth provider you must register your application with G
``` ```
- { name: 'github', app_id: 'YOUR APP ID', - { name: 'github', app_id: 'YOUR APP ID',
app_secret: 'YOUR APP SECRET', app_secret: 'YOUR APP SECRET',
url: "https://github.com/",
args: { scope: 'user:email' } } args: { scope: 'user:email' } }
``` ```
1. If you want to use GitHub Enterprise then your configuration should look like the following:
```
- { name: 'github', app_id: 'YOUR APP ID',
app_secret: 'YOUR APP SECRET',
url: "https://github.example.com/",
args: { scope: 'user:email' } }
```
1. Change 'YOUR APP ID' to the client ID from the GitHub application page from step 7. 1. Change 'YOUR APP ID' to the client ID from the GitHub application page from step 7.
1. Change 'YOUR APP SECRET' to the client secret from the GitHub application page from step 7. 1. Change 'YOUR APP SECRET' to the client secret from the GitHub application page from step 7.
......
...@@ -12,7 +12,7 @@ module Gitlab ...@@ -12,7 +12,7 @@ module Gitlab
if access_token if access_token
::Octokit.auto_paginate = true ::Octokit.auto_paginate = true
@api = ::Octokit::Client.new(access_token: access_token) @api = ::Octokit::Client.new(access_token: access_token, api_endpoint: github_options[:site])
end end
end end
...@@ -46,11 +46,7 @@ module Gitlab ...@@ -46,11 +46,7 @@ module Gitlab
end end
def github_options def github_options
{ config["args"]["client_options"].deep_symbolize_keys
site: 'https://api.github.com',
authorize_url: 'https://github.com/login/oauth/authorize',
token_url: 'https://github.com/login/oauth/access_token'
}
end end
end end
end end
......
...@@ -11,6 +11,7 @@ describe Import::GithubController do ...@@ -11,6 +11,7 @@ describe Import::GithubController do
it "updates access token" do it "updates access token" do
token = "asdasd12345" token = "asdasd12345"
Gitlab::GithubImport::Client.any_instance.stub(:get_token).and_return(token) Gitlab::GithubImport::Client.any_instance.stub(:get_token).and_return(token)
Gitlab::GithubImport::Client.any_instance.stub(:github_options).and_return({})
Gitlab.config.omniauth.providers << OpenStruct.new(app_id: "asd123", app_secret: "asd123", name: "github") Gitlab.config.omniauth.providers << OpenStruct.new(app_id: "asd123", app_secret: "asd123", name: "github")
get :callback get :callback
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment