Skip to content

Commit 06f8d5f

Browse files
author
Kevin Paulisse
committed
Merge branch 'kpaulisse-release-1-0-doc' into kpaulisse-script-integration
2 parents 7955b4a + 9d9c786 commit 06f8d5f

17 files changed

Lines changed: 254 additions & 37 deletions

File tree

.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.6.1
1+
0.99.rc1

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ At GitHub, we manage thousands of nodes with a Puppet code base containing 500,0
88

99
`octocatalog-diff` is written in Ruby and is distributed as a gem. It runs on Mac OS and Unix/Linux platforms.
1010

11-
It is under active development at this time. We suspect that with the initial release, some people who try it out could be using configurations of Puppet that we haven't experienced within our environment. We are eager to identify and fix as many of these as we can to expand the compatibility of this tool as much as possible.
11+
We consider the 1.x release of `octocatalog-diff` to be stable and production-quality. We continue to maintain and enhance `octocatalog-diff` to meet our own internal needs and to incorporate suggestions from the community. Please consult the [change log](/doc/CHANGELOG.md) for details.
1212

1313
## How?
1414

doc/CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@
88
</tr>
99
</thead><tbody>
1010
<tr valign=top>
11+
<td>0.99.0rc1</td>
12+
<td>2017-xx-xx</td>
13+
<td>
14+
This is a release candidate for `octocatalog-diff` version 1.0. Please use caution before using this in a production environment. Report any problems to us as <a href="https://github.com/github/octocatalog-diff/issues/new">in a new issue</a>.
15+
16+
<h4>New Features</h4>
17+
18+
The most significant change in version 1.0 is the addition of the <a href="./dev/api.md">V1 API</a>, which permits developers to build catalogs (<code>--catalog-only</code>) and compare/diff catalogs using octocatalog-diff. Under the hood, we've rearranged the code to support these APIs, which should also improve the reliability and allow faster development cycles.
19+
20+
<h4>Breaking Changes</h4>
21+
22+
The format of the output from <code>--output-format json</code> has changed. In version 0.x of the software, each difference was represented by an array. In version 1.x, each difference is represented by a hash with meaningful English keys. We have added an option <code>--output-format legacy_json</code> if anyone depends upon the output in the old format.
23+
24+
</td>
25+
</tr>
26+
<tr valign=top>
1127
<td>0.6.1</td>
1228
<td>2017-01-07</td>
1329
<td>

doc/dev/api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
The octocatalog-diff API allows developers to construct and work with certain octocatalog-diff internals in their own projects.
44

5-
The current API version is [API v1](/doc/dev/api/v1.md), which is available as of octocatalog-diff version 0.7.
5+
The current API version is [API v1](/doc/dev/api/v1.md), which is available as of octocatalog-diff version 1.0.

doc/dev/api/v1/objects/diff.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ Note that this is a pass-through of information provided in the Puppet catalog,
4444

4545
Note also that if the diff represents removal of a resource, this will return `nil`, because the resource does not exist in the new catalog.
4646

47+
#### `#new_location` (Hash)
48+
49+
Returns a hash containing `:file` (equal to `#new_file`) and `:line` (equal to `#new_line`) when either is defined. Returns `nil` if both are undefined.
50+
4751
#### `#new_value` (Object)
4852

4953
Returns the value of the resource from the new catalog.
@@ -111,6 +115,10 @@ Note that this is a pass-through of information provided in the Puppet catalog,
111115

112116
Note also that if the diff represents addition of a resource, this will return `nil`, because the resource does not exist in the old catalog.
113117

118+
#### `#old_location` (Hash)
119+
120+
Returns a hash containing `:file` (equal to `#old_file`) and `:line` (equal to `#old_line`) when either is defined. Returns `nil` if both are undefined.
121+
114122
#### `#old_value` (Object)
115123

116124
Returns the value of the resource from the old catalog.
@@ -249,4 +257,5 @@ These methods are available for debugging or development purposes but are not gu
249257
- `#inspect` (String): Returns inspection of object
250258
- `#raw` (Array): Returns internal array data structure of the "diff"
251259
- `#to_h` (Hash): Returns object as a hash, where keys are above described methods
260+
- `#to_h_with_string_keys` (Hash): Returns object as a hash, where keys are above described methods; keys are strings, not symbols
252261
- `#[]` (Object): Retrieve indexed array elements from raw internal array object

