Commit 6094bc77 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'sh-fix-issue-2555' into 'master'

Add primary node clone URL to Geo secondary 'How to work faster with Geo' popover

Closes #2555

See merge request !2027
parents 2b1e6a44 c5d0a7b9
module EE module EE
module GitlabRoutingHelper module GitlabRoutingHelper
include ProjectsHelper
include ApplicationSettingsHelper
def geo_primary_web_url(project) def geo_primary_web_url(project)
File.join(::Gitlab::Geo.primary_node.url, ::Gitlab::Routing.url_helpers.namespace_project_path(project.namespace, project)) File.join(::Gitlab::Geo.primary_node.url, ::Gitlab::Routing.url_helpers.namespace_project_path(project.namespace, project))
end end
def geo_primary_ssh_url_to_repo(project)
"#{::Gitlab::Geo.primary_node.clone_url_prefix}#{project.path_with_namespace}"
end
def geo_primary_http_url_to_repo(project) def geo_primary_http_url_to_repo(project)
"#{geo_primary_web_url(project)}.git" "#{geo_primary_web_url(project)}.git"
end end
def geo_primary_default_url_to_repo(project) def geo_primary_default_url_to_repo(project)
case default_clone_protocol case default_clone_protocol
when 'http' when 'ssh'
geo_primary_ssh_url_to_repo(project)
else
geo_primary_http_url_to_repo(project) geo_primary_http_url_to_repo(project)
end end
end end
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
remote: remote:
= clipboard_button(target: 'pre#geo-info-2') = clipboard_button(target: 'pre#geo-info-2')
%pre#geo-info-2.dark %pre#geo-info-2.dark
git remote set-url --push origin <clone url for primary repository> git remote set-url --push origin #{geo_primary_default_url_to_repo(project)}
%p %p
%strong= 'Done.' %strong= 'Done.'
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
'git clone ' + 'git clone ' +
(data.cloneUrlSecondary || '<clone url for secondary repository>') (data.cloneUrlSecondary || '<clone url for secondary repository>')
); );
$('geo-info-2').text( $('#geo-info-2').text(
'git remote set-url --push origin ' + 'git remote set-url --push origin ' +
(data.cloneUrlPrimary || '<clone url for primary repository>') (data.cloneUrlPrimary || '<clone url for primary repository>')
); );
......
---
title: Add primary node clone URL to Geo secondary 'How to work faster with Geo' popover
merge_request:
author:
require 'rails_helper'
feature 'Geo clone instructions', feature: true, js: true do
include Devise::Test::IntegrationHelpers
let(:project) { create(:empty_project, :empty_repo) }
let(:developer) { create(:user) }
background do
primary = create(:geo_node, :primary, schema: 'https', host: 'primary.domain.com', port: 443)
primary.update_attribute(:clone_url_prefix, 'git@primary.domain.com:')
create(:geo_node, :current)
allow(Gitlab::Geo).to receive(:secondary?).and_return(true)
project.team << [developer, :developer]
sign_in(developer)
end
context 'with an SSH key' do
background do
create(:personal_key, user: developer)
end
scenario 'defaults to SSH' do
visit_project
show_geo_clone_instructions
expect_instructions_for('ssh')
end
scenario 'switches to HTTP' do
visit_project
select_protocol('HTTP')
show_geo_clone_instructions
expect_instructions_for('http')
end
end
def visit_project
visit namespace_project_path(project.namespace, project)
end
def select_protocol(protocol)
find('#clone-dropdown').click
find(".#{protocol.downcase}-selector").click
end
def show_geo_clone_instructions
find('.btn-geo').click
end
def expect_instructions_for(protocol)
primary_remote = primary_url(protocol)
secondary_remote = secondary_url(protocol)
expect(page).to have_content('How to work faster with Geo')
expect(page).to have_content("git clone #{secondary_remote}")
expect(page).to have_content("git remote set-url --push origin #{primary_remote}")
end
def primary_url(protocol)
case protocol
when 'ssh'
'git@primary.domain.com:'
when 'http'
'https://primary.domain.com'
end
end
def secondary_url(protocol)
case protocol
when 'ssh'
project.ssh_url_to_repo
when 'http'
project.http_url_to_repo(developer)
end
end
end
require 'spec_helper'
describe EE::GitlabRoutingHelper do
include ProjectsHelper
include ApplicationSettingsHelper
let!(:primary_node) { create(:geo_node, :primary) }
let(:project) { build_stubbed(:empty_project) }
describe '#geo_primary_default_url_to_repo' do
it 'returns an HTTP URL' do
allow(helper).to receive(:default_clone_protocol).and_return('http')
result = helper.geo_primary_default_url_to_repo(project)
expect(result).to start_with('http://')
expect(result).to eq(helper.geo_primary_http_url_to_repo(project))
end
it 'returns an HTTPS URL' do
primary_node.update_attribute(:schema, 'https')
allow(helper).to receive(:default_clone_protocol).and_return('https')
result = helper.geo_primary_default_url_to_repo(project)
expect(result).to start_with('https://')
expect(result).to eq(helper.geo_primary_http_url_to_repo(project))
end
it 'returns an SSH URL' do
allow(helper).to receive(:default_clone_protocol).and_return('ssh')
result = helper.geo_primary_default_url_to_repo(project)
expect(result).to start_with('git@')
expect(result).to eq(helper.geo_primary_ssh_url_to_repo(project))
end
end
end
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