Class: Datadog::CI::ImpactedTestsDetection::Component
- Inherits:
-
Object
- Object
- Datadog::CI::ImpactedTestsDetection::Component
- Defined in:
- lib/datadog/ci/impacted_tests_detection/component.rb
Instance Method Summary collapse
- #configure(library_settings, test_session) ⇒ Object
- #enabled? ⇒ Boolean
-
#initialize(enabled:) ⇒ Component
constructor
A new instance of Component.
- #modified?(test_span) ⇒ Boolean
- #tag_modified_test(test_span) ⇒ Object
Constructor Details
#initialize(enabled:) ⇒ Component
Returns a new instance of Component.
12 13 14 15 |
# File 'lib/datadog/ci/impacted_tests_detection/component.rb', line 12 def initialize(enabled:) @enabled = enabled @changed_files = Set.new end |
Instance Method Details
#configure(library_settings, test_session) ⇒ Object
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 |
# File 'lib/datadog/ci/impacted_tests_detection/component.rb', line 17 def configure(library_settings, test_session) @enabled &&= library_settings.impacted_tests_enabled? return unless @enabled # we must unshallow the repository before trying to find base_commit_sha or executing `git diff` command git_tree_upload_worker.wait_until_done base_commit_sha = test_session.base_commit_sha || Git::LocalRepository.base_commit_sha if base_commit_sha.nil? Datadog.logger.debug { "Impacted tests detection disabled: base commit not found" } @enabled = false return end changed_files = Git::LocalRepository.get_changed_files_from_diff(base_commit_sha) if changed_files.nil? Datadog.logger.debug { "Impacted tests detection disabled: could not get changed files" } @enabled = false return end Datadog.logger.debug do "Impacted tests detection: found #{changed_files.size} changed files" end Datadog.logger.debug do "Impacted tests detection: changed files: #{changed_files.inspect}" end @changed_files = changed_files @enabled = true end |
#enabled? ⇒ Boolean
50 51 52 |
# File 'lib/datadog/ci/impacted_tests_detection/component.rb', line 50 def enabled? @enabled end |
#modified?(test_span) ⇒ Boolean
54 55 56 57 58 59 60 61 |
# File 'lib/datadog/ci/impacted_tests_detection/component.rb', line 54 def modified?(test_span) return false unless enabled? source_file = test_span.source_file return false if source_file.nil? @changed_files.include?(source_file) end |
#tag_modified_test(test_span) ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/datadog/ci/impacted_tests_detection/component.rb', line 63 def tag_modified_test(test_span) return unless modified?(test_span) Datadog.logger.debug do "Impacted tests detection: test #{test_span.name} with source file #{test_span.source_file} is modified" end test_span.set_tag(Ext::Test::TAG_TEST_IS_MODIFIED, "true") end |