Commit 11423aa2 authored by Nick Thomas's avatar Nick Thomas

Fix submodule links to gist.github.com

parent 067b08dc
......@@ -38,6 +38,8 @@ module SubmoduleHelper
url_helpers.namespace_project_tree_path(namespace, project, submodule_item_id)]
elsif relative_self_url?(url)
relative_self_links(url, submodule_item_id, repository.project)
elsif gist_github_dot_com_url?(url)
gist_github_com_tree_links(namespace, project, submodule_item_id)
elsif github_dot_com_url?(url)
github_com_tree_links(namespace, project, submodule_item_id)
elsif gitlab_dot_com_url?(url)
......@@ -52,6 +54,10 @@ module SubmoduleHelper
protected
def gist_github_dot_com_url?(url)
url =~ %r{gist\.github\.com[/:][^/]+/[^/]+\Z}
end
def github_dot_com_url?(url)
url =~ %r{github\.com[/:][^/]+/[^/]+\Z}
end
......@@ -78,6 +84,11 @@ module SubmoduleHelper
[base, [base, '/-/tree/', commit].join('')]
end
def gist_github_com_tree_links(namespace, project, commit)
base = ['https://gist.github.com/', namespace, '/', project].join('')
[base, [base, commit].join('/')]
end
def github_com_tree_links(namespace, project, commit)
base = ['https://github.com/', namespace, '/', project].join('')
[base, [base, '/tree/', commit].join('')]
......
---
title: Fix submodule links to gist.github.com
merge_request: 27346
author:
type: fixed
......@@ -81,6 +81,33 @@ describe SubmoduleHelper do
end
end
context 'submodule on gist.github.com' do
it 'detects ssh' do
stub_url('git@gist.github.com:gitlab-org/gitlab-foss.git')
is_expected.to eq(['https://gist.github.com/gitlab-org/gitlab-foss', 'https://gist.github.com/gitlab-org/gitlab-foss/hash'])
end
it 'detects http' do
stub_url('http://gist.github.com/gitlab-org/gitlab-foss.git')
is_expected.to eq(['https://gist.github.com/gitlab-org/gitlab-foss', 'https://gist.github.com/gitlab-org/gitlab-foss/hash'])
end
it 'detects https' do
stub_url('https://gist.github.com/gitlab-org/gitlab-foss.git')
is_expected.to eq(['https://gist.github.com/gitlab-org/gitlab-foss', 'https://gist.github.com/gitlab-org/gitlab-foss/hash'])
end
it 'handles urls with no .git on the end' do
stub_url('http://gist.github.com/gitlab-org/gitlab-foss')
is_expected.to eq(['https://gist.github.com/gitlab-org/gitlab-foss', 'https://gist.github.com/gitlab-org/gitlab-foss/hash'])
end
it 'returns original with non-standard url' do
stub_url('http://gist.github.com/another/gitlab-org/gitlab-foss.git')
is_expected.to eq([repo.submodule_url_for, nil])
end
end
context 'submodule on github.com' do
it 'detects ssh' do
stub_url('git@github.com:gitlab-org/gitlab-foss.git')
......
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