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

whats_new_helper.rb « helpers « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: edb3544d2d4d38653d55b058dbdf6b79cb0a5c41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# frozen_string_literal: true

module WhatsNewHelper
  EMPTY_JSON = ''.to_json

  def whats_new_most_recent_release_items_count
    items = parsed_most_recent_release_items

    return unless items.is_a?(Array)

    items.count
  end

  def whats_new_storage_key
    items = parsed_most_recent_release_items

    return unless items.is_a?(Array)

    release = items.first.try(:[], 'release')

    ['display-whats-new-notification', release].compact.join('-')
  end

  def whats_new_most_recent_release_items
    YAML.load_file(most_recent_release_file_path).to_json

  rescue => e
    Gitlab::ErrorTracking.track_exception(e, yaml_file_path: most_recent_release_file_path)

    EMPTY_JSON
  end

  private

  def parsed_most_recent_release_items
    Gitlab::Json.parse(whats_new_most_recent_release_items)
  end

  def most_recent_release_file_path
    Dir.glob(files_path).max
  end

  def files_path
    Rails.root.join('data', 'whats_new', '*.yml')
  end
end