File: crystalball_env.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (59 lines) | stat: -rw-r--r-- 2,186 bytes parent folder | download
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
48
49
50
51
52
53
54
55
56
57
58
59
# frozen_string_literal: true

module CrystalballEnv
  EXCLUDED_PREFIXES = %w[vendor/ruby].freeze

  extend self

  def start!
    return unless ENV['CRYSTALBALL'] == 'true'

    require 'crystalball'

    enable_described_strategy # We use this for writing and reading

    # TODO: Please work on https://gitlab.com/gitlab-org/gitlab/-/issues/498479 before enabling CoverageStrategy again
    # enable_coverage_strategy # We use this only for writing for now
  end

  def enable_described_strategy
    require_relative '../tooling/lib/tooling/crystalball/described_class_execution_detector'

    Crystalball::MapGenerator.start! do |config|
      config.map_storage_path = "crystalball/described/#{map_storage_name}.yml"

      # https://toptal.github.io/crystalball/map_generators/#describedclassstrategy
      described_class_execution_detector = Tooling::Crystalball::DescribedClassExecutionDetector.new(
        root_path: File.expand_path('../', __dir__),
        exclude_prefixes: EXCLUDED_PREFIXES
      )
      config.register Crystalball::MapGenerator::DescribedClassStrategy.new(
        execution_detector: described_class_execution_detector
      )
    end
  end

  def enable_coverage_strategy
    # Modified version of https://toptal.github.io/crystalball/map_generators/#coveragestrategy
    require_relative '../tooling/lib/tooling/crystalball/coverage_lines_execution_detector'
    require_relative '../tooling/lib/tooling/crystalball/coverage_lines_strategy'

    Crystalball::MapGenerator.start! do |config|
      config.map_storage_path = "crystalball/coverage/#{map_storage_name}.yml"

      execution_detector = Tooling::Crystalball::CoverageLinesExecutionDetector
        .new(exclude_prefixes: EXCLUDED_PREFIXES)

      config.register Tooling::Crystalball::CoverageLinesStrategy
        .new(execution_detector)

      # https://toptal.github.io/crystalball/map_generators/#actionviewstrategy
      # require 'crystalball/rails/map_generator/action_view_strategy'
      # config.register Crystalball::Rails::MapGenerator::ActionViewStrategy.new
    end
  end

  def map_storage_name
    (ENV['CI_JOB_NAME'] || 'crystalball_data').gsub(%r{[/ ]}, '_')
  end
end