11# frozen_string_literal: true
22
3+ require_relative '../../api/v1/diff'
34require_relative '../filter'
45
56require 'yaml'
@@ -13,20 +14,24 @@ class YAML < OctocatalogDiff::CatalogDiff::Filter
1314 # Return true if the YAML objects are known to be equivalent. Return false if they
1415 # are not equivalent, or if equivalence cannot be determined.
1516 #
16- # @param diff [Array] Difference
17+ # @param diff_in [Array] Difference
1718 # @param _options [Hash] Additional options (there are none for this filter)
1819 # @return [Boolean] true if this difference is a YAML file with identical objects, false otherwise
19- def filtered? ( diff , _options = { } )
20+ def filtered? ( diff_in , _options = { } )
21+ # Create API object for diff to simplify code
22+ diff = OctocatalogDiff ::API ::V1 ::Diff . new ( diff_in )
23+
2024 # Skip additions or removals - focus only on changes
21- return false unless diff [ 0 ] == '~' || diff [ 0 ] == '!'
25+ return false unless diff . change?
2226
2327 # Make sure we are comparing file content for a file ending in .yaml or .yml extension
24- return false unless diff [ 1 ] =~ /^File\f ([^\f ]+)\. ya?ml\f parameters\f content$/
28+ return false unless diff . type == 'File' && diff . structure == %w( parameters content )
29+ return false unless diff . title =~ /\. ya?ml\z /
2530
26- # Attempt to convert the old (diff[2]) and new (diff[3]) into YAML objects. Assuming
31+ # Attempt to convert the old value and new value into YAML objects. Assuming
2732 # that doesn't error out, the return value is whether or not they're equal.
28- obj_old = ::YAML . load ( diff [ 2 ] )
29- obj_new = ::YAML . load ( diff [ 3 ] )
33+ obj_old = ::YAML . load ( diff . old_value )
34+ obj_new = ::YAML . load ( diff . new_value )
3035 obj_old == obj_new
3136 rescue # Rescue everything - if something failed, we aren't sure what's going on, so we'll return false.
3237 false
0 commit comments