Class: Datadog::CI::Remote::LibrarySettings

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/ci/remote/library_settings.rb

Overview

Wrapper around the settings HTTP response

Instance Method Summary collapse

Constructor Details

#initialize(http_response) ⇒ LibrarySettings

Returns a new instance of LibrarySettings.



17
18
19
20
# File 'lib/datadog/ci/remote/library_settings.rb', line 17

def initialize(http_response)
  @http_response = http_response
  @json = nil
end

Instance Method Details

#code_coverage_enabled?Boolean

Returns:

  • (Boolean)


67
68
69
70
71
72
73
# File 'lib/datadog/ci/remote/library_settings.rb', line 67

def code_coverage_enabled?
  return @code_coverage_enabled if defined?(@code_coverage_enabled)

  @code_coverage_enabled = Utils::Parsing.convert_to_bool(
    payload.fetch(Ext::Transport::DD_API_SETTINGS_RESPONSE_CODE_COVERAGE_KEY, false)
  )
end

#early_flake_detection_enabled?Boolean

Returns:

  • (Boolean)


93
94
95
96
97
98
99
# File 'lib/datadog/ci/remote/library_settings.rb', line 93

def early_flake_detection_enabled?
  return @early_flake_detection_enabled if defined?(@early_flake_detection_enabled)

  @early_flake_detection_enabled = Utils::Parsing.convert_to_bool(
    early_flake_detection_payload.fetch(Ext::Transport::DD_API_SETTINGS_RESPONSE_ENABLED_KEY, false)
  )
end

#faulty_session_thresholdObject



109
110
111
112
113
114
115
# File 'lib/datadog/ci/remote/library_settings.rb', line 109

def faulty_session_threshold
  return @faulty_session_threshold if defined?(@faulty_session_threshold)

  @faulty_session_threshold = early_flake_detection_payload.fetch(
    Ext::Transport::DD_API_SETTINGS_RESPONSE_FAULTY_SESSION_THRESHOLD_KEY, 0
  )
end

#flaky_test_retries_enabled?Boolean

Returns:

  • (Boolean)


83
84
85
86
87
88
89
90
91
# File 'lib/datadog/ci/remote/library_settings.rb', line 83

def flaky_test_retries_enabled?
  return @flaky_test_retries_enabled if defined?(@flaky_test_retries_enabled)

  @flaky_test_retries_enabled = Utils::Parsing.convert_to_bool(
    payload.fetch(
      Ext::Transport::DD_API_SETTINGS_RESPONSE_FLAKY_TEST_RETRIES_KEY, false
    )
  )
end

#itr_enabled?Boolean

Returns:

  • (Boolean)


59
60
61
62
63
64
65
# File 'lib/datadog/ci/remote/library_settings.rb', line 59

def itr_enabled?
  return @itr_enabled if defined?(@itr_enabled)

  @itr_enabled = Utils::Parsing.convert_to_bool(
    payload.fetch(Ext::Transport::DD_API_SETTINGS_RESPONSE_ITR_ENABLED_KEY, false)
  )
end

#ok?Boolean

Returns:

  • (Boolean)


22
23
24
25
# File 'lib/datadog/ci/remote/library_settings.rb', line 22

def ok?
  resp = @http_response
  !resp.nil? && resp.ok?
end

#payloadObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/datadog/ci/remote/library_settings.rb', line 27

def payload
  cached = @json
  return cached unless cached.nil?

  resp = @http_response
  return @json = default_payload if resp.nil? || !ok?

  begin
    @json = JSON.parse(resp.payload).dig(*Ext::Transport::DD_API_SETTINGS_RESPONSE_DIG_KEYS) ||
      default_payload
  rescue JSON::ParserError => e
    Datadog.logger.error("Failed to parse settings response payload: #{e}. Payload was: #{resp.payload}")

    Transport::Telemetry.api_requests_errors(
      Ext::Telemetry::METRIC_GIT_REQUESTS_SETTINGS_ERRORS,
      1,
      error_type: "invalid_json",
      status_code: nil
    )

    @json = default_payload
  end
end

#require_git?Boolean

Returns:

  • (Boolean)


51
52
53
54
55
56
57
# File 'lib/datadog/ci/remote/library_settings.rb', line 51

def require_git?
  return @require_git if defined?(@require_git)

  @require_git = Utils::Parsing.convert_to_bool(
    payload.fetch(Ext::Transport::DD_API_SETTINGS_RESPONSE_REQUIRE_GIT_KEY, false)
  )
end

#slow_test_retriesObject



101
102
103
104
105
106
107
# File 'lib/datadog/ci/remote/library_settings.rb', line 101

def slow_test_retries
  return @slow_test_retries if defined?(@slow_test_retries)

  @slow_test_retries = SlowTestRetries.new(
    early_flake_detection_payload.fetch(Ext::Transport::DD_API_SETTINGS_RESPONSE_SLOW_TEST_RETRIES_KEY, {})
  )
end

#tests_skipping_enabled?Boolean

Returns:

  • (Boolean)


75
76
77
78
79
80
81
# File 'lib/datadog/ci/remote/library_settings.rb', line 75

def tests_skipping_enabled?
  return @tests_skipping_enabled if defined?(@tests_skipping_enabled)

  @tests_skipping_enabled = Utils::Parsing.convert_to_bool(
    payload.fetch(Ext::Transport::DD_API_SETTINGS_RESPONSE_TESTS_SKIPPING_KEY, false)
  )
end