Class: Datadog::CI::TestImpactAnalysis::Coverage::Files
- Inherits:
-
Object
- Object
- Datadog::CI::TestImpactAnalysis::Coverage::Files
- Defined in:
- lib/datadog/ci/test_impact_analysis/coverage/files.rb
Overview
Keeps native coverage and custom impacted files together and normalizes their paths for serialization.
Constant Summary collapse
- EMPTY_FILES =
[].freeze
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(coverage, custom_impacted_files = EMPTY_FILES) ⇒ Files
constructor
A new instance of Files.
-
#inspect_coverage ⇒ Object
Returns a readable view while preserving the paths supplied by native coverage and the custom impacted-files API.
- #size ⇒ Object
-
#write_to(packer) ⇒ Object
Writes the complete MessagePack files array.
Constructor Details
#initialize(coverage, custom_impacted_files = EMPTY_FILES) ⇒ Files
Returns a new instance of Files.
17 18 19 20 21 22 23 24 25 |
# File 'lib/datadog/ci/test_impact_analysis/coverage/files.rb', line 17 def initialize(coverage, custom_impacted_files = EMPTY_FILES) @coverage = coverage @custom_impacted_files = custom_impacted_files # The repository root is a process invariant between coverage # events. Capture it once so native normalization can reuse the # same exact boundary for this event without repeated lookups. @root = Git::LocalRepository.root @normalized_files = nil end |
Instance Method Details
#each ⇒ Object
27 28 29 |
# File 'lib/datadog/ci/test_impact_analysis/coverage/files.rb', line 27 def each normalized_files.each { |file| yield file } end |
#inspect_coverage ⇒ Object
Returns a readable view while preserving the paths supplied by native coverage and the custom impacted-files API. Serialized files are normalized through #each.
62 63 64 65 66 67 68 |
# File 'lib/datadog/ci/test_impact_analysis/coverage/files.rb', line 62 def inspect_coverage coverage = @coverage.dup @custom_impacted_files.each do |file| coverage[file] = true end coverage end |
#size ⇒ Object
31 32 33 |
# File 'lib/datadog/ci/test_impact_analysis/coverage/files.rb', line 31 def size normalized_files.size end |
#write_to(packer) ⇒ Object
Writes the complete MessagePack files array. The native fast path combines absolute-path classification, immutable-root slicing, and filename-entry packing. Any shape it does not support falls back before writing bytes.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/datadog/ci/test_impact_analysis/coverage/files.rb', line 39 def write_to(packer) if FileSerialization.respond_to?(:pack_files) && (packed_files = FileSerialization.pack_files( @coverage, @custom_impacted_files, @root )) packer.buffer.write(packed_files) return packer end packer.write_array_header(size) each do |filename| packer.write_map_header(1) packer.write("filename") packer.write(filename) end packer end |