diff --git a/app/helpers/version_check_helper.rb b/app/helpers/version_check_helper.rb index 75637eb067697ab225c4482eb52eead966e98801..ab77b1490729740b53db0bf1bfeacced40b8c040 100644 --- a/app/helpers/version_check_helper.rb +++ b/app/helpers/version_check_helper.rb @@ -9,4 +9,17 @@ module VersionCheckHelper image_url = VersionCheck.new.url image_tag image_url, class: 'js-version-status-badge' 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 diff --git a/app/views/help/index.html.haml b/app/views/help/index.html.haml index 198c2d35b29e60e2fe823fa65d0c57bf92a2caec..dfa5d820ce932628bfde9c778bd1024c9adce3c3 100644 --- a/app/views/help/index.html.haml +++ b/app/views/help/index.html.haml @@ -7,7 +7,7 @@ GitLab Community Edition - if user_signed_in? - %span= link_to Gitlab::VERSION, Gitlab::COM_URL + namespace_project_tag_path('gitlab-org', 'gitlab-ce', "v#{Gitlab::VERSION}") + %span= link_to_version = version_status_badge %hr diff --git a/changelogs/unreleased/bvl-show-pre-release-sha.yml b/changelogs/unreleased/bvl-show-pre-release-sha.yml new file mode 100644 index 0000000000000000000000000000000000000000..524b3c374f70e041f1383e86e76baa197434101f --- /dev/null +++ b/changelogs/unreleased/bvl-show-pre-release-sha.yml @@ -0,0 +1,5 @@ +--- +title: Show SHA for pre-release versions on the help page +merge_request: 22026 +author: +type: changed diff --git a/lib/gitlab.rb b/lib/gitlab.rb index ab6b609d09979b6569d11f8a35a37e305cf4a4c2..7790534d5d78091cbcdde972d518d3b143cb0b8a 100644 --- a/lib/gitlab.rb +++ b/lib/gitlab.rb @@ -47,4 +47,8 @@ module Gitlab def self.dev_env_or_com? Rails.env.development? || org? || com? end + + def self.pre_release? + VERSION.include?('pre') + end end diff --git a/spec/support/stub_version.rb b/spec/support/stub_version.rb new file mode 100644 index 0000000000000000000000000000000000000000..594ab64e7c6c8edf379dcfa17dd3503fe9dc4d7f --- /dev/null +++ b/spec/support/stub_version.rb @@ -0,0 +1,8 @@ +# 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 diff --git a/spec/views/help/index.html.haml_spec.rb b/spec/views/help/index.html.haml_spec.rb index c8c9c4e773dd94cbdd235ce5669404985503f25c..34e93d929a7603764b02e1f7f548a204e44d95cb 100644 --- a/spec/views/help/index.html.haml_spec.rb +++ b/spec/views/help/index.html.haml_spec.rb @@ -1,11 +1,18 @@ +# frozen_string_literal: true + require 'rails_helper' describe 'help/index' do + include StubVersion + describe 'version information' do + before do + stub_helpers + end + it 'is hidden from guests' do stub_user(nil) stub_version('8.0.2', 'abcdefg') - stub_helpers render @@ -13,15 +20,28 @@ describe 'help/index' do expect(rendered).not_to match 'abcdefg' end - it 'is shown to users' do - stub_user - stub_version('8.0.2', 'abcdefg') - stub_helpers + context 'when logged in' do + before do + stub_user + 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' - expect(rendered).to have_link('8.0.2', href: 'https://gitlab.com/gitlab-org/gitlab-ce/tags/v8.0.2') + render + + 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 @@ -37,11 +57,6 @@ describe 'help/index' do allow(view).to receive(:user_signed_in?).and_return(user) end - def stub_version(version, revision) - stub_const('Gitlab::VERSION', version) - allow(Gitlab).to receive(:revision).and_return(revision) - end - def stub_helpers allow(view).to receive(:markdown).and_return('') allow(view).to receive(:version_status_badge).and_return('')