Commit 4adda745 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Merge branch 'common/feat/integrate_cn_version' into 'master'

Refactor Version Check to adapt extension

See merge request gitlab-org/gitlab!61658
parents 613c322e 1d37742b
...@@ -11,16 +11,24 @@ module VersionCheckHelper ...@@ -11,16 +11,24 @@ module VersionCheckHelper
def link_to_version def link_to_version
if Gitlab.pre_release? 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 [Gitlab::VERSION, content_tag(:small, commit_link)].join(' ').html_safe
else 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
end end
def source_host_url
Gitlab::COM_URL
end
def source_code_group
'gitlab-org'
end
def source_code_project def source_code_project
'gitlab-foss' 'gitlab-foss'
end end
end end
VersionCheckHelper.prepend_mod_with('VersionCheckHelper') VersionCheckHelper.prepend_mod
...@@ -73,3 +73,5 @@ class SubmitUsagePingService ...@@ -73,3 +73,5 @@ class SubmitUsagePingService
end end
end end
end end
SubmitUsagePingService.prepend_mod
...@@ -56,8 +56,9 @@ module Gitlab ...@@ -56,8 +56,9 @@ module Gitlab
config.generators.templates.push("#{config.root}/generator_templates") config.generators.templates.push("#{config.root}/generator_templates")
foss_eager_load_paths = config.eager_load_paths.dup.freeze
load_paths = lambda do |dir:| 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)) ext_path = config.root.join(dir, Pathname.new(path).relative_path_from(config.root))
memo << ext_path.to_s memo << ext_path.to_s
end end
......
...@@ -12,7 +12,7 @@ RSpec.describe EE::VersionCheckHelper do ...@@ -12,7 +12,7 @@ RSpec.describe EE::VersionCheckHelper do
end end
it 'links to an ee-commit' do 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
end end
...@@ -22,7 +22,7 @@ RSpec.describe EE::VersionCheckHelper do ...@@ -22,7 +22,7 @@ RSpec.describe EE::VersionCheckHelper do
end end
it 'links to an ee-tag' do 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 end
end end
......
...@@ -12,10 +12,12 @@ class VersionCheck ...@@ -12,10 +12,12 @@ class VersionCheck
def self.url def self.url
encoded_data = Base64.urlsafe_encode64(data.to_json) encoded_data = Base64.urlsafe_encode64(data.to_json)
"#{host}?gitlab_info=#{encoded_data}" "#{host}/check.svg?gitlab_info=#{encoded_data}"
end end
def self.host def self.host
'https://version.gitlab.com/check.svg' 'https://version.gitlab.com'
end end
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 ...@@ -217,7 +217,7 @@ RSpec.describe SubmitUsagePingService do
end end
def stub_response(body:, status: 201) def stub_response(body:, status: 201)
stub_full_request(SubmitUsagePingService::STAGING_URL, method: :post) stub_full_request(subject.send(:url), method: :post)
.to_return( .to_return(
headers: { 'Content-Type' => 'application/json' }, headers: { 'Content-Type' => 'application/json' },
body: body.to_json, body: body.to_json,
......
...@@ -21,6 +21,11 @@ RSpec.describe 'help/index' do ...@@ -21,6 +21,11 @@ RSpec.describe 'help/index' do
end end
context 'when logged in' do 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 before do
stub_user stub_user
end end
...@@ -31,7 +36,7 @@ RSpec.describe 'help/index' do ...@@ -31,7 +36,7 @@ RSpec.describe 'help/index' do
render render
expect(rendered).to match '8.0.2' 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 end
it 'shows a link to the commit for pre-releases' do it 'shows a link to the commit for pre-releases' do
...@@ -40,7 +45,7 @@ RSpec.describe 'help/index' do ...@@ -40,7 +45,7 @@ RSpec.describe 'help/index' do
render render
expect(rendered).to match '8.0.2' 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 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