knife-changelog 1.0.10 → 1.1.0

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
  SHA256:
3
- metadata.gz: 6427a7cfa99765ab6a02df18e9695630b841647d09844d8ac56b72a6bb1dfb6a
4
- data.tar.gz: f44ddf5ff9e5f5be024ee151d76e547c08dd4d7245a837c63142d493b1a6ce80
3
+ metadata.gz: d77470d3d495c0e512053d6c4a9ccca7584f9b0f2d8fc2cd3ff15c21436ec39b
4
+ data.tar.gz: 2217ba60bde8435019511858cc2f356ad6f588079343ec473faf76f0a2121131
5
5
  SHA512:
6
- metadata.gz: c285457809139a674fe3337aaba0d462adeab532209bdc4a6fc73f88d4d11775c83e873869ea99ac132408cf9401c1d535e829026a0f600e37625bce1ee95209
7
- data.tar.gz: d009ca6842b5e0974978fe6b0e4759cebb8bae8351343dd72f3e88363591f8ef7dd5ec98a0016fc88df276f32173b36b818f8cfbc6df88cbd77aa8afd4a54012
6
+ metadata.gz: 6dad4972d1a93fe7b50950051f909cc16623e8ea3d4ba3a4a16e61818da437a55da552de07effc58ff455b0d760b7051093576ce8710f699ff075c1bd2b54004
7
+ data.tar.gz: 9f804da5f9fd9cebf78b939b571f46ef3f7569aa45e0ba52f03cacd96826fffce44c35694270183fe298f43353d402a2a081fa354927133a6a451e14864137c3
@@ -2,11 +2,10 @@
2
2
 
