Commit 53ba2f11 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Show the commit-sha for pre-release versions

The pre-release tags are set at the beginning of a release, so it
would be impossible to figure out which version was running if we're
running nightlies.

In that case it's better to still link to the SHA. These versions
don't get deployed to .com.
parent 7bbe8949
# frozen_string_literal: true # frozen_string_literal: true
module VersionCheckHelper module VersionCheckHelper
prepend EE::VersionCheckHelper
def version_status_badge def version_status_badge
return unless Rails.env.production? return unless Rails.env.production?
return unless Gitlab::CurrentSettings.version_check_enabled return unless Gitlab::CurrentSettings.version_check_enabled
...@@ -9,4 +11,17 @@ module VersionCheckHelper ...@@ -9,4 +11,17 @@ module VersionCheckHelper
image_url = VersionCheck.new.url image_url = VersionCheck.new.url
image_tag image_url, class: 'js-version-status-badge' image_tag image_url, class: 'js-version-status-badge'
end end
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))
[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}")
end
end
def source_code_project
'gitlab-ce'
end
end end
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
GitLab GitLab
Enterprise Edition Enterprise Edition
- if user_signed_in? - if user_signed_in?
%span= link_to Gitlab::VERSION, Gitlab::COM_URL + namespace_project_tag_path('gitlab-org', 'gitlab-ee', "v#{Gitlab::VERSION}") %span= link_to_version
= version_status_badge = version_status_badge
%hr %hr
......
# frozen_string_literal: true
module EE
module VersionCheckHelper
def source_code_project
'gitlab-ee'
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe EE::VersionCheckHelper do
include StubVersion
describe '#link_to_version' do
context 'for a pre-release' do
before do
stub_version('8.0.2-pre', 'deadbeef')
end
it 'links to an ee-commit' do
expect(helper.link_to_version).to include('https://gitlab.com/gitlab-org/gitlab-ee/commits/deadbeef')
end
end
context 'for a normal release' do
before do
stub_version('8.0.2-ee', 'deadbeef')
end
it 'links to an ee-tag' do
expect(helper.link_to_version).to include('https://gitlab.com/gitlab-org/gitlab-ee/tags/v8.0.2-ee')
end
end
end
end
...@@ -47,4 +47,8 @@ module Gitlab ...@@ -47,4 +47,8 @@ module Gitlab
def self.dev_env_or_com? def self.dev_env_or_com?
Rails.env.development? || org? || com? Rails.env.development? || org? || com?
end end
def self.pre_release?
VERSION.include?('pre')
end
end end
# frozen_string_literal: true
module StubVersion
def stub_version(version, revision)
stub_const('Gitlab::VERSION', version)
allow(Gitlab).to receive(:revision).and_return(revision)
end
end
# frozen_string_literal: true
require 'rails_helper' require 'rails_helper'
describe 'help/index' do describe 'help/index' do
include StubVersion
describe 'version information' do describe 'version information' do
before do
stub_helpers
end
it 'is hidden from guests' do it 'is hidden from guests' do
stub_user(nil) stub_user(nil)
stub_version('8.0.2', 'abcdefg') stub_version('8.0.2', 'abcdefg')
stub_helpers
render render
...@@ -13,15 +20,28 @@ describe 'help/index' do ...@@ -13,15 +20,28 @@ describe 'help/index' do
expect(rendered).not_to match 'abcdefg' expect(rendered).not_to match 'abcdefg'
end end
it 'is shown to users' do context 'when logged in' do
stub_user before do
stub_version('8.0.2', 'abcdefg') stub_user
stub_helpers end
render it 'shows a link to the tag to users' do
stub_version('8.0.2', 'abcdefg')
render
expect(rendered).to match '8.0.2'
expect(rendered).to have_link('8.0.2', href: %r{https://gitlab.com/gitlab-org/gitlab-(ce|ee)/tags/v8.0.2})
end
it 'shows a link to the commit for pre-releases' do
stub_version('8.0.2-pre', 'abcdefg')
expect(rendered).to match '8.0.2' render
expect(rendered).to have_link('8.0.2', href: 'https://gitlab.com/gitlab-org/gitlab-ee/tags/v8.0.2')
expect(rendered).to match '8.0.2'
expect(rendered).to have_link('abcdefg', href: %r{https://gitlab.com/gitlab-org/gitlab-(ce|ee)/commits/abcdefg})
end
end end
end end
...@@ -37,11 +57,6 @@ describe 'help/index' do ...@@ -37,11 +57,6 @@ describe 'help/index' do
allow(view).to receive(:user_signed_in?).and_return(user) allow(view).to receive(:user_signed_in?).and_return(user)
end end
def stub_version(version, revision)
stub_const('Gitlab::VERSION', version)
allow(Gitlab).to receive(:revision).and_return(revision)
end
def stub_helpers def stub_helpers
allow(view).to receive(:markdown).and_return('') allow(view).to receive(:markdown).and_return('')
allow(view).to receive(:version_status_badge).and_return('') allow(view).to receive(:version_status_badge).and_return('')
......
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