Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBrandon Labuschagne <blabuschagne@gitlab.com>2019-01-14 19:10:19 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2019-01-14 19:10:19 +0300
commitcc281afb27365adef2d24c85f83686cc8b829187 (patch)
tree0c2d33acde02760d7d45e22c0cdba8f8a8a3f2d6 /lib
parent31af7daf788f3f65d630ab4e5d8bae4bd5607807 (diff)
Resolve "Add "What's new" menu item in top navigation"
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab.rb48
-rw-r--r--lib/gitlab/release_blog_post.rb40
-rw-r--r--lib/gitlab/version_info.rb8
3 files changed, 88 insertions, 8 deletions
diff --git a/lib/gitlab.rb b/lib/gitlab.rb
index 2ef54658a11..074d04fc32a 100644
--- a/lib/gitlab.rb
+++ b/lib/gitlab.rb
@@ -27,12 +27,52 @@ module Gitlab
end
end
+ def self.version_info
+ Gitlab::VersionInfo.parse(Gitlab::VERSION)
+ end
+
COM_URL = 'https://gitlab.com'.freeze
APP_DIRS_PATTERN = %r{^/?(app|config|ee|lib|spec|\(\w*\))}
SUBDOMAIN_REGEX = %r{\Ahttps://[a-z0-9]+\.gitlab\.com\z}
VERSION = File.read(root.join("VERSION")).strip.freeze
INSTALLATION_TYPE = File.read(root.join("INSTALLATION_TYPE")).strip.freeze
+ def self.pre_release?
+ VERSION.include?('pre')
+ end
+
+ def self.final_release?
+ !VERSION.include?('rc') && !pre_release?
+ end
+
+ def self.minor_release
+ "#{version_info.major}.#{version_info.minor}"
+ end
+
+ def self.prev_minor_release
+ "#{version_info.major}.#{version_info.minor - 1}"
+ end
+
+ def self.prev_major_release
+ "#{version_info.major.to_i - 1}"
+ end
+
+ def self.new_major_release?
+ version_info.minor.to_i.zero?
+ end
+
+ def self.previous_release
+ if version_info.minor_version?
+ if version_info.patch_version?
+ minor_release
+ else
+ prev_minor_release
+ end
+ else
+ prev_major_release
+ end
+ end
+
def self.com?
# Check `gl_subdomain?` as well to keep parity with gitlab.com
Gitlab.config.gitlab.url == COM_URL || gl_subdomain?
@@ -49,12 +89,4 @@ module Gitlab
def self.dev_env_or_com?
Rails.env.development? || org? || com?
end
-
- def self.pre_release?
- VERSION.include?('pre')
- end
-
- def self.version_info
- Gitlab::VersionInfo.parse(Gitlab::VERSION)
- end
end
diff --git a/lib/gitlab/release_blog_post.rb b/lib/gitlab/release_blog_post.rb
new file mode 100644
index 00000000000..639aee61464
--- /dev/null
+++ b/lib/gitlab/release_blog_post.rb
@@ -0,0 +1,40 @@
+# frozen_string_literal: true
+require 'singleton'
+
+module Gitlab
+ class ReleaseBlogPost
+ include Singleton
+
+ RELEASE_RSS_URL = 'https://about.gitlab.com/releases.xml'
+
+ def blog_post_url
+ @url ||= fetch_blog_post_url
+ end
+
+ private
+
+ def fetch_blog_post_url
+ installed_version = Gitlab.final_release? ? Gitlab.minor_release : Gitlab.previous_release
+ response = Gitlab::HTTP.get(RELEASE_RSS_URL, verify: false)
+
+ return unless response.code == 200
+
+ blog_entry = find_installed_blog_entry(response, installed_version)
+ blog_entry['id'] if blog_entry
+ end
+
+ def find_installed_blog_entry(response, installed_version)
+ response['feed']['entry'].find do |entry|
+ entry['release'] == installed_version || matches_previous_release_post(entry['release'], installed_version)
+ end
+ end
+
+ def should_match_previous_release_post?
+ Gitlab.new_major_release? && !Gitlab.final_release?
+ end
+
+ def matches_previous_release_post(rss_release_version, installed_version)
+ should_match_previous_release_post? && rss_release_version[/\d+/] == installed_version
+ end
+ end
+end
diff --git a/lib/gitlab/version_info.rb b/lib/gitlab/version_info.rb
index aa6d5310161..142ead12c08 100644
--- a/lib/gitlab/version_info.rb
+++ b/lib/gitlab/version_info.rb
@@ -20,6 +20,14 @@ module Gitlab
@patch = patch
end
+ def minor_version?
+ minor.to_i > 0
+ end
+
+ def patch_version?
+ patch.to_i > 0
+ end
+
def <=>(other)
return unless other.is_a? VersionInfo
return unless valid? && other.valid?