3
3
  lib = File.expand_path('../lib', __FILE__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'knife/changelog/version'
6
5
 
7
6
  Gem::Specification.new do |spec|
8
7
  spec.name = 'knife-changelog'
9
- spec.version = Knife::Changelog::VERSION
8
+ spec.version = '1.1.0'
10
9
  spec.authors = ['Gregoire Seux']
11
10
  spec.email = ['kamaradclimber@gmail.com']
12
11
  spec.summary = 'Facilitate access to cookbooks changelog'
@@ -9,7 +9,6 @@ class Chef
9
9
  banner 'knife changelog COOKBOOK [COOKBOOK ...]'
10
10
 
11
11
  deps do
12
- require 'knife/changelog/version'
13
12
  require 'knife/changelog/changelog'
14
13
  require 'knife/changelog/berksfile'
15
14
  require 'berkshelf'
data/lib/policyfile.rb CHANGED
@@ -171,7 +171,12 @@ class PolicyChangelog
171
171
  def format_output(name, data)
172
172
  output = ["\nChangelog for #{name}: #{data['current_version']}->#{data['target_version']}"]
173
173
  output << '=' * output.first.size
174
- output << git_changelog(data['source_url'], data['current_version'], data['target_version'])
174
+ output << if data['current_version']
175
+ git_changelog(data['source_url'], data['current_version'], data['target_version'])
176
+ else
177
+ 'Cookbook was not in the Policyfile.lock.json'
178
+ end
179
+
175
180
  output.join("\n")
176
181
  end
177
182
 
@@ -182,9 +187,7 @@ class PolicyChangelog
182
187
  # @return [true, false]
183
188
  def reject_version_filter(data)
184
189
  raise 'Data containing versions is nil' if data.nil?
185
- data['current_version'] == data['target_version'] ||
186
- data['current_version'].nil? ||
187
- data['target_version'].nil?
190
+ data['current_version'] == data['target_version'] || data['target_version'].nil?
188
191
  end
189
192
 
190
193
  # Generates Policyfile changelog
@@ -203,10 +206,18 @@ class PolicyChangelog
203
206
  else
204
207
  updated_cookbooks.select { |name, _data| @cookbooks_to_update.include?(name) }
205
208
  end
206
- sources = {}
207
- changelog_cookbooks.each_key do |name|
208
- sources[name] = get_source_url(lock_target['cookbook_locks'][name]['source_options'])
209
- end
210
- changelog_cookbooks.deep_merge(sources).map { |name, data| format_output(name, data) }.join("\n")
209
+ generate_changelog_from_versions(changelog_cookbooks)
210
+ end
211
+
212
+ # Generates Policyfile changelog
213
+ #
214
+ # @param cookbook_versions. Format is { 'NAME' => { 'current_version' => 'VERSION', 'target_version' => 'VERSION' }
215
+ # @return [String] formatted version changelog
216
+ def generate_changelog_from_versions(cookbook_versions)
217
+ lock_current = read_policyfile_lock(@policyfile_dir)
218
+ sources = cookbook_versions.keys.map do |name|
219
+ [name, get_source_url(lock_current['cookbook_locks'][name]['source_options'])]
220
+ end.to_h
221
+ cookbook_versions.deep_merge(sources).map { |name, data| format_output(name, data) }.join("\n")
211
222
  end
212
223
  end
@@ -256,12 +256,16 @@ RSpec.describe PolicyChangelog do
256
256
  expect(changelog.reject_version_filter(data)).to be false
257
257
  end
258
258
  end
259
- context 'when current or target do not exist' do
259
+ context 'when target does not exist' do
260
260
  it 'returns true' do
261
- expect(changelog.reject_version_filter('target_version' => '1.0.0')).to be true
262
261
  expect(changelog.reject_version_filter('current_version' => '1.0.0')).to be true
263
262
  end
264
263
  end
264
+ context 'when current does not exist but target_does' do
265
+ it 'returns false' do
266
+ expect(changelog.reject_version_filter('target_version' => '1.0.0')).to be false
267
+ end
268
+ end
265
269
  context 'when data is nil' do
266
270
  it 'raises an exception' do
267
271
  expect { changelog.reject_version_filter(nil) }.to raise_error
@@ -269,6 +273,28 @@ RSpec.describe PolicyChangelog do
269
273
  end
270
274
  end
271
275
 
276
+ describe '#generate_changelog_from_versions' do
277
+ context 'when given origin/target versions' do
278
+ it 'generate the right changelog' do
279
+ expect(changelog).not_to receive(:update_policyfile_lock)
280
+
281
+ origin_and_target = {
282
+ 'users' => { 'current_version' => '4.0.0', 'target_version' => '5.0.0' }
283
+ }
284
+
285
+ allow(changelog).to receive(:git_changelog)
286
+ .with(instance_of(String), '4.0.0', '5.0.0')
287
+ .and_return('e1b971a Add test commit message')
288
+
289
+ output = "\nChangelog for users: 4.0.0->5.0.0\n" \
290
+ "==================================\n" \
291
+ "e1b971a Add test commit message"
292
+
293
+ expect(changelog.generate_changelog_from_versions(origin_and_target)).to eq(output)
294
+ end
295
+ end
296
+ end
297
+
272
298
  describe '#generate_changelog' do
273
299
  context 'when generating a changelog' do
274
300
  it 'detects type for regular tag' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-changelog
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.10
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregoire Seux
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-12 00:00:00.000000000 Z
11
+ date: 2018-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -211,7 +211,6 @@ files:
211
211
  - lib/knife/changelog/berksfile.rb
212
212
  - lib/knife/changelog/changelog.rb
213
213
  - lib/knife/changelog/git.rb
214
- - lib/knife/changelog/version.rb
215
214
  - lib/policyfile.rb
216
215
  - resources/Berksfile
217
216
  - resources/Berksfile.lock
@@ -243,7 +242,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
243
242
  version: '0'
244
243
  requirements: []
245
244
  rubyforge_project:
246
- rubygems_version: 2.7.5
245
+ rubygems_version: 2.7.6
247
246
  signing_key:
248
247
  specification_version: 4
249
248
  summary: Facilitate access to cookbooks changelog
@@ -1,5 +0,0 @@
1
- module Knife
2
- module Changelog
3
- VERSION = '1.0.10'.freeze
4
- end
5
- end