Commit 8563dc1c authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '26111-fix-github-gist-links' into 'master'

Fix submodule links to gist.github.com

Closes #26111

See merge request gitlab-org/gitlab!27346
parents 09e0f794 11423aa2
...@@ -38,6 +38,8 @@ module SubmoduleHelper ...@@ -38,6 +38,8 @@ module SubmoduleHelper
url_helpers.namespace_project_tree_path(namespace, project, submodule_item_id)] url_helpers.namespace_project_tree_path(namespace, project, submodule_item_id)]
elsif relative_self_url?(url) elsif relative_self_url?(url)
relative_self_links(url, submodule_item_id, repository.project) 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) elsif github_dot_com_url?(url)
github_com_tree_links(namespace, project, submodule_item_id) github_com_tree_links(namespace, project, submodule_item_id)
elsif gitlab_dot_com_url?(url) elsif gitlab_dot_com_url?(url)
...@@ -52,6 +54,10 @@ module SubmoduleHelper ...@@ -52,6 +54,10 @@ module SubmoduleHelper
protected protected
def gist_github_dot_com_url?(url)
url =~ %r{gist\.github\.com[/:][^/]+/[^/]+\Z}
end
def github_dot_com_url?(url) def github_dot_com_url?(url)
url =~ %r{github\.com[/:][^/]+/[^/]+\Z} url =~ %r{github\.com[/:][^/]+/[^/]+\Z}
end end
...@@ -78,6 +84,11 @@ module SubmoduleHelper ...@@ -78,6 +84,11 @@ module SubmoduleHelper
[base, [base, '/-/tree/', commit].join('')] [base, [base, '/-/tree/', commit].join('')]
end 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) def github_com_tree_links(namespace, project, commit)
base = ['https://github.com/', namespace, '/', project].join('') base = ['https://github.com/', namespace, '/', project].join('')
[base, [base, '/tree/', commit].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 ...@@ -81,6 +81,33 @@ describe SubmoduleHelper do
end end
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 context 'submodule on github.com' do
it 'detects ssh' do it 'detects ssh' do
stub_url('git@github.com:gitlab-org/gitlab-foss.git') 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