Merge branch 'rd-fix-github-url-when-listing-repositories-at-importing' into 'master'
Fix provider server URL used when listing repos to import See merge request gitlab-org/gitlab-ce!17692
This commit is contained in:
commit
51f9153764
|
@ -1,4 +1,6 @@
|
||||||
module ImportHelper
|
module ImportHelper
|
||||||
|
include ::Gitlab::Utils::StrongMemoize
|
||||||
|
|
||||||
def has_ci_cd_only_params?
|
def has_ci_cd_only_params?
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
@ -75,17 +77,18 @@ module ImportHelper
|
||||||
private
|
private
|
||||||
|
|
||||||
def github_project_url(full_path)
|
def github_project_url(full_path)
|
||||||
"#{github_root_url}/#{full_path}"
|
URI.join(github_root_url, full_path).to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
def github_root_url
|
def github_root_url
|
||||||
return @github_url if defined?(@github_url)
|
strong_memoize(:github_url) do
|
||||||
|
provider = Gitlab::Auth::OAuth::Provider.config_for('github')
|
||||||
|
|
||||||
provider = Gitlab.config.omniauth.providers.find { |p| p.name == 'github' }
|
provider&.dig('url').presence || 'https://github.com'
|
||||||
@github_url = provider.fetch('url', 'https://github.com') if provider
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def gitea_project_url(full_path)
|
def gitea_project_url(full_path)
|
||||||
"#{@gitea_host_url.sub(%r{/+\z}, '')}/#{full_path}"
|
URI.join(@gitea_host_url, full_path).to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: Fix generated URL when listing repoitories for import
|
||||||
|
merge_request: 17692
|
||||||
|
author:
|
||||||
|
type: fixed
|
|
@ -4,7 +4,7 @@ module Gitlab
|
||||||
class Config
|
class Config
|
||||||
class << self
|
class << self
|
||||||
def options
|
def options
|
||||||
Gitlab.config.omniauth.providers.find { |provider| provider.name == 'saml' }
|
Gitlab::Auth::OAuth::Provider.config_for('saml')
|
||||||
end
|
end
|
||||||
|
|
||||||
def groups
|
def groups
|
||||||
|
|
|
@ -197,10 +197,7 @@ module Gitlab
|
||||||
end
|
end
|
||||||
|
|
||||||
def github_omniauth_provider
|
def github_omniauth_provider
|
||||||
@github_omniauth_provider ||=
|
@github_omniauth_provider ||= Gitlab::Auth::OAuth::Provider.config_for('github').to_h
|
||||||
Gitlab.config.omniauth.providers
|
|
||||||
.find { |provider| provider.name == 'github' }
|
|
||||||
.to_h
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def rate_limit_counter
|
def rate_limit_counter
|
||||||
|
|
|
@ -72,7 +72,7 @@ module Gitlab
|
||||||
end
|
end
|
||||||
|
|
||||||
def config
|
def config
|
||||||
Gitlab.config.omniauth.providers.find {|provider| provider.name == "gitlab"}
|
Gitlab::Auth::OAuth::Provider.config_for('gitlab')
|
||||||
end
|
end
|
||||||
|
|
||||||
def gitlab_options
|
def gitlab_options
|
||||||
|
|
|
@ -83,7 +83,7 @@ module Gitlab
|
||||||
end
|
end
|
||||||
|
|
||||||
def config
|
def config
|
||||||
Gitlab.config.omniauth.providers.find { |provider| provider.name == "github" }
|
Gitlab::Auth::OAuth::Provider.config_for('github')
|
||||||
end
|
end
|
||||||
|
|
||||||
def github_options
|
def github_options
|
||||||
|
|
|
@ -32,7 +32,7 @@ module GoogleApi
|
||||||
private
|
private
|
||||||
|
|
||||||
def config
|
def config
|
||||||
Gitlab.config.omniauth.providers.find { |provider| provider.name == "google_oauth2" }
|
Gitlab::Auth::OAuth::Provider.config_for('google_oauth2')
|
||||||
end
|
end
|
||||||
|
|
||||||
def client
|
def client
|
||||||
|
|
|
@ -27,25 +27,48 @@ describe ImportHelper do
|
||||||
|
|
||||||
describe '#provider_project_link' do
|
describe '#provider_project_link' do
|
||||||
context 'when provider is "github"' do
|
context 'when provider is "github"' do
|
||||||
|
let(:github_server_url) { nil }
|
||||||
|
|
||||||
|
before do
|
||||||
|
setting = Settingslogic.new('name' => 'github')
|
||||||
|
setting['url'] = github_server_url if github_server_url
|
||||||
|
|
||||||
|
allow(Gitlab.config.omniauth).to receive(:providers).and_return([setting])
|
||||||
|
end
|
||||||
|
|
||||||
context 'when provider does not specify a custom URL' do
|
context 'when provider does not specify a custom URL' do
|
||||||
it 'uses default GitHub URL' do
|
it 'uses default GitHub URL' do
|
||||||
allow(Gitlab.config.omniauth).to receive(:providers)
|
|
||||||
.and_return([Settingslogic.new('name' => 'github')])
|
|
||||||
|
|
||||||
expect(helper.provider_project_link('github', 'octocat/Hello-World'))
|
expect(helper.provider_project_link('github', 'octocat/Hello-World'))
|
||||||
.to include('href="https://github.com/octocat/Hello-World"')
|
.to include('href="https://github.com/octocat/Hello-World"')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when provider specify a custom URL' do
|
context 'when provider specify a custom URL' do
|
||||||
it 'uses custom URL' do
|
let(:github_server_url) { 'https://github.company.com' }
|
||||||
allow(Gitlab.config.omniauth).to receive(:providers)
|
|
||||||
.and_return([Settingslogic.new('name' => 'github', 'url' => 'https://github.company.com')])
|
|
||||||
|
|
||||||
|
it 'uses custom URL' do
|
||||||
expect(helper.provider_project_link('github', 'octocat/Hello-World'))
|
expect(helper.provider_project_link('github', 'octocat/Hello-World'))
|
||||||
.to include('href="https://github.company.com/octocat/Hello-World"')
|
.to include('href="https://github.company.com/octocat/Hello-World"')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when custom URL contains a '/' char at the end" do
|
||||||
|
let(:github_server_url) { 'https://github.company.com/' }
|
||||||
|
|
||||||
|
it "doesn't render double slash" do
|
||||||
|
expect(helper.provider_project_link('github', 'octocat/Hello-World'))
|
||||||
|
.to include('href="https://github.company.com/octocat/Hello-World"')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when provider is missing' do
|
||||||
|
it 'uses the default URL' do
|
||||||
|
allow(Gitlab.config.omniauth).to receive(:providers).and_return([])
|
||||||
|
|
||||||
|
expect(helper.provider_project_link('github', 'octocat/Hello-World'))
|
||||||
|
.to include('href="https://github.com/octocat/Hello-World"')
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when provider is "gitea"' do
|
context 'when provider is "gitea"' do
|
||||||
|
|
Loading…
Reference in New Issue