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

project_dashboard_service.rb « dashboard « metrics « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fdffd067c933c7f7114348b4569d67b0bbeca396 (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
47
# frozen_string_literal: true

# Searches a projects repository for a metrics dashboard and formats the output.
# Expects any custom dashboards will be located in `.gitlab/dashboards`
# Use Gitlab::Metrics::Dashboard::Finder to retrive dashboards.
module Gitlab
  module Metrics
    module Dashboard
      class ProjectDashboardService < Gitlab::Metrics::Dashboard::BaseService
        DASHBOARD_ROOT = ".gitlab/dashboards"

        class << self
          def all_dashboard_paths(project)
            file_finder(project)
              .list_files_for(DASHBOARD_ROOT)
              .map do |filepath|
                Rails.cache.delete(cache_key(project.id, filepath))

                { path: filepath, default: false }
              end
          end

          def file_finder(project)
            Gitlab::Template::Finders::RepoTemplateFinder.new(project, DASHBOARD_ROOT, '.yml')
          end

          def cache_key(id, dashboard_path)
            "project_#{id}_metrics_dashboard_#{dashboard_path}"
          end
        end

        private

        # Searches the project repo for a custom-defined dashboard.
        def get_raw_dashboard
          yml = self.class.file_finder(project).read(dashboard_path)

          YAML.safe_load(yml)
        end

        def cache_key
          self.class.cache_key(project.id, dashboard_path)
        end
      end
    end
  end
end