doc/optionsref.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Usage: octocatalog-diff [command line options]
2727
--bootstrap-then-exit Bootstrap from-dir and/or to-dir and then exit
2828
--[no-]color Enable/disable colors in output
2929
-o, --output-file FILENAME Output results into FILENAME
30-
--output-format FORMAT Output format: text,json
30+
--output-format FORMAT Output format: text,json,legacy_json
3131
-d, --[no-]debug Print debugging messages to STDERR
3232
-q, --[no-]quiet Quiet (no status messages except errors)
3333
--ignore "Type1[Title1],Type2[Title2],..."
@@ -708,10 +708,12 @@ to ignore any changes for any defined type where this tag is set. (<a href="../l
708708
<pre><code>--output-format FORMAT</code></pre>
709709
</td>
710710
<td valign=top>
711-
Output format: text,json
711+
Output format: text,json,legacy_json
712712
</td>
713713
<td valign=top>
714-
Output format option (<a href="../lib/octocatalog-diff/cli/options/output_format.rb">output_format.rb</a>)
714+
Output format option. 'text' is human readable text, 'json' is an array of differences
715+
identified by human readable keys (the preferred octocatalog-diff 1.x format), and 'legacy_json' is an
716+
array of differences, where each difference is an array (the octocatalog-diff 0.x format). (<a href="../lib/octocatalog-diff/cli/options/output_format.rb">output_format.rb</a>)
715717
</td>
716718
</tr>
717719

lib/octocatalog-diff/api/v1/diff.rb

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@ class Diff
2222
# Constructor: Accepts a diff in the traditional array format and stores it.
2323
# @param raw [Array] Diff in the traditional format
2424
def initialize(raw)
25+
if raw.is_a?(OctocatalogDiff::API::V1::Diff)
26+
@raw = raw.raw
27+
return
28+
end
29+
2530
unless raw.is_a?(Array)
26-
raise ArgumentError, 'OctocatalogDiff::API::V1::Diff#initialize expects Array argument'
31+
raise ArgumentError, "OctocatalogDiff::API::V1::Diff#initialize expects Array argument (got #{raw.class})"
2732
end
2833
@raw = raw
2934
end
@@ -119,6 +124,22 @@ def new_line
119124
x.nil? ? nil : x['line']
120125
end
121126

127+
# Public: Get the "old" location, i.e. location in the "from" catalog
128+
# @return [Hash] <file:, line:> of resource
129+
def old_location
130+
return nil if addition?
131+
return @raw[3] if removal?
132+
@raw[4]
133+
end
134+
135+
# Public: Get the "new" location, i.e. location in the "to" catalog
136+
# @return [Hash] <file:, line:> of resource
137+
def new_location
138+
return @raw[3] if addition?
139+
return nil if removal?
140+
@raw[5]
141+
end
142+
122143
# Public: Convert this object to a hash
123144
# @return [Hash] Hash with keys set by these methods
124145
def to_h
@@ -132,10 +153,20 @@ def to_h
132153
old_file: old_file,
133154
old_line: old_line,
134155
new_file: new_file,
135-
new_line: new_line
156+
new_line: new_line,
157+
old_location: old_location,
158+
new_location: new_location
136159
}
137160
end
138161

162+
# Public: Convert this object to a hash with string keys
163+
# @return [Hash] Hash with keys set by these methods, with string keys
164+
def to_h_with_string_keys
165+
result = {}
166+
to_h.each { |key, val| result[key.to_s] = val }
167+
result
168+
end
169+
139170
# Public: String inspection
140171
# @return [String] String for inspection
141172
def inspect
@@ -147,24 +178,6 @@ def inspect
147178
def to_s
148179
raw.inspect
149180
end
150-
151-
private
152-
153-
# Private: Get the "old" location, i.e. location in the "from" catalog
154-
# @return [Hash] <file:, line:> of resource
155-
def old_location
156-
return nil if addition?
157-
return @raw[3] if removal?
158-
@raw[4]
159-
end
160-
161-
# Private: Get the "new" location, i.e. location in the "to" catalog
162-
# @return [Hash] <file:, line:> of resource
163-
def new_location
164-
return @raw[3] if addition?
165-
return nil if removal?
166-
@raw[5]
167-
end
168181
end
169182
end
170183
end

