Commit 1d37742b authored by Baodong Cao's avatar Baodong Cao Committed by Lin Jen-Shin

Refactor Version Check to adapt extension

Cherry pick and squash from:

https://gitlab.com/gitlab-jh/gitlab/-/merge_requests/17
parent 7368e2a6
......@@ -11,16 +11,24 @@ module VersionCheckHelper
def link_to_version
if Gitlab.pre_release?
commit_link = link_to(Gitlab.revision, Gitlab::COM_URL + namespace_project_commits_path('gitlab-org', source_code_project, Gitlab.revision))
commit_link = link_to(Gitlab.revision, source_host_url + namespace_project_commits_path(source_code_group, source_code_project, Gitlab.revision))
[Gitlab::VERSION, content_tag(:small, commit_link)].join(' ').html_safe
else
link_to Gitlab::VERSION, Gitlab::COM_URL + namespace_project_tag_path('gitlab-org', source_code_project, "v#{Gitlab::VERSION}")
link_to Gitlab::VERSION, source_host_url + namespace_project_tag_path(source_code_group, source_code_project, "v#{Gitlab::VERSION}")
end
end
def source_host_url
Gitlab::COM_URL
end
def source_code_group
'gitlab-org'
end
def source_code_project
'gitlab-foss'
end
end
VersionCheckHelper.prepend_mod_with('VersionCheckHelper')
VersionCheckHelper.prepend_mod
......@@ -73,3 +73,5 @@ class SubmitUsagePingService
end
end
end
SubmitUsagePingService.prepend_mod
......@@ -56,8 +56,9 @@ module Gitlab
config.generators.templates.push("#{config.root}/generator_templates")
foss_eager_load_paths = config.eager_load_paths.dup.freeze
load_paths = lambda do |dir:|
ext_paths = config.eager_load_paths.each_with_object([]) do |path, memo|
ext_paths = foss_eager_load_paths.each_with_object([]) do |path, memo|
ext_path = config.root.join(dir, Pathname.new(path).relative_path_from(config.root))
memo << ext_path.to_s
end
......
......@@ -12,7 +12,7 @@ RSpec.describe EE::VersionCheckHelper do
end
it 'links to an ee-commit' do
expect(helper.link_to_version).to include('https://gitlab.com/gitlab-org/gitlab/-/commits/deadbeef')
expect(helper.link_to_version).to include("#{helper.source_host_url}/#{helper.source_code_group}/gitlab/-/commits/deadbeef")
end
end
......@@ -22,7 +22,7 @@ RSpec.describe EE::VersionCheckHelper do
end
it 'links to an ee-tag' do
expect(helper.link_to_version).to include('https://gitlab.com/gitlab-org/gitlab/-/tags/v8.0.2-ee')
expect(helper.link_to_version).to include("#{helper.source_host_url}/#{helper.source_code_group}/gitlab/-/tags/v8.0.2-ee")
end
end
end
......
......@@ -12,10 +12,12 @@ class VersionCheck
def self.url
encoded_data = Base64.urlsafe_encode64(data.to_json)
"#{host}?gitlab_info=#{encoded_data}"
"#{host}/check.svg?gitlab_info=#{encoded_data}"
end
def self.host
'https://version.gitlab.com/check.svg'
'https://version.gitlab.com'
end
end
VersionCheck.prepend_mod
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe VersionCheck do
describe '.url' do
it 'returns the correct URL' do
expect(described_class.url).to match(%r{\A#{Regexp.escape(described_class.host)}/check\.svg\?gitlab_info=\w+})
end
end
end
......@@ -217,7 +217,7 @@ RSpec.describe SubmitUsagePingService do
end
def stub_response(body:, status: 201)
stub_full_request(SubmitUsagePingService::STAGING_URL, method: :post)
stub_full_request(subject.send(:url), method: :post)
.to_return(
headers: { 'Content-Type' => 'application/json' },
body: body.to_json,
......
......@@ -21,6 +21,11 @@ RSpec.describe 'help/index' do
end
context 'when logged in' do
def version_link_regexp(path)
base_url = "#{view.source_host_url}/#{view.source_code_group}"
%r{#{Regexp.escape(base_url)}/(gitlab|gitlab\-foss)/#{Regexp.escape(path)}}
end
before do
stub_user
end
......@@ -31,7 +36,7 @@ RSpec.describe 'help/index' do
render
expect(rendered).to match '8.0.2'
expect(rendered).to have_link('8.0.2', href: %r{https://gitlab.com/gitlab-org/(gitlab|gitlab-foss)/-/tags/v8.0.2})
expect(rendered).to have_link('8.0.2', href: version_link_regexp('-/tags/v8.0.2'))
end
it 'shows a link to the commit for pre-releases' do
......@@ -40,7 +45,7 @@ RSpec.describe 'help/index' do
render
expect(rendered).to match '8.0.2'
expect(rendered).to have_link('abcdefg', href: %r{https://gitlab.com/gitlab-org/(gitlab|gitlab-foss)/-/commits/abcdefg})
expect(rendered).to have_link('abcdefg', href: version_link_regexp('-/commits/abcdefg'))
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