octocatalog-diff 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 39148d81d6f446067f306d988b78a3544f381a47
4
- data.tar.gz: e3212a9a0510be17e5bad0280baa66451cc3d77c
3
+ metadata.gz: a89d4a61710f5fd7a044241c3dd99d0d50ec2737
4
+ data.tar.gz: 362d9371778130cc5eda6978ce9563ac6a1d93e1
5
5
  SHA512:
6
- metadata.gz: a2abdf4c5a2604c70938a50875dacc5af83e4ad4aeaa08ad2ac1e1c97a61c1cd4f47ad928cc361919993db5fb9fa5e70c76f29d172761e8c8bb8b3f68cf62e12
7
- data.tar.gz: 2dbc74ab05804f35ae3106ccdbf494952f262110335e57c57f92f719387071289272fec6f6cea4db30b18b07d745b650a10708120ca9cda44e18a5e0ea3776fd
6
+ metadata.gz: 5fcf1c9e9373f21fc8c14cb3cca8163659e6b0be55a4c449e500d95f35172d29f546de3deba0028d2702e53310a77b9182a06dadace338ec15afa237ddb1fc90
7
+ data.tar.gz: cad1f341cf55e43336f1e1945035491f949f9d81d6cfa13359e5b9c8ae50b6caccf3e7c8c7822e86e05d09fdddff45c7135d2949b5cffe085ff9301cb10ae785
data/.version CHANGED
@@ -1 +1 @@
1
- 0.6.0
1
+ 0.6.1
data/doc/CHANGELOG.md CHANGED
@@ -8,6 +8,15 @@
8
8
  </tr>
9
9
  </thead><tbody>
10
10
  <tr valign=top>
11
+ <td>0.6.1</td>
12
+ <td>2017-01-07</td>
13
+ <td>
14
+ <ul>
15
+ <li><a href="https://github.com/github/octocatalog-diff/pull/46">#46</a>: Add option to ignore whitespace in yaml file diff</li>
16
+ </ul>
17
+ </td>
18
+ </tr>
19
+ <tr valign=top>
11
20
  <td>0.6.0</td>
12
21
  <td>2017-01-04</td>
13
22
  <td>
@@ -0,0 +1,26 @@
1
+ # Additional output filters
2
+
3
+ It is possible to enable additional filters for output results via the `--filters` command line option. This command line option accepts a comma-separated list of additional filters, and applies them to the results in the order you specify. The default behavior is not to use any of these filters.
4
+
5
+ Please note that there are other options to ignore specified diffs, including:
6
+
7
+ - [Ignoring certain changes via command line options](/doc/advanced-ignores.md)
8
+ - [Dynamic ignoring of changes via tags in Puppet manifests](/doc/advanced-dynamic-ignores.md)
9
+
10
+ Here is the list of available filters and an explanation of each:
11
+
12
+ - [YAML](#YAML) - Ignore whitespace/comment differences if YAML parses to the same object
13
+
14
+ ## YAML
15
+
16
+ #### Usage
17
+
18
+ ```
19
+ --filters YAML
20
+ ```
21
+
22
+ #### Description
23
+
24
+ If a file resource has extension `.yml` or `.yaml` and a difference in its content is observed, YAML objects are constructed from the previous and new values. If these YAML objects are identical, the difference is ignored.
25
+
26
+ This allows you to ignore changes in whitespace, comments, etc., that are not meaningful to a machine parsing the file. Please note that by filtering these changes, you are ignoring changes to comments, which may be meaningful to humans.
data/doc/advanced.md CHANGED
@@ -27,6 +27,7 @@ See also:
27
27
  ### Controlling output
28
28
 
29
29
  - [Ignoring certain changes via command line options](/doc/advanced-ignores.md)
30
+ - [Additional output filters](/doc/advanced-filter.md)
30
31
  - [Dynamic ignoring of changes via tags in Puppet manifests](/doc/advanced-dynamic-ignores.md)
31
32
  - [Output formats](/doc/advanced-output-formats.md)
32
33
  - [Useful output hacks](/doc/advanced-output-hacks.md)
data/doc/optionsref.md CHANGED
@@ -46,6 +46,8 @@ Usage: octocatalog-diff [command line options]
46
46
  --no-hiera-path-strip Do not use any default hiera path strip settings
47
47
  --ignore-attr "attr1,attr2,..."
48
48
  Attributes to ignore
49
+ --filters FILTER1[,FILTER2[,...]]
50
+ Filters to apply
49
51
  --[no-]display-source Show source file and line for each difference
50
52
  --[no-]validate-references "before,require,subscribe,notify"
51
53
  References to validate
@@ -424,6 +426,20 @@ on which this is running. (<a href="../lib/octocatalog-diff/catalog-diff/cli/opt
424
426
  </td>
425
427
  </tr>
426
428
 
429
+ <tr>
430
+ <td valign=top>
431
+ <pre><code>--filters FILTER1[,FILTER2[,...]]</code></pre>
432
+ </td>
433
+ <td valign=top>
434
+ Filters to apply
435
+ </td>
436
+ <td valign=top>
437
+ Specify one or more filters to apply to the results of the catalog difference.
438
+ For a list of available filters and further explanation, please refer to
439
+ [Filtering results](/doc/advanced-filter.md). (<a href="../lib/octocatalog-diff/catalog-diff/cli/options/filters.rb">filters.rb</a>)
440
+ </td>
441
+ </tr>
442
+
427
443
  <tr>
428
444
  <td valign=top>
429
445
  <pre><code>-f FROM_BRANCH
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Specify one or more filters to apply to the results of the catalog difference.
4
+ # For a list of available filters and further explanation, please refer to
5
+ # [Filtering results](/doc/advanced-filter.md).
6
+ # @param parser [OptionParser object] The OptionParser argument
7
+ # @param options [Hash] Options hash being constructed; this is modified in this method.
8
+ OctocatalogDiff::CatalogDiff::Cli::Options::Option.newoption(:filters) do
9
+ has_weight 199
10
+
11
+ def parse(parser, options)
12
+ parser.on('--filters FILTER1[,FILTER2[,...]]', Array, 'Filters to apply') do |x|
13
+ options[:filters] ||= []
14
+ options[:filters].concat x
15
+ end
16
+ end
17
+ end
@@ -7,6 +7,7 @@ require 'set'
7
7
  require 'stringio'
8
8
 
9
9
  require_relative '../catalog'
10
+ require_relative 'filter'
10
11
 
11
12
  module OctocatalogDiff
12
13
  module CatalogDiff
@@ -153,6 +154,9 @@ module OctocatalogDiff
153
154
  # out any such parameters from the result array.
154
155
  filter_diffs_for_absent_files(result) if @opts[:suppress_absent_file_details]
155
156
 
157
+ # Apply any additional pluggable filters.
158
+ OctocatalogDiff::CatalogDiff::Filter.apply_filters(result, @opts[:filters])
159
+
156
160
  # That's it!
157
161
  @logger.debug "Exiting catdiff; change count: #{result.size}"
158
162
  result
@@ -175,7 +179,7 @@ module OctocatalogDiff
175
179
  absent_files = Set.new
176
180
  result.each do |diff|
177
181
  next unless diff[0] == '~' || diff[0] == '!'
178
- next unless diff[1] =~ /^File\f(.+)\fparameters\fensure$/
182
+ next unless diff[1] =~ /^File\f([^\f]+)\fparameters\fensure$/
179
183
  next unless ['absent', 'false', false].include?(diff[3])
180
184
  absent_files.add Regexp.last_match(1)
181
185
  end
@@ -0,0 +1,38 @@
1
+ require_relative 'filter/yaml'
2
+
3
+ module OctocatalogDiff
4
+ module CatalogDiff
5
+ # Filtering of diffs, and parent class for inheritance.
6
+ class Filter
7
+ # Public: Apply multiple filters by repeatedly calling the `filter` method for each
8
+ # filter in an array. This method returns nothing.
9
+ #
10
+ # @param result [Array] Difference array (mutated)
11
+ # @param filter_names [Array] Filters to run
12
+ # @param options [Hash] Options for each filter (hashed by name)
13
+ def self.apply_filters(result, filter_names, options = {})
14
+ return unless filter_names.is_a?(Array)
15
+ filter_names.each { |x| filter(result, x, options[x] || {}) }
16
+ end
17
+
18
+ # Public: Perform a filter on `result` using the specified filter class.
19
+ # This mutates `result` by removing items that are ignored. This method
20
+ # returns nothing.
21
+ #
22
+ # @param result [Array] Difference array (mutated)
23
+ # @param filter_class_name [String] Filter class name (from `filter` subdirectory)
24
+ # @param options [Hash] Additional options (optional) to pass to filtered? method
25
+ def self.filter(result, filter_class_name, options = {})
26
+ filter_class_name = [name.to_s, filter_class_name].join('::')
27
+ clazz = Kernel.const_get(filter_class_name)
28
+ result.reject! { |item| clazz.filtered?(item, options) }
29
+ end
30
+
31
+ # Inherited: Construct a default `filtered?` method for the subclass via inheritance.
32
+ # Each subclass must implement this method, so the default method errors.
33
+ def self.filtered?(_item, _options = {})
34
+ raise "No `filtered?` method is implemented in #{name}"
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+
5
+ module OctocatalogDiff
6
+ module CatalogDiff
7
+ class Filter
8
+ # Filter based on equivalence of YAML objects for file resources with named extensions.
9
+ class YAML < OctocatalogDiff::CatalogDiff::Filter
10
+ # Public: Actually do the comparison of YAML objects for appropriate resources.
11
+ # Return true if the YAML objects are known to be equivalent. Return false if they
12
+ # are not equivalent, or if equivalence cannot be determined.
13
+ #
14
+ # @param diff [Array] Difference
15
+ # @param _options [Hash] Additional options (there are none for this filter)
16
+ # @return [Boolean] true if this difference is a YAML file with identical objects, false otherwise
17
+ def self.filtered?(diff, _options = {})
18
+ # Skip additions or removals - focus only on changes
19
+ return false unless diff[0] == '~' || diff[0] == '!'
20
+
21
+ # Make sure we are comparing file content for a file ending in .yaml or .yml extension
22
+ return false unless diff[1] =~ /^File\f([^\f]+)\.ya?ml\fparameters\fcontent$/
23
+
24
+ # Attempt to convert the old (diff[2]) and new (diff[3]) into YAML objects. Assuming
25
+ # that doesn't error out, the return value is whether or not they're equal.
26
+ obj_old = ::YAML.load(diff[2])
27
+ obj_new = ::YAML.load(diff[3])
28
+ obj_old == obj_new
29
+ rescue # Rescue everything - if something failed, we aren't sure what's going on, so we'll return false.
30
+ false
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octocatalog-diff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub, Inc.
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-01-04 00:00:00.000000000 Z
12
+ date: 2017-01-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: diffy
@@ -230,6 +230,7 @@ files:
230
230
  - doc/advanced-ci.md
231
231
  - doc/advanced-dynamic-ignores.md
232
232
  - doc/advanced-environments.md
233
+ - doc/advanced-filter.md
233
234
  - doc/advanced-future-parser.md
234
235
  - doc/advanced-hiera-path-stripping.md
235
236
  - doc/advanced-ignores.md
@@ -291,6 +292,7 @@ files:
291
292
  - lib/octocatalog-diff/catalog-diff/cli/options/fact_file.rb
292
293
  - lib/octocatalog-diff/catalog-diff/cli/options/fact_override.rb
293
294
  - lib/octocatalog-diff/catalog-diff/cli/options/facts_terminus.rb
295
+ - lib/octocatalog-diff/catalog-diff/cli/options/filters.rb
294
296
  - lib/octocatalog-diff/catalog-diff/cli/options/from_puppetdb.rb
295
297
  - lib/octocatalog-diff/catalog-diff/cli/options/header.rb
296
298
  - lib/octocatalog-diff/catalog-diff/cli/options/hiera_config.rb
@@ -339,6 +341,8 @@ files:
339
341
  - lib/octocatalog-diff/catalog-diff/display.rb
340
342
  - lib/octocatalog-diff/catalog-diff/display/json.rb
341
343
  - lib/octocatalog-diff/catalog-diff/display/text.rb
344
+ - lib/octocatalog-diff/catalog-diff/filter.rb
345
+ - lib/octocatalog-diff/catalog-diff/filter/yaml.rb
342
346
  - lib/octocatalog-diff/catalog-util/bootstrap.rb
343
347
  - lib/octocatalog-diff/catalog-util/builddir.rb
344
348
  - lib/octocatalog-diff/catalog-util/cached_master_directory.rb