lib/octocatalog-diff/catalog-diff/display.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# frozen_string_literal: true
22

3+
require_relative '../api/v1/diff'
34
require_relative 'differ'
45
require_relative 'display/json'
6+
require_relative 'display/legacy_json'
57
require_relative 'display/text'
68

79
module OctocatalogDiff
@@ -21,8 +23,9 @@ class Display
2123
# @param logger [Logger] Logger object
2224
# @return [String] Text output for provided diff
2325
def self.output(diff_in, options = {}, logger = nil)
24-
diff = diff_in.is_a?(OctocatalogDiff::CatalogDiff::Differ) ? diff_in.diff : diff_in
25-
raise ArgumentError, "text_output requires Array<Diff results>; passed in #{diff_in.class}" unless diff.is_a?(Array)
26+
diff_x = diff_in.is_a?(OctocatalogDiff::CatalogDiff::Differ) ? diff_in.diff : diff_in
27+
raise ArgumentError, "text_output requires Array<Diff results>; passed in #{diff_in.class}" unless diff_x.is_a?(Array)
28+
diff = diff_x.map { |x| OctocatalogDiff::API::V1::Diff.new(x) }
2629

2730
# req_format means 'requested format' because 'format' has a built-in meaning to Ruby
2831
req_format = options.fetch(:format, :color_text)
@@ -41,6 +44,9 @@ def self.output(diff_in, options = {}, logger = nil)
4144
when :json
4245
logger.debug 'Generating JSON output' if logger
4346
OctocatalogDiff::CatalogDiff::Display::Json.generate(diff, opts, logger)
47+
when :legacy_json
48+
logger.debug 'Generating Legacy JSON output' if logger
49+
OctocatalogDiff::CatalogDiff::Display::LegacyJson.generate(diff, opts, logger)
4450
when :text
4551
logger.debug 'Generating non-colored text output' if logger
4652
OctocatalogDiff::CatalogDiff::Display::Text.generate(diff, opts.merge(color: false), logger)

lib/octocatalog-diff/catalog-diff/display/json.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
module OctocatalogDiff
88
module CatalogDiff
99
class Display
10-
# Display the output from a diff in JSON format.
10+
# Display the output from a diff in JSON format. This is the new format, used in octocatalog-diff
11+
# 1.x, where each diff is represented by an hash with named keys.
1112
class Json < OctocatalogDiff::CatalogDiff::Display
1213
# Generate JSON representation of the 'diff' suitable for further analysis.
1314
# @param diff [Array<Diff results>] The diff which *must* be in this format
@@ -16,7 +17,7 @@ class Json < OctocatalogDiff::CatalogDiff::Display
1617
# @param _logger [Logger] Not used here
1718
def self.generate(diff, options = {}, _logger = nil)
1819
result = {
19-
'diff' => diff
20+
'diff' => diff.map(&:to_h_with_string_keys)
2021
}
2122
result['header'] = options[:header] unless options[:header].nil?
2223
result.to_json
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../display'
4+
5+
require 'json'
6+
7+
module OctocatalogDiff
8+
module CatalogDiff
9+
class Display
10+
# Display the output from a diff in JSON format. This is the legacy format, used in octocatalog-diff
11+
# 0.x, where each diff is represented by an array.
12+
class LegacyJson < OctocatalogDiff::CatalogDiff::Display
13+
# Generate JSON representation of the 'diff' suitable for further analysis.
14+
# @param diff [Array<Diff results>] The diff which *must* be in this format
15+
# @param options [Hash] Options which are:
16+
# - :header => [String] Header to print; no header is printed if not specified
17+
# @param _logger [Logger] Not used here
18+
def self.generate(diff, options = {}, _logger = nil)
19+
result = {
20+
'diff' => diff.map(&:raw)
21+
}
22+
result['header'] = options[:header] unless options[:header].nil?
23+
result.to_json
24+
end
25+
end
26+
end
27+
end
28+
end

0 commit comments

Comments
 